problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;
int a[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
struct note {
int i, cost;
bool operator<(const note &x) const { return i > x.i; }
} t[100];
int ans[100], tot, flag;
int temp[100], at;
int n, m, mi = 99, di;
int l1;
void bi() {
int f = 0;
if (tot > at) {
f = 1;
} else
for (int q = 0; q < tot; q++) {
if (ans[q] > temp[q]) {
f = 1;
break;
} else if (ans[q] < temp[q])
break;
}
if (f) {
for (int q = 0; q < tot; q++)
temp[q] = ans[q];
at = tot;
}
}
void dfs(int yu) {
if (yu == 0) {
if (flag) {
bi();
} else {
flag = 1;
at = tot;
for (int q = 0; q < tot; q++)
temp[q] = ans[q];
}
return;
}
for (int q = 0; q < m; q++) {
if (yu >= t[q].cost) {
yu -= t[q].cost;
ans[tot++] = t[q].i;
dfs(yu);
tot--;
yu += t[q].cost;
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int q = 0; q < m; q++) {
scanf("%d", &t[q].i);
t[q].cost = a[t[q].i];
if (mi > t[q].cost) {
mi = t[q].cost;
di = t[q].i;
} else if (mi == t[q].cost) {
di = max(di, t[q].i);
}
}
sort(t, t + m);
int len = n / mi;
int yu = n % mi;
tot = 0;
flag = 0;
if (len >= 30) {
len -= 30;
yu += mi * 30;
} else {
yu += len * mi;
len = 0;
}
dfs(yu);
tot = at;
if (flag) {
int l = 0;
for (; l < tot; l++) {
if (temp[l] > di) {
printf("%d", temp[l]);
} else
break;
}
for (int q = 0; q < len; q++)
printf("%d", di);
for (; l < tot; l++)
printf("%d", temp[l]);
}
printf("\n");
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int maxn = 2e5 + 5;
int a[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
struct note {
int i, cost;
bool operator<(const note &x) const { return i > x.i; }
} t[100];
int ans[100], tot, flag;
int temp[100], at;
int n, m, mi = 99, di;
int l1;
void bi() {
int f = 0;
if (tot > at) {
f = 1;
} else
for (int q = 0; q < tot; q++) {
if (ans[q] > temp[q]) {
f = 1;
break;
} else if (ans[q] < temp[q])
break;
}
if (f) {
for (int q = 0; q < tot; q++)
temp[q] = ans[q];
at = tot;
}
}
void dfs(int yu) {
if (yu == 0) {
if (flag) {
bi();
} else {
flag = 1;
at = tot;
for (int q = 0; q < tot; q++)
temp[q] = ans[q];
}
return;
}
for (int q = 0; q < m; q++) {
if (yu >= t[q].cost) {
yu -= t[q].cost;
ans[tot++] = t[q].i;
dfs(yu);
tot--;
yu += t[q].cost;
}
}
}
int main() {
scanf("%d%d", &n, &m);
for (int q = 0; q < m; q++) {
scanf("%d", &t[q].i);
t[q].cost = a[t[q].i];
if (mi > t[q].cost) {
mi = t[q].cost;
di = t[q].i;
} else if (mi == t[q].cost) {
di = max(di, t[q].i);
}
}
sort(t, t + m);
int len = n / mi;
int yu = n % mi;
tot = 0;
flag = 0;
if (len >= 5) {
len -= 5;
yu += mi * 5;
} else {
yu += len * mi;
len = 0;
}
dfs(yu);
tot = at;
if (flag) {
int l = 0;
for (; l < tot; l++) {
if (temp[l] > di) {
printf("%d", temp[l]);
} else
break;
}
for (int q = 0; q < len; q++)
printf("%d", di);
for (; l < tot; l++)
printf("%d", temp[l]);
}
printf("\n");
}
| replace | 82 | 85 | 82 | 85 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
const string MINUSINF = "-";
int N, M;
cin >> N >> M;
int A[N];
string dp[11000]; // N本使った時の最大の数
// dp[i] = dp[i-M]
int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < M; i++)
cin >> A[i];
for (int i = 0; i < N + 1; i++)
dp[i] = MINUSINF;
dp[0] = "";
for (int i = 0; i < N + 1; i++) {
// cout << "i: " << i << endl;
for (int j = 0; j < M; j++) {
if (i - cost[A[j]] < 0)
continue;
if (dp[i - cost[A[j]]] == MINUSINF)
continue;
string newVal;
if (to_string(A[j]) > dp[i - cost[A[j]]])
newVal = to_string(A[j]) + dp[i - cost[A[j]]];
else
newVal = dp[i - cost[A[j]]] + to_string(A[j]);
int csz = dp[i].size();
int nsz = newVal.size();
if (nsz > csz)
dp[i] = newVal;
else if (nsz == csz) {
if (newVal > dp[i])
dp[i] = newVal;
}
// cout << "i: " << i << ", j: " << j << ", dp[i]: " << dp[i] <<
// endl;
}
}
cout << dp[N] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void) {
const string MINUSINF = "-";
int N, M;
cin >> N >> M;
int A[M];
string dp[11000]; // N本使った時の最大の数
// dp[i] = dp[i-M]
int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < M; i++)
cin >> A[i];
for (int i = 0; i < N + 1; i++)
dp[i] = MINUSINF;
dp[0] = "";
for (int i = 0; i < N + 1; i++) {
// cout << "i: " << i << endl;
for (int j = 0; j < M; j++) {
if (i - cost[A[j]] < 0)
continue;
if (dp[i - cost[A[j]]] == MINUSINF)
continue;
string newVal;
if (to_string(A[j]) > dp[i - cost[A[j]]])
newVal = to_string(A[j]) + dp[i - cost[A[j]]];
else
newVal = dp[i - cost[A[j]]] + to_string(A[j]);
int csz = dp[i].size();
int nsz = newVal.size();
if (nsz > csz)
dp[i] = newVal;
else if (nsz == csz) {
if (newVal > dp[i])
dp[i] = newVal;
}
// cout << "i: " << i << ", j: " << j << ", dp[i]: " << dp[i] <<
// endl;
}
}
cout << dp[N] << endl;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
/* return true if s>t */
bool strcomp(string s, string t) {
if (s.size() > t.size()) {
return true;
} else if (s.size() < t.size()) {
return false;
} else {
return s > t;
}
}
int main() {
int N, M;
cin >> N >> M;
typedef pair<int, int> P;
vector<P> AB(M); /* A:num, B:cost */
rep(i, M) {
cin >> AB[i].fi;
AB[i].se = cost[AB[i].fi];
}
vector<int> dp(N + 1, -INF);
dp[0] = 0;
rep(i, N) {
rep(j, M) {
int ncost = AB[j].se;
chmax(dp[i + ncost], dp[i] + 1);
}
}
int keta = dp[N];
sort(all(AB), greater<P>());
string ans;
int itr = N;
rep(i, keta) {
rep(j, M) {
int num = AB[j].fi;
int cost = AB[j].se;
if (itr - cost >= 0 && dp[itr] - 1 == dp[itr - cost]) {
ans += (char)(num + '0');
itr -= cost;
break;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
/* return true if s>t */
bool strcomp(string s, string t) {
if (s.size() > t.size()) {
return true;
} else if (s.size() < t.size()) {
return false;
} else {
return s > t;
}
}
int main() {
int N, M;
cin >> N >> M;
typedef pair<int, int> P;
vector<P> AB(M); /* A:num, B:cost */
rep(i, M) {
cin >> AB[i].fi;
AB[i].se = cost[AB[i].fi];
}
vector<int> dp(N + 1, -INF);
dp[0] = 0;
rep(i, N) {
rep(j, M) {
int ncost = AB[j].se;
if (i + ncost <= N)
chmax(dp[i + ncost], dp[i] + 1);
}
}
int keta = dp[N];
sort(all(AB), greater<P>());
string ans;
int itr = N;
rep(i, keta) {
rep(j, M) {
int num = AB[j].fi;
int cost = AB[j].se;
if (itr - cost >= 0 && dp[itr] - 1 == dp[itr - cost]) {
ans += (char)(num + '0');
itr -= cost;
break;
}
}
}
cout << ans << endl;
} | replace | 59 | 60 | 59 | 61 | -6 | malloc(): corrupted top size
|
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9 + 7;
ll const INF = 1e18;
using namespace std;
int main() {
ios();
vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
cin >> n >> m;
vector<int> v(m);
for (auto &i : v) {
cin >> i;
}
sort(v.rbegin(), v.rend());
vector<int> dp(n, (int)-1e9);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (auto j : v) {
if (i - cost[j] >= 0) {
dp[i] = max(dp[i], dp[i - cost[j]] + 1);
}
}
}
string ans;
while (n > 0) {
int a;
for (auto i : v) {
if (n >= cost[i] && dp[n - cost[i]] == dp[n] - 1) {
a = i;
break;
}
}
ans += '0' + a;
n -= cost[a];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9 + 7;
ll const INF = 1e18;
using namespace std;
int main() {
ios();
vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
cin >> n >> m;
vector<int> v(m);
for (auto &i : v) {
cin >> i;
}
sort(v.rbegin(), v.rend());
vector<int> dp(n + 1, (int)-1e9);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (auto j : v) {
if (i - cost[j] >= 0) {
dp[i] = max(dp[i], dp[i - cost[j]] + 1);
}
}
}
string ans;
while (n > 0) {
int a;
for (auto i : v) {
if (n >= cost[i] && dp[n - cost[i]] == dp[n] - 1) {
a = i;
break;
}
}
ans += '0' + a;
n -= cost[a];
}
cout << ans << endl;
return 0;
}
| replace | 24 | 25 | 24 | 25 | TLE | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d", &i))
#define GLL(i) (scanf("%lld", &i))
#define GD(i) (scanf("%lf", &i))
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define GET0(x) (get<0>(x))
#define GET1(x) (get<1>(x))
#define GET2(x) (get<2>(x))
#define ALL(X) (X).begin(), (X).end()
#define LLMAX (1LL << 60)
#define LLMIN -(1LL << 60)
#define IMAX (1 << 30)
#define IMIN -(1 << 30)
typedef long long LL;
using namespace std;
int cost[11] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<string> cache(10000, string(""));
vector<int> A;
int comp(string s, string t) {
if (s == "N")
return false;
if (t == "N")
return true;
if (s.size() < t.size())
return false;
else if (s.size() > t.size())
return true;
else {
int n = s.size();
REP(i, n) {
if (s[i] > t[i])
return true;
else if (s[i] < t[i])
return false;
}
return true;
}
}
string rec(int N) {
if (N == 0)
return "";
if (cache[N] != "")
return cache[N];
string res = "N";
for (int a : A) {
if (cost[a] <= N && rec(N - cost[a]) != "N") {
string s = (char)('0' + a) + rec(N - cost[a]);
if (comp(s, res))
res = s;
}
}
cache[N] = res;
return res;
}
int main(void) {
int N, M;
GI(N);
GI(M);
vector<int> B(M);
REP(i, M)
GI(B[i]);
A = B;
string ans = rec(N);
printf("%s\n", ans.c_str());
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d", &i))
#define GLL(i) (scanf("%lld", &i))
#define GD(i) (scanf("%lf", &i))
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define GET0(x) (get<0>(x))
#define GET1(x) (get<1>(x))
#define GET2(x) (get<2>(x))
#define ALL(X) (X).begin(), (X).end()
#define LLMAX (1LL << 60)
#define LLMIN -(1LL << 60)
#define IMAX (1 << 30)
#define IMIN -(1 << 30)
typedef long long LL;
using namespace std;
int cost[11] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<string> cache(20000, string(""));
vector<int> A;
int comp(string s, string t) {
if (s == "N")
return false;
if (t == "N")
return true;
if (s.size() < t.size())
return false;
else if (s.size() > t.size())
return true;
else {
int n = s.size();
REP(i, n) {
if (s[i] > t[i])
return true;
else if (s[i] < t[i])
return false;
}
return true;
}
}
string rec(int N) {
if (N == 0)
return "";
if (cache[N] != "")
return cache[N];
string res = "N";
for (int a : A) {
if (cost[a] <= N && rec(N - cost[a]) != "N") {
string s = (char)('0' + a) + rec(N - cost[a]);
if (comp(s, res))
res = s;
}
}
cache[N] = res;
return res;
}
int main(void) {
int N, M;
GI(N);
GI(M);
vector<int> B(M);
REP(i, M)
GI(B[i]);
A = B;
string ans = rec(N);
printf("%s\n", ans.c_str());
return 0;
} | replace | 41 | 42 | 41 | 42 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define err(args...) \
{}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream &operator>>(istream &is, vector<T> &a) {
for (T &x : a) {
is >> x;
}
return is;
}
const int N = 10'000;
bool can[N][N];
vector<int> sticks = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void build(int n, int d, vector<int> &a) {
for (int x : a) {
if (sticks[x] <= n and can[n - sticks[x]][d - 1]) {
cout << x;
build(n - sticks[x], d - 1, a);
break;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(m);
cin >> a;
sort(a.begin(), a.end(), greater<int>());
can[0][0] = true;
for (int d = 1; d <= n; d++) {
for (int i = 1; i <= n; i++) {
for (int x : a) {
if (sticks[x] <= i) {
can[i][d] |= can[i - sticks[x]][d - 1];
}
}
}
}
for (int d = n; d >= 0; d--) {
if (can[n][d]) {
build(n, d, a);
cout << endl;
break;
}
}
return 0;
}
| #include <bits/stdc++.h>
#define err(args...) \
{}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream &operator>>(istream &is, vector<T> &a) {
for (T &x : a) {
is >> x;
}
return is;
}
const int N = 10'000;
bool can[N + 1][N + 1];
vector<int> sticks = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void build(int n, int d, vector<int> &a) {
for (int x : a) {
if (sticks[x] <= n and can[n - sticks[x]][d - 1]) {
cout << x;
build(n - sticks[x], d - 1, a);
break;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(m);
cin >> a;
sort(a.begin(), a.end(), greater<int>());
can[0][0] = true;
for (int d = 1; d <= n; d++) {
for (int i = 1; i <= n; i++) {
for (int x : a) {
if (sticks[x] <= i) {
can[i][d] |= can[i - sticks[x]][d - 1];
}
}
}
}
for (int d = n; d >= 0; d--) {
if (can[n][d]) {
build(n, d, a);
cout << endl;
break;
}
}
return 0;
}
| replace | 17 | 18 | 17 | 18 | 127 | /tmp/779294f4-2e11-4f2b-998e-33d906bb0608.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object
|
p03128 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
int a[15];
int dp[10005][15];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++)
cin >> a[i];
sort(a, a + m);
memset(dp, -1, sizeof(dp));
for (int i = 0; i < m; i++)
dp[0][i] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int k = 0; k < m; k++)
dp[i + num[a[k]]][k] = max(dp[i + num[a[k]]][k], dp[i][j] + 1);
while (n > 0) {
int mx = 0, ma = -1;
for (int i = 0; i < m; i++)
if (dp[n][i] >= mx) {
mx = dp[n][i];
ma = a[i];
}
n -= num[ma];
cout << ma;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
int a[15];
int dp[20005][15];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++)
cin >> a[i];
sort(a, a + m);
memset(dp, -1, sizeof(dp));
for (int i = 0; i < m; i++)
dp[0][i] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
for (int k = 0; k < m; k++)
dp[i + num[a[k]]][k] = max(dp[i + num[a[k]]][k], dp[i][j] + 1);
while (n > 0) {
int mx = 0, ma = -1;
for (int i = 0; i < m; i++)
if (dp[n][i] >= mx) {
mx = dp[n][i];
ma = a[i];
}
n -= num[ma];
cout << ma;
}
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define repr(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define forin(i, array) for (auto &x : array)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef vector<pint> vpint;
vll s(100009), t(100009);
vll truth(100009);
int vec[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vint arr;
vint ans(100000);
vector<string> dp(10000);
string strmax(string a, string b) {
if (a == "err")
return b;
if (a.length() < b.length())
return b;
if (a.length() > b.length())
return a;
if (a <= b)
return b;
else
return a;
}
string strfunc(int a, string b) {
stringstream ss;
ss << a << b;
return ss.str();
}
int main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int x;
cin >> x;
arr.pb(x - 1);
}
rep(i, n + 1) {
if (i == 0)
dp[i] = "";
else
dp[i] = "err";
}
reps(i, 1, n + 1) {
rep(j, 9) {
if (find(all(arr), j) == arr.end())
continue;
if (i - vec[j] < 0)
continue;
if (dp[i - vec[j]] == "err")
continue;
dp[i] = strmax(dp[i], strfunc(j + 1, dp[i - vec[j]]));
}
}
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define repr(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define forin(i, array) for (auto &x : array)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef vector<pint> vpint;
vll s(100009), t(100009);
vll truth(100009);
int vec[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vint arr;
vint ans(100000);
vector<string> dp(100000);
string strmax(string a, string b) {
if (a == "err")
return b;
if (a.length() < b.length())
return b;
if (a.length() > b.length())
return a;
if (a <= b)
return b;
else
return a;
}
string strfunc(int a, string b) {
stringstream ss;
ss << a << b;
return ss.str();
}
int main() {
int n, m;
cin >> n >> m;
rep(i, m) {
int x;
cin >> x;
arr.pb(x - 1);
}
rep(i, n + 1) {
if (i == 0)
dp[i] = "";
else
dp[i] = "err";
}
reps(i, 1, n + 1) {
rep(j, 9) {
if (find(all(arr), j) == arr.end())
continue;
if (i - vec[j] < 0)
continue;
if (dp[i - vec[j]] == "err")
continue;
dp[i] = strmax(dp[i], strfunc(j + 1, dp[i - vec[j]]));
}
}
cout << dp[n] << endl;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int num_sticks[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
vector<int> dp(N + 1, -1e9);
dp.at(0) = 0;
for (auto &a : A) {
cin >> a;
dp.at(num_sticks[a]) = 1;
}
for (int i = 1; i <= N; i++) {
for (auto a : A) {
int j = i + num_sticks[a];
if (j <= N) {
dp.at(j) = max(dp.at(j), dp.at(i) + 1);
}
}
}
sort(A.begin(), A.end(), greater<>());
int remaining = N;
while (remaining > 0) {
for (auto a : A) {
int sticks = num_sticks[a];
if (sticks > remaining) {
continue;
} else if (dp.at(remaining) == dp.at(remaining - sticks) + 1) {
cout << a;
remaining -= sticks;
break;
}
}
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int num_sticks[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
vector<int> dp(N + 10, -1e9);
dp.at(0) = 0;
for (auto &a : A) {
cin >> a;
dp.at(num_sticks[a]) = 1;
}
for (int i = 1; i <= N; i++) {
for (auto a : A) {
int j = i + num_sticks[a];
if (j <= N) {
dp.at(j) = max(dp.at(j), dp.at(i) + 1);
}
}
}
sort(A.begin(), A.end(), greater<>());
int remaining = N;
while (remaining > 0) {
for (auto a : A) {
int sticks = num_sticks[a];
if (sticks > remaining) {
continue;
} else if (dp.at(remaining) == dp.at(remaining - sticks) + 1) {
cout << a;
remaining -= sticks;
break;
}
}
}
cout << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03128 | Python | Runtime Error | def main():
n, m, *a = map(int, open(0).read().split())
t = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
a.sort(reverse=True)
dp = [-float("Inf")] * (n + 1)
dp[0] = 0
for i in range(2, n + 1):
for j in a:
dp[i] = max(dp[i], dp[i - t[j]] + 1)
nums = []
k = dp[n]
while n:
for x in a:
if dp[n - t[x]] == k - 1:
nums.append(x)
n -= t[x]
break
k -= 1
ans = "".join(map(str, nums))
print(ans)
if __name__ == "__main__":
main()
| def main():
n, m, *a = map(int, open(0).read().split())
t = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
a.sort(reverse=True)
dp = [-float("Inf")] * (n + 10)
dp[0] = 0
for i in range(2, n + 1):
for j in a:
dp[i] = max(dp[i], dp[i - t[j]] + 1)
nums = []
k = dp[n]
while n:
for x in a:
if dp[n - t[x]] == k - 1:
nums.append(x)
n -= t[x]
break
k -= 1
ans = "".join(map(str, nums))
print(ans)
if __name__ == "__main__":
main()
| replace | 5 | 6 | 5 | 6 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
string strmax(string a, string b) {
if (a.size() > b.size())
return a;
if (a.size() < b.size())
return b;
if (a > b)
return a;
else
return b;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
int C[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, 0, M) cin >> A[i];
vector<string> dp(1010, "0");
dp[0] = "";
rep(i, 0, N) rep(j, 0, M) {
if (dp[i] != "0")
dp[i + C[A[j] - 1]] =
strmax(dp[i + C[A[j] - 1]], to_string(A[j]) + dp[i]);
}
cout << dp[N] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
string strmax(string a, string b) {
if (a.size() > b.size())
return a;
if (a.size() < b.size())
return b;
if (a > b)
return a;
else
return b;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
int C[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, 0, M) cin >> A[i];
vector<string> dp(10101, "0");
dp[0] = "";
rep(i, 0, N) rep(j, 0, M) {
if (dp[i] != "0")
dp[i + C[A[j] - 1]] =
strmax(dp[i + C[A[j] - 1]], to_string(A[j]) + dp[i]);
}
cout << dp[N] << endl;
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 | |
p03128 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
void Main() {
const int INF = 1e9;
int n, m;
cin >> n >> m;
vi num = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vi a(m);
rep(i, m) {
cin >> a[i];
a[i]--;
}
// dp[s] = s 本のマッチを使うときの実現可能な最大桁数
vi dp(n + 5, -INF);
dp[0] = 0;
rep(i, m) dp[num[a[i]]] = 1;
rep(s, n + 5) { rep(i, m) chmax(dp[s + num[a[i]]], dp[s] + 1); }
int keta = dp[n];
// cout << keta << endl;
rep(k, keta) {
int tmp = -1;
rep(i, m) {
if (n - num[a[i]] < 0)
continue;
if (dp[n - num[a[i]]] == dp[n] - 1) {
chmax(tmp, a[i]);
}
}
n -= num[tmp];
cout << tmp + 1;
// cout << "debug: " << n << " " << tmp+1 << " " << num[tmp] << endl;
}
cout << endl;
return;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
void Main() {
const int INF = 1e9;
int n, m;
cin >> n >> m;
vi num = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vi a(m);
rep(i, m) {
cin >> a[i];
a[i]--;
}
// dp[s] = s 本のマッチを使うときの実現可能な最大桁数
vi dp(n + 5, -INF);
dp[0] = 0;
rep(i, m) dp[num[a[i]]] = 1;
rep(s, n + 5) {
rep(i, m) {
if (s + num[a[i]] <= n + 2)
chmax(dp[s + num[a[i]]], dp[s] + 1);
}
}
int keta = dp[n];
// cout << keta << endl;
rep(k, keta) {
int tmp = -1;
rep(i, m) {
if (n - num[a[i]] < 0)
continue;
if (dp[n - num[a[i]]] == dp[n] - 1) {
chmax(tmp, a[i]);
}
}
n -= num[tmp];
cout << tmp + 1;
// cout << "debug: " << n << " " << tmp+1 << " " << num[tmp] << endl;
}
cout << endl;
return;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | replace | 48 | 49 | 48 | 54 | 0 | |
p03128 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdbool.h>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define N (1000000000 + 7)
using namespace std;
typedef pair<int, int> P;
#define INF (-1000)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int a[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10010] = {INF};
int main(void) {
string ans = "";
int n, m;
cin >> n >> m;
vector<int> digit(n);
for (int i = 0; i < m; i++) {
cin >> digit[i];
}
sort(digit.begin(), digit.end());
reverse(digit.begin(), digit.end());
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (i - a[digit[j]] == 0) {
dp[i] = 1;
} else {
if ((i - a[digit[j]]) > 0) {
if (dp[i - a[digit[j]]] > 0) {
dp[i] = max(dp[i], dp[i - a[digit[j]]] + 1);
}
}
}
}
if (dp[i] == INF)
dp[i] = 0;
}
int size = n;
string t = "";
for (int i = 0; i < dp[n]; i++) {
if (i + 1 == dp[n]) {
for (int j = 0; j < m; j++) {
if (size - a[digit[j]] == 0) {
if (dp[size] == dp[size - a[digit[j]]] + 1) {
size -= a[digit[j]];
t = digit[j] + '0';
ans += t;
break;
}
}
}
} else {
for (int j = 0; j < m; j++) {
if ((size - a[digit[j]] >= 0) &&
(dp[size] == dp[size - a[digit[j]]] + 1)) {
size -= a[digit[j]];
t = digit[j] + '0';
ans += t;
break;
}
}
}
}
cout << ans << endl;
return 0;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stdbool.h>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define N (1000000000 + 7)
using namespace std;
typedef pair<int, int> P;
#define INF (-1000)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int a[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10010] = {INF};
int main(void) {
string ans = "";
int n, m;
cin >> n >> m;
vector<int> digit(m);
for (int i = 0; i < m; i++) {
cin >> digit[i];
}
sort(digit.begin(), digit.end());
reverse(digit.begin(), digit.end());
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (i - a[digit[j]] == 0) {
dp[i] = 1;
} else {
if ((i - a[digit[j]]) > 0) {
if (dp[i - a[digit[j]]] > 0) {
dp[i] = max(dp[i], dp[i - a[digit[j]]] + 1);
}
}
}
}
if (dp[i] == INF)
dp[i] = 0;
}
int size = n;
string t = "";
for (int i = 0; i < dp[n]; i++) {
if (i + 1 == dp[n]) {
for (int j = 0; j < m; j++) {
if (size - a[digit[j]] == 0) {
if (dp[size] == dp[size - a[digit[j]]] + 1) {
size -= a[digit[j]];
t = digit[j] + '0';
ans += t;
break;
}
}
}
} else {
for (int j = 0; j < m; j++) {
if ((size - a[digit[j]] >= 0) &&
(dp[size] == dp[size - a[digit[j]]] + 1)) {
size -= a[digit[j]];
t = digit[j] + '0';
ans += t;
break;
}
}
}
}
cout << ans << endl;
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
int n, m, a[10] = {}, c[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}, d[10004] = {};
cin >> n >> m;
for (int i = 0; i < m; i++)
cin >> a[i];
sort(a, a + m);
reverse(a, a + m);
for (int i = 1; i <= n; i++) {
d[i] = -10004;
for (int j = 0; j < m; j++)
if (i >= c[a[j]])
d[i] = max(d[i], d[i - c[a[j]]] + 1);
}
while (n) {
for (int i = 0; i < m; i++)
if (n >= a[i] && d[n - c[a[i]]] + 1 == d[n]) {
cout << a[i];
n -= c[a[i]];
break;
}
}
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
int n, m, a[10] = {}, c[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}, d[10004] = {};
cin >> n >> m;
for (int i = 0; i < m; i++)
cin >> a[i];
sort(a, a + m);
reverse(a, a + m);
for (int i = 1; i <= n; i++) {
d[i] = -10004;
for (int j = 0; j < m; j++)
if (i >= c[a[j]])
d[i] = max(d[i], d[i - c[a[j]]] + 1);
}
while (n) {
for (int i = 0; i < m; i++)
if (n >= c[a[i]] && d[n - c[a[i]]] + 1 == d[n]) {
cout << a[i];
n -= c[a[i]];
break;
}
}
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const ll match[10] = {inf, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void update(string &a, string b) {
if (a == "x")
a = b;
else if (a.size() < b.size())
a = b;
else if (a.size() == b.size()) {
if (a < b)
a = b;
}
}
int main() {
ll n, m;
cin >> n >> m;
vl a(m);
rep(i, m) cin >> a[i];
string dp[1010];
rep(i, 1010) { dp[i] = "x"; }
dp[0] = "";
rep(i, n + 1) {
if (dp[i] == "x")
continue;
for (auto p : a) {
update(dp[i + match[p]], dp[i] + to_string(p));
}
}
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define vtpl(x, y, z) vector<tuple<x, y, z>>
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const ll match[10] = {inf, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void update(string &a, string b) {
if (a == "x")
a = b;
else if (a.size() < b.size())
a = b;
else if (a.size() == b.size()) {
if (a < b)
a = b;
}
}
int main() {
ll n, m;
cin >> n >> m;
vl a(m);
rep(i, m) cin >> a[i];
string dp[10100];
rep(i, 10100) { dp[i] = "x"; }
dp[0] = "";
rep(i, n + 1) {
if (dp[i] == "x")
continue;
for (auto p : a) {
update(dp[i + match[p]], dp[i] + to_string(p));
}
}
cout << dp[n] << endl;
} | replace | 57 | 59 | 57 | 59 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
struct sss {
string s;
} dp[10001];
bool flag[10];
bool cmp(string a, string b) {
if (a.size() > b.size())
return 1;
else if (a.size() < b.size())
return 0;
else
return a > b;
}
bool cmp1(char a, char b) { return a > b; }
int main() {
int n, m;
string x;
map<int, string> mp;
map<string, int> vis;
vis["1"] = 2;
vis["2"] = 5;
vis["3"] = 5;
vis["4"] = 4;
vis["5"] = 5;
vis["6"] = 6;
vis["7"] = 3;
vis["8"] = 7;
vis["9"] = 6;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
cin >> x;
flag[vis[x]] = 1;
if (mp[vis[x]] < x)
mp[vis[x]] = x;
}
for (int i = 1; i <= n; i++) {
for (int j = 2; j <= 7; j++) {
if (flag[j] && i >= j) {
if (i == j) {
string z = mp[j];
if (dp[i].s == "")
dp[i].s = z;
else if (cmp(z, dp[i].s))
dp[i].s = z;
} else {
if (dp[i - j].s == "")
continue;
else {
string z = dp[i - j].s + mp[j];
sort(z.begin(), z.end(), cmp1);
if (dp[i].s == "")
dp[i].s = z;
else {
if (cmp(z, dp[i].s))
dp[i].s = z;
}
}
}
}
}
}
cout << dp[n].s;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;
struct sss {
string s;
} dp[10001];
bool flag[10];
bool cmp(string a, string b) {
if (a.size() > b.size())
return 1;
else if (a.size() < b.size())
return 0;
else
return a > b;
}
bool cmp1(char a, char b) { return a > b; }
int main() {
int n, m;
string x;
map<int, string> mp;
map<string, int> vis;
vis["1"] = 2;
vis["2"] = 5;
vis["3"] = 5;
vis["4"] = 4;
vis["5"] = 5;
vis["6"] = 6;
vis["7"] = 3;
vis["8"] = 7;
vis["9"] = 6;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
cin >> x;
flag[vis[x]] = 1;
if (mp[vis[x]] < x)
mp[vis[x]] = x;
}
for (int i = 1; i <= n; i++) {
for (int j = 2; j <= 7; j++) {
if (flag[j] && i >= j) {
if (i == j) {
string z = mp[j];
if (dp[i].s == "")
dp[i].s = z;
else if (cmp(z, dp[i].s))
dp[i].s = z;
} else {
if (dp[i - j].s == "")
continue;
else {
string z = dp[i - j].s + mp[j];
if (dp[i].s == "")
dp[i].s = z;
else {
if (cmp(z, dp[i].s))
dp[i].s = z;
}
}
}
}
}
}
cout << dp[n].s;
}
| delete | 58 | 59 | 58 | 58 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (int(i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for (int(i) = (n); (i) < (m); ++(i))
constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9 + 7;
constexpr int MAXN = 1e4 + 10;
vector<string> dp(MAXN);
int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool cmp(string &a, string &b) {
if (a.size() != b.size()) {
return a.size() > b.size();
} else {
return a > b;
}
}
string maxs(string &a, string &b) {
if (a == "?" || a == "") {
return b;
}
if (cmp(a, b)) {
return a;
} else {
return b;
}
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(N);
REP(i, M) { cin >> A[i]; }
REP(i, MAXN) { dp[i] = "?"; }
dp[0] = "";
REP(i, N) {
if (dp[i] == "?")
continue;
for (auto a : A) {
string s = dp[i] + to_string(a);
dp[i + cost[a]] = maxs(dp[i + cost[a]], s);
}
}
cout << dp[N] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (int(i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for (int(i) = (n); (i) < (m); ++(i))
constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9 + 7;
constexpr int MAXN = 1e4 + 10;
vector<string> dp(MAXN);
int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool cmp(string &a, string &b) {
if (a.size() != b.size()) {
return a.size() > b.size();
} else {
return a > b;
}
}
string maxs(string &a, string &b) {
if (a == "?" || a == "") {
return b;
}
if (cmp(a, b)) {
return a;
} else {
return b;
}
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
REP(i, M) { cin >> A[i]; }
REP(i, MAXN) { dp[i] = "?"; }
dp[0] = "";
REP(i, N) {
if (dp[i] == "?")
continue;
for (auto a : A) {
string s = dp[i] + to_string(a);
dp[i + cost[a]] = maxs(dp[i + cost[a]], s);
}
}
cout << dp[N] << endl;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const vector<int> match = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void chmax(string &a, string b) {
if (a == "-")
a = b;
else if (a.size() < b.size())
a = b;
else if (a.size() == b.size()) {
if (a < b)
a = b;
}
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; i++) {
cin >> a[i];
}
vector<string> dp(5010, "-"); // dp[0] = "-", dp[1] = "-", dp[2] = "-", ...
dp[0] = "";
for (int i = 0; i <= n; i++) {
if (dp[i] == "-")
continue;
for (auto num : a) {
chmax(dp[i + match[num]],
dp[i] + (char)('0' + num) // joining : string + char
);
}
}
cout << dp[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const vector<int> match = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void chmax(string &a, string b) {
if (a == "-")
a = b;
else if (a.size() < b.size())
a = b;
else if (a.size() == b.size()) {
if (a < b)
a = b;
}
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; i++) {
cin >> a[i];
}
vector<string> dp(20000, "-"); // dp[0] = "-", dp[1] = "-", dp[2] = "-", ...
dp[0] = "";
for (int i = 0; i <= n; i++) {
if (dp[i] == "-")
continue;
for (auto num : a) {
chmax(dp[i + match[num]],
dp[i] + (char)('0' + num) // joining : string + char
);
}
}
cout << dp[n] << endl;
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int INF = 1001001001;
// id = i - 1
const int need[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[1005];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end(), greater<int>());
fill(dp, dp + n + 1, -INF);
dp[0] = 0;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < m; ++j) {
if (i - need[a[j] - 1] >= 0) {
dp[i] = max(dp[i], dp[i - need[a[j] - 1]] + 1);
}
}
}
int now = n;
for (int i = 0; i < m; ++i) {
while (now - need[a[i] - 1] >= 0 &&
dp[now] == dp[now - need[a[i] - 1]] + 1) {
cout << a[i];
now -= need[a[i] - 1];
}
}
cout << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int INF = 1001001001;
// id = i - 1
const int need[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[100005];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end(), greater<int>());
fill(dp, dp + n + 1, -INF);
dp[0] = 0;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < m; ++j) {
if (i - need[a[j] - 1] >= 0) {
dp[i] = max(dp[i], dp[i - need[a[j] - 1]] + 1);
}
}
}
int now = n;
for (int i = 0; i < m; ++i) {
while (now - need[a[i] - 1] >= 0 &&
dp[now] == dp[now - need[a[i] - 1]] + 1) {
cout << a[i];
now -= need[a[i] - 1];
}
}
cout << endl;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; i++)
#define fornd(i, n) for (int i = n - 1; i >= 0; i--)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define for1d(i, n) for (int i = n; i >= 1; i--)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;
const int maxn = 100010;
int c[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}, n, a[11];
struct node {
int cnt[11] = {0}, size = 0;
};
node dp[1010];
bool grt(node a, node b) {
if (a.size != b.size)
return a.size > b.size;
for1d(i, 9) if (a.cnt[i] != b.cnt[i]) return a.cnt[i] > b.cnt[i];
return false;
}
void print(node a) {
for1d(i, 9) while (a.cnt[i]--) cerr << i;
cerr << ' ';
}
int main() {
int ndig;
cin >> n >> ndig;
forn(i, n) scanf("%d", &a[i]);
for1(i, n) {
forn(j, ndig) {
if (i >= c[a[j]]) {
if (dp[i - c[a[j]]].size == 0 && i - c[a[j]])
continue;
node tmp;
for1(k, 9) tmp.cnt[k] = dp[i - c[a[j]]].cnt[k];
tmp.cnt[a[j]]++;
tmp.size = dp[i - c[a[j]]].size;
tmp.size++;
// cerr << i << ' '; print(tmp); print(dp[i]); cerr << tmp.size << ' '
// << dp[i].size << endl;
if (grt(tmp, dp[i])) {
for1(k, 9) dp[i].cnt[k] = tmp.cnt[k];
dp[i].size = tmp.size;
}
}
}
}
// for1(i, n) { for1d(j, 9) while (dp[i].cnt[j]--) printf("%d", j); cerr << '
// '; }
for1d(i, 9) while (dp[n].cnt[i]--) printf("%d", i);
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define forn(i, n) for (int i = 0; i < n; i++)
#define fornd(i, n) for (int i = n - 1; i >= 0; i--)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define for1d(i, n) for (int i = n; i >= 1; i--)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;
const int maxn = 100010;
int c[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}, n, a[11];
struct node {
int cnt[11] = {0}, size = 0;
};
node dp[10010];
bool grt(node a, node b) {
if (a.size != b.size)
return a.size > b.size;
for1d(i, 9) if (a.cnt[i] != b.cnt[i]) return a.cnt[i] > b.cnt[i];
return false;
}
void print(node a) {
for1d(i, 9) while (a.cnt[i]--) cerr << i;
cerr << ' ';
}
int main() {
int ndig;
cin >> n >> ndig;
forn(i, n) scanf("%d", &a[i]);
for1(i, n) {
forn(j, ndig) {
if (i >= c[a[j]]) {
if (dp[i - c[a[j]]].size == 0 && i - c[a[j]])
continue;
node tmp;
for1(k, 9) tmp.cnt[k] = dp[i - c[a[j]]].cnt[k];
tmp.cnt[a[j]]++;
tmp.size = dp[i - c[a[j]]].size;
tmp.size++;
// cerr << i << ' '; print(tmp); print(dp[i]); cerr << tmp.size << ' '
// << dp[i].size << endl;
if (grt(tmp, dp[i])) {
for1(k, 9) dp[i].cnt[k] = tmp.cnt[k];
dp[i].size = tmp.size;
}
}
}
}
// for1(i, n) { for1d(j, 9) while (dp[i].cnt[j]--) printf("%d", j); cerr << '
// '; }
for1d(i, 9) while (dp[n].cnt[i]--) printf("%d", i);
return 0;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF = (long long)1E17;
#define i_7 (long long)(1E9 + 7)
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
using namespace std;
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
class UnionFind {
public:
// 各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
vector<int> Parent;
// クラスを作るときは、Parentの値を全て-1にする。
// 以下のようにすると全てバラバラの頂点として解釈できる。
UnionFind(int N) { Parent = vector<int>(N, -1); }
// Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
// 自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)]; // 先祖をrootで取っておきたい。
}
// AとBをくっ付ける
bool connect(int A, int B) {
// AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
// すでにくっついてるからくっ付けない
return false;
}
// 大きい方(A)に小さいほう(B)をくっ付けたい
// 大小が逆だったらAとBをひっくり返す。
if (size(A) < size(B))
swap(A, B);
// Aのサイズを更新する
Parent[A] += Parent[B];
// Bの親をAに変更する
Parent[B] = A;
return true;
}
};
int main() {
int consume[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
cin >> n >> m;
vector<int> a(m);
REP(i, m) { cin >> a[i]; }
sort(a.begin(), a.end(), greater<int>());
vector<int> dp(n + 1, -1); // マッチをi本使って作れる最大の桁数を格納する。
vector<int> to(n + 1, -1);
REP(i, m) {
if (dp[consume[a[i]]] > 0)
continue;
dp[consume[a[i]]] = 1;
to[consume[a[i]]] = i;
}
REP(i, n) {
REP(j, m) {
if (i + 1 - consume[a[j]] < 0)
continue;
if (dp[i + 1 - consume[a[j]]] < 0)
continue;
if (dp[i + 1] < (dp[i + 1 - consume[a[j]]] + 1)) {
dp[i + 1] = dp[i + 1 - consume[a[j]]] + 1;
to[i + 1] = j;
}
}
}
int matches = n; // 残りのマッチの数
string ans = "";
int index;
char next_;
while (to[matches] >= 0) {
index = to[matches];
next_ = '0' + a[index];
ans += next_;
matches -= consume[a[index]];
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF = (long long)1E17;
#define i_7 (long long)(1E9 + 7)
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
using namespace std;
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
class UnionFind {
public:
// 各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
vector<int> Parent;
// クラスを作るときは、Parentの値を全て-1にする。
// 以下のようにすると全てバラバラの頂点として解釈できる。
UnionFind(int N) { Parent = vector<int>(N, -1); }
// Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
// 自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)]; // 先祖をrootで取っておきたい。
}
// AとBをくっ付ける
bool connect(int A, int B) {
// AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
// すでにくっついてるからくっ付けない
return false;
}
// 大きい方(A)に小さいほう(B)をくっ付けたい
// 大小が逆だったらAとBをひっくり返す。
if (size(A) < size(B))
swap(A, B);
// Aのサイズを更新する
Parent[A] += Parent[B];
// Bの親をAに変更する
Parent[B] = A;
return true;
}
};
int main() {
int consume[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
cin >> n >> m;
vector<int> a(m);
REP(i, m) { cin >> a[i]; }
sort(a.begin(), a.end(), greater<int>());
vector<int> dp(n + 1, -1); // マッチをi本使って作れる最大の桁数を格納する。
vector<int> to(n + 1, -1);
REP(i, m) {
if (consume[a[i]] > n)
continue;
if (dp[consume[a[i]]] > 0)
continue;
dp[consume[a[i]]] = 1;
to[consume[a[i]]] = i;
}
REP(i, n) {
REP(j, m) {
if (i + 1 - consume[a[j]] < 0)
continue;
if (dp[i + 1 - consume[a[j]]] < 0)
continue;
if (dp[i + 1] < (dp[i + 1 - consume[a[j]]] + 1)) {
dp[i + 1] = dp[i + 1 - consume[a[j]]] + 1;
to[i + 1] = j;
}
}
}
int matches = n; // 残りのマッチの数
string ans = "";
int index;
char next_;
while (to[matches] >= 0) {
index = to[matches];
next_ = '0' + a[index];
ans += next_;
matches -= consume[a[index]];
}
cout << ans << endl;
return 0;
}
| insert | 99 | 99 | 99 | 101 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
long long n, m;
long long a[11];
long long dp[10005];
vector<int> V;
vector<pair<int, int>> pd;
string s;
int k;
int num(int k) {
int answer = 0;
if (k == 1) {
answer = 2;
} else if (k == 2) {
answer = 5;
} else if (k == 3) {
answer = 5;
} else if (k == 4) {
answer = 4;
} else if (k == 5) {
answer = 5;
} else if (k == 6) {
answer = 6;
} else if (k == 7) {
answer = 3;
} else if (k == 8) {
answer = 7;
} else if (k == 9) {
answer = 6;
}
return answer;
}
string solver(int n) {
for (int i = 1; i < n + 1; ++i) {
dp[i] = 0;
}
for (int i = 1; i < n + 1; ++i) {
for (int j = 0; j < m; ++j) {
if (i >= num(a[j])) {
dp[i] = max(dp[i - num(a[j])] + 1, dp[i]);
}
}
}
while (n > 0) {
// for(int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j) {
if (dp[n] == dp[n - num(a[j])] + 1 && n >= num(a[j])) {
if (dp[n] == 1) {
if (n != num(a[j])) {
continue;
}
}
n -= num(a[j]);
s += to_string(a[j]);
break;
}
}
//}
}
return s;
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> a[i];
// cout << num(a[i]) << endl;
V.push_back(a[i]);
}
sort(V.begin(), V.end(), greater<int>());
for (int i = 0; i < m; ++i) {
a[i] = V[i];
// cout << a[i] << endl;
}
cout << solver(n) << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
long long n, m;
long long a[11];
long long dp[10005];
vector<int> V;
vector<pair<int, int>> pd;
string s;
int k;
int num(int k) {
int answer = 0;
if (k == 1) {
answer = 2;
} else if (k == 2) {
answer = 5;
} else if (k == 3) {
answer = 5;
} else if (k == 4) {
answer = 4;
} else if (k == 5) {
answer = 5;
} else if (k == 6) {
answer = 6;
} else if (k == 7) {
answer = 3;
} else if (k == 8) {
answer = 7;
} else if (k == 9) {
answer = 6;
}
return answer;
}
string solver(int n) {
for (int i = 1; i < n + 1; ++i) {
dp[i] = -10;
}
for (int i = 1; i < n + 1; ++i) {
for (int j = 0; j < m; ++j) {
if (i >= num(a[j])) {
dp[i] = max(dp[i - num(a[j])] + 1, dp[i]);
}
}
}
while (n > 0) {
// for(int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j) {
if (dp[n] == dp[n - num(a[j])] + 1 && n >= num(a[j])) {
if (dp[n] == 1) {
if (n != num(a[j])) {
continue;
}
}
n -= num(a[j]);
s += to_string(a[j]);
break;
}
}
//}
}
return s;
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> a[i];
// cout << num(a[i]) << endl;
V.push_back(a[i]);
}
sort(V.begin(), V.end(), greater<int>());
for (int i = 0; i < m; ++i) {
a[i] = V[i];
// cout << a[i] << endl;
}
cout << solver(n) << endl;
} | replace | 42 | 43 | 42 | 43 | TLE | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <deque>
#include <functional>
#include <memory>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
int n, m;
int digits[9];
int sticks_for_digits[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool called[10000];
bool reachable[10000];
struct Node {
int value;
shared_ptr<Node> next;
Node(int v, shared_ptr<Node> n) : value(v), next(n){};
};
struct LinkedList {
shared_ptr<Node> root;
int length;
LinkedList() : length(0){};
LinkedList(int v, LinkedList &tail)
: length(tail.length + 1), root(make_shared<Node>(v, tail.root)){};
bool empty() { return length == 0; }
int size() { return length; }
};
const LinkedList nil;
LinkedList cons(int value, LinkedList &list) { return LinkedList(value, list); }
LinkedList dp[10000];
bool is_left_ge(LinkedList &left, LinkedList &right) {
if (left.length > right.length)
return true;
if (left.length < right.length)
return false;
shared_ptr<Node> l = left.root;
shared_ptr<Node> r = right.root;
while (!((l == nullptr) && (r == nullptr))) {
if (l->value > r->value)
return true;
if (l->value < r->value)
return false;
l = l->next;
r = r->next;
}
return true;
}
void solve(int sticks) {
if (called[sticks])
return;
called[sticks] = true;
LinkedList cur;
// printf("entering solve(%d)\n", sticks);
// cur.push_back(0);
for (int i = 0; i < m; i++) {
int to_consume = sticks_for_digits[digits[i]];
if (sticks < to_consume)
continue;
solve(sticks - to_consume);
/*printf("solve(%d) =", sticks-to_consume);
Node *ptr = dp[sticks-to_consume];
while (ptr) {
printf("%d", ptr->value);
ptr = ptr->next;
}
printf("\n");*/
if (!reachable[sticks - to_consume])
continue;
LinkedList newlist = cons(digits[i], dp[sticks - to_consume]);
if (is_left_ge(newlist, cur)) {
cur = newlist;
}
}
if (cur.length == 0) {
int c = 0;
for (int i = 0; i < m; i++) {
if (sticks_for_digits[digits[i]] == sticks) {
c = max(c, digits[i]);
}
}
if (c != 0) {
cur = cons(c, cur);
}
} else if (cur.length == 1) {
for (int i = 0; i < m; i++) {
if (sticks_for_digits[digits[i]] == sticks) {
cur.root->value = max(cur.root->value, digits[i]);
}
}
}
if (cur.length != 0) {
dp[sticks] = cur;
reachable[sticks] = true;
}
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d", &(digits[i]));
// int sticks = sticks_for_digits[digits[i]];
// digits_for_sticks[sticks] = max(digits_for_sticks[sticks], digits[i]);
}
reachable[0] = true;
called[0] = true;
dp[0] = LinkedList();
solve(n);
shared_ptr<Node> ptr = dp[n].root;
vector<int> ds;
while (ptr) {
ds.push_back(ptr->value);
ptr = ptr->next;
}
for (auto d : ds) {
printf("%d", d);
}
printf("\n");
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <deque>
#include <functional>
#include <memory>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
int n, m;
int digits[9];
int sticks_for_digits[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool called[10000];
bool reachable[10000];
struct Node {
int value;
shared_ptr<Node> next;
Node(int v, shared_ptr<Node> n) : value(v), next(n){};
};
struct LinkedList {
shared_ptr<Node> root;
int length;
LinkedList() : length(0){};
LinkedList(int v, LinkedList &tail)
: length(tail.length + 1), root(make_shared<Node>(v, tail.root)){};
bool empty() { return length == 0; }
int size() { return length; }
};
LinkedList nil;
LinkedList cons(int value, LinkedList &list) { return LinkedList(value, list); }
LinkedList dp[10000];
bool is_left_ge(LinkedList &left, LinkedList &right) {
if (left.length > right.length)
return true;
if (left.length < right.length)
return false;
shared_ptr<Node> l = left.root;
shared_ptr<Node> r = right.root;
while (!((l == nullptr) && (r == nullptr))) {
if (l->value > r->value)
return true;
if (l->value < r->value)
return false;
l = l->next;
r = r->next;
}
return true;
}
void solve(int sticks) {
if (called[sticks])
return;
called[sticks] = true;
LinkedList cur;
// printf("entering solve(%d)\n", sticks);
// cur.push_back(0);
for (int i = 0; i < m; i++) {
int to_consume = sticks_for_digits[digits[i]];
if (sticks < to_consume)
continue;
solve(sticks - to_consume);
/*printf("solve(%d) =", sticks-to_consume);
Node *ptr = dp[sticks-to_consume];
while (ptr) {
printf("%d", ptr->value);
ptr = ptr->next;
}
printf("\n");*/
if (!reachable[sticks - to_consume])
continue;
LinkedList newlist = cons(digits[i], dp[sticks - to_consume]);
if (is_left_ge(newlist, cur)) {
cur = newlist;
}
}
if (cur.length == 0) {
int c = 0;
for (int i = 0; i < m; i++) {
if (sticks_for_digits[digits[i]] == sticks) {
c = max(c, digits[i]);
}
}
if (c != 0) {
cur = cons(c, cur);
}
} else if (cur.length == 1) {
for (int i = 0; i < m; i++) {
if (sticks_for_digits[digits[i]] == sticks) {
cur.root->value = max(cur.root->value, digits[i]);
}
}
}
if (cur.length != 0) {
dp[sticks] = cur;
reachable[sticks] = true;
}
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d", &(digits[i]));
// int sticks = sticks_for_digits[digits[i]];
// digits_for_sticks[sticks] = max(digits_for_sticks[sticks], digits[i]);
}
reachable[0] = true;
called[0] = true;
dp[0] = LinkedList();
solve(n);
shared_ptr<Node> ptr = dp[n].root;
vector<int> ds;
while (ptr) {
ds.push_back(ptr->value);
ptr = ptr->next;
}
for (auto d : ds) {
printf("%d", d);
}
printf("\n");
return 0;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p03128 | C++ | Runtime Error |
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n) \
rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int, P>
#define PP pair<P, P>
int n, m;
bool b[10];
string dp[1100];
int size(int k) {
if (k == 1)
return 2;
if (k == 7)
return 3;
if (k == 4)
return 4;
if (k == 2 || k == 3 || k == 5)
return 5;
if (k == 6 || k == 9)
return 6;
if (k == 8)
return 7;
}
string f(string s, string t, char c) {
string res = "";
int i = 0;
while (i < t.size() && t[i] > c) {
res += t[i];
i++;
}
res += c;
while (i < t.size()) {
res += t[i];
i++;
}
i = 0;
if (res.size() > s.size())
return res;
if (res.size() < s.size())
return s;
while (i < res.size()) {
if (res[i] > s[i])
return res;
if (res[i] < s[i])
return s;
i++;
}
return res;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
cin >> n >> m;
rep(i, m) {
int a;
cin >> a;
b[a] = true;
}
rep(i, n + 1) {
rep(j, 10) {
if (!b[j])
continue;
int k = i - size(j);
if (k < 0 || k != 0 && dp[k] == "")
continue;
dp[i] = f(dp[i], dp[k], j + '0');
// cout<<i<<' '<<dp[i]<<endl;
}
}
cout << dp[n] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n) \
rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int, P>
#define PP pair<P, P>
int n, m;
bool b[10];
string dp[11000];
int size(int k) {
if (k == 1)
return 2;
if (k == 7)
return 3;
if (k == 4)
return 4;
if (k == 2 || k == 3 || k == 5)
return 5;
if (k == 6 || k == 9)
return 6;
if (k == 8)
return 7;
}
string f(string s, string t, char c) {
string res = "";
int i = 0;
while (i < t.size() && t[i] > c) {
res += t[i];
i++;
}
res += c;
while (i < t.size()) {
res += t[i];
i++;
}
i = 0;
if (res.size() > s.size())
return res;
if (res.size() < s.size())
return s;
while (i < res.size()) {
if (res[i] > s[i])
return res;
if (res[i] < s[i])
return s;
i++;
}
return res;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
cin >> n >> m;
rep(i, m) {
int a;
cin >> a;
b[a] = true;
}
rep(i, n + 1) {
rep(j, 10) {
if (!b[j])
continue;
int k = i - size(j);
if (k < 0 || k != 0 && dp[k] == "")
continue;
dp[i] = f(dp[i], dp[k], j + '0');
// cout<<i<<' '<<dp[i]<<endl;
}
}
cout << dp[n] << endl;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << (x) << endl
// dp[i] := i本使って作れる数値の最大値(stringで持つ)
// 遷移
// dp[i] = max(dp[i], dp[i-cost[a[j]]] + a[j])
string dp[1010];
int cost[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(ALL(a));
reverse(ALL(a));
fill_n(dp, n, "0");
dp[0] = "";
int sm = 0;
for (int i = 0; i <= n; ++i) {
for (auto &&ai : a) {
// cerr<<"fuge"<<endl;
if (i - cost[ai - 1] < 0)
continue;
if (dp[i - cost[ai - 1]] == "0")
continue;
// debug(i);
// debug(ai);
string tmp = to_string(ai) + dp[i - cost[ai - 1]];
// cerr<<"hoge"<<endl;
// debug(cost[ai-1]);
// cerr<<tmp<< endl<<endl;
if (dp[i].size() > tmp.size())
continue;
if (dp[i].size() == tmp.size()) {
if (dp[i] > tmp)
continue;
}
// cerr<<tmp<< endl;
dp[i] = tmp;
// cerr<<tmp<< endl;
}
}
string ans = dp[n];
sort(ALL(ans));
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define debug(x) cerr << #x << ":" << (x) << endl
// dp[i] := i本使って作れる数値の最大値(stringで持つ)
// 遷移
// dp[i] = max(dp[i], dp[i-cost[a[j]]] + a[j])
string dp[101010];
int cost[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(ALL(a));
reverse(ALL(a));
fill_n(dp, n, "0");
dp[0] = "";
int sm = 0;
for (int i = 0; i <= n; ++i) {
for (auto &&ai : a) {
// cerr<<"fuge"<<endl;
if (i - cost[ai - 1] < 0)
continue;
if (dp[i - cost[ai - 1]] == "0")
continue;
// debug(i);
// debug(ai);
string tmp = to_string(ai) + dp[i - cost[ai - 1]];
// cerr<<"hoge"<<endl;
// debug(cost[ai-1]);
// cerr<<tmp<< endl<<endl;
if (dp[i].size() > tmp.size())
continue;
if (dp[i].size() == tmp.size()) {
if (dp[i] > tmp)
continue;
}
// cerr<<tmp<< endl;
dp[i] = tmp;
// cerr<<tmp<< endl;
}
}
string ans = dp[n];
sort(ALL(ans));
reverse(ALL(ans));
cout << ans << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03128 | C++ | Runtime Error | // #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <array>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
#include <cassert>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <random>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
// typedef unsigned __int128 HASH;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
typedef pair<long double, int> pdbi;
typedef pair<int, pii> pipii;
typedef pair<ll, pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 62;
const long double EPS = 1e-12;
const ll mod = 1000000000 + 7;
// const ll mod = 998244353;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const long double pi = 3.141592653589793;
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) \
(0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false
// debug
#define DEBUG
#define DUMPOUT cout
#ifdef DEBUG
#define dump(...) \
DUMPOUT << #__VA_ARGS__ << " :[" << __FUNCTION__ << ":" << __LINE__ << "]" \
<< endl; \
DUMPOUT << " "; \
dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
void dump_func() { DUMPOUT << endl; };
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) == 0)
DUMPOUT << " ";
else
DUMPOUT << ", ";
dump_func(std::move(tail)...);
}
// ostream
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "[";
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "[";
for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
os << "(" << itr->first << ", " << itr->second << ")";
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "[";
for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
os << *itr;
++itr;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "]";
return os;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int n, m;
vector<int> a(10);
int c[11] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
// vector<vector<int>> dp(1005, vector<int>(1005, -1));
vector<string> dp(1005, "-1");
int ans = -1;
string dfs(int nokori) {
if (dp[nokori] != "-1")
return dp[nokori];
if (nokori == 0) {
dp[nokori] = "0";
return dp[nokori];
}
rep(i, m) {
int cost = c[a[i]];
if (nokori - cost < 0)
continue;
string tmp = dfs(nokori - cost);
if (tmp == "-1")
continue;
int keta = tmp.size();
int base = 1;
rep(i, keta) base *= 10;
if (tmp == "0") {
char s1 = a[i] + '0';
if (dp[nokori].size() >= 2 && dp[nokori] != "-1")
continue;
int dpi = stoi(dp[nokori]);
if (dpi < a[i]) {
dp[nokori] = a[i] + '0';
}
} else {
char s1 = a[i] + '0';
string ss = s1 + tmp;
if (ss.size() > dp[nokori].size()) {
dp[nokori] = ss;
} else if (ss.size() < dp[nokori].size()) {
continue;
} else {
rep(i, ss.size()) {
if (dp[nokori][i] < ss[i]) {
dp[nokori] = ss;
break;
} else if (dp[nokori][i] > ss[i]) {
break;
}
}
}
}
}
return dp[nokori];
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
rep(i, m) cin >> a[i];
cout << dfs(n) << endl;
}
| // #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <array>
#include <bitset>
#include <complex>
#include <cstring>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
#include <cassert>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <random>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
// typedef unsigned __int128 HASH;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<double, int> pdi;
typedef pair<long double, int> pdbi;
typedef pair<int, pii> pipii;
typedef pair<ll, pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i > 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1 << 30;
const ll INFLL = 1LL << 62;
const long double EPS = 1e-12;
const ll mod = 1000000000 + 7;
// const ll mod = 998244353;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const long double pi = 3.141592653589793;
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) \
(0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false
// debug
#define DEBUG
#define DUMPOUT cout
#ifdef DEBUG
#define dump(...) \
DUMPOUT << #__VA_ARGS__ << " :[" << __FUNCTION__ << ":" << __LINE__ << "]" \
<< endl; \
DUMPOUT << " "; \
dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
void dump_func() { DUMPOUT << endl; };
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) == 0)
DUMPOUT << " ";
else
DUMPOUT << ", ";
dump_func(std::move(tail)...);
}
// ostream
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
os << "[";
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
os << "]";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "[";
for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
os << "(" << itr->first << ", " << itr->second << ")";
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "[";
for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
os << *itr;
++itr;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "]";
return os;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int n, m;
vector<int> a(10);
int c[11] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
// vector<vector<int>> dp(1005, vector<int>(1005, -1));
vector<string> dp(10005, "-1");
int ans = -1;
string dfs(int nokori) {
if (dp[nokori] != "-1")
return dp[nokori];
if (nokori == 0) {
dp[nokori] = "0";
return dp[nokori];
}
rep(i, m) {
int cost = c[a[i]];
if (nokori - cost < 0)
continue;
string tmp = dfs(nokori - cost);
if (tmp == "-1")
continue;
int keta = tmp.size();
int base = 1;
rep(i, keta) base *= 10;
if (tmp == "0") {
char s1 = a[i] + '0';
if (dp[nokori].size() >= 2 && dp[nokori] != "-1")
continue;
int dpi = stoi(dp[nokori]);
if (dpi < a[i]) {
dp[nokori] = a[i] + '0';
}
} else {
char s1 = a[i] + '0';
string ss = s1 + tmp;
if (ss.size() > dp[nokori].size()) {
dp[nokori] = ss;
} else if (ss.size() < dp[nokori].size()) {
continue;
} else {
rep(i, ss.size()) {
if (dp[nokori][i] < ss[i]) {
dp[nokori] = ss;
break;
} else if (dp[nokori][i] > ss[i]) {
break;
}
}
}
}
}
return dp[nokori];
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
rep(i, m) cin >> a[i];
cout << dfs(n) << endl;
}
| replace | 155 | 156 | 155 | 156 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(), vec.end()
#define P pair<int, int>
#define S second
#define F first
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
bool prime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0)
return false;
}
return true;
}
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
int res = 1;
while (y > 0) {
if (y & 1)
res = res * x % mood;
x = x * x % mood;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
return kai(x) * mod_pow(kai(x - y), mod - 2, mod) % mod *
mod_pow(kai(y), mod - 2, mod) % mod;
}
int n, m, a;
int ta[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<P> vec;
int dp[1010];
vector<int> cnt;
signed main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a;
vec.push_back({a, ta[a - 1]});
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (int)vec.size(); j++) {
if (vec[j].second <= i && dp[i - vec[j].second] != INF)
dp[i] = max(dp[i], dp[i - vec[j].second] + 1);
}
if (dp[i] == 0)
dp[i] = INF;
}
sort(all(vec));
reverse(all(vec));
int b = n;
while (dp[b] != 0) {
bool bl = false;
for (int j = 0; j < (int)vec.size(); j++) {
if (!bl && b - vec[j].second >= 0 && dp[b] == dp[b - vec[j].second] + 1) {
b -= vec[j].second;
cnt.push_back(vec[j].first);
bl = true;
}
}
}
for (int i = 0; i < (int)cnt.size(); i++) {
cout << cnt[i];
}
cout << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(), vec.end()
#define P pair<int, int>
#define S second
#define F first
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
bool prime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0)
return false;
}
return true;
}
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
int res = 1;
while (y > 0) {
if (y & 1)
res = res * x % mood;
x = x * x % mood;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
return kai(x) * mod_pow(kai(x - y), mod - 2, mod) % mod *
mod_pow(kai(y), mod - 2, mod) % mod;
}
int n, m, a;
int ta[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<P> vec;
int dp[10010];
vector<int> cnt;
signed main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a;
vec.push_back({a, ta[a - 1]});
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (int)vec.size(); j++) {
if (vec[j].second <= i && dp[i - vec[j].second] != INF)
dp[i] = max(dp[i], dp[i - vec[j].second] + 1);
}
if (dp[i] == 0)
dp[i] = INF;
}
sort(all(vec));
reverse(all(vec));
int b = n;
while (dp[b] != 0) {
bool bl = false;
for (int j = 0; j < (int)vec.size(); j++) {
if (!bl && b - vec[j].second >= 0 && dp[b] == dp[b - vec[j].second] + 1) {
b -= vec[j].second;
cnt.push_back(vec[j].first);
bl = true;
}
}
}
for (int i = 0; i < (int)cnt.size(); i++) {
cout << cnt[i];
}
cout << endl;
} | replace | 59 | 60 | 59 | 60 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;
int main() {
int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<pair<int, int>> candidate;
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int A;
cin >> A;
candidate.push_back(make_pair(A, num[A]));
}
sort(candidate.begin(), candidate.end(), greater<pair<int, int>>());
vector<int> DP(1e5);
for (int i = 0; i < candidate.size(); i++) {
DP[candidate[i].second] = 1;
}
for (int i = 2; i < N + 1; i++) {
if (DP[i] > 0) {
for (int j = 0; j < candidate.size(); j++) {
int num = candidate[j].second;
DP[i + num] = max(DP[i + num], DP[i] + 1);
}
}
}
int dig = DP[N], sum = N;
while (dig > 0) {
for (int i = 0; i < candidate.size(); i++) {
int now = candidate[i].second;
if (DP[sum - now] + 1 == DP[sum] && DP[sum] > 1) {
cout << candidate[i].first;
sum -= now;
break;
} else if (DP[sum] == 1 && sum == now) {
cout << candidate[i].first;
sum -= now;
break;
}
}
dig--;
}
cout << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;
int main() {
int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<pair<int, int>> candidate;
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int A;
cin >> A;
candidate.push_back(make_pair(A, num[A]));
}
sort(candidate.begin(), candidate.end(), greater<pair<int, int>>());
map<int, int> DP;
for (int i = 0; i < candidate.size(); i++) {
DP[candidate[i].second] = 1;
}
for (int i = 2; i < N + 1; i++) {
if (DP[i] > 0) {
for (int j = 0; j < candidate.size(); j++) {
int num = candidate[j].second;
DP[i + num] = max(DP[i + num], DP[i] + 1);
}
}
}
int dig = DP[N], sum = N;
while (dig > 0) {
for (int i = 0; i < candidate.size(); i++) {
int now = candidate[i].second;
if (DP[sum - now] + 1 == DP[sum] && DP[sum] > 1) {
cout << candidate[i].first;
sum -= now;
break;
} else if (DP[sum] == 1 && sum == now) {
cout << candidate[i].first;
sum -= now;
break;
}
}
dig--;
}
cout << endl;
return 0;
}
| replace | 30 | 31 | 30 | 31 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9 : (int)1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
auto inner = vectors(tail...);
return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
for (auto itr : a) {
if (itr != *a.begin())
cout << " ";
cout << itr;
}
}
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
int f[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
signed main() {
int n, m;
cin >> n >> m;
vector<int> v(m);
for (auto &e : v)
cin >> e;
map<int, int> mp;
for (auto e : v)
cmax(mp[f[e]], e);
vector<int> u;
for (auto itr : mp)
u.push_back(itr.second);
vector<string> dp(n + 1, "");
rep(i, dp.size()) {
rep(j, u.size()) {
if (i == 0) {
dp[f[u[j]]] = to_string(u[j]);
} else if (dp[i] != "") {
string t = dp[i];
string comp = dp[i] + to_string(u[j]);
sort(all(comp), greater<>());
if (i + f[u[j]] <= n) {
if (comp.size() > dp[i + f[u[j]]].size() or
(comp.size() == dp[i + f[u[j]]].size() and
comp > dp[i + f[u[j]]]))
dp[i + f[u[j]]] = comp;
}
}
}
}
cout << dp[n] << endl;
}
| #include <bits/stdc++.h>
using ll = long long;
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9 : (int)1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
auto inner = vectors(tail...);
return vector<decltype(inner)>(x, inner);
}
template <class T> void join(T a) {
for (auto itr : a) {
if (itr != *a.begin())
cout << " ";
cout << itr;
}
}
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pii>;
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
int f[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
signed main() {
int n, m;
cin >> n >> m;
vector<int> v(m);
for (auto &e : v)
cin >> e;
map<int, int> mp;
for (auto e : v)
cmax(mp[f[e]], e);
vector<int> u;
for (auto itr : mp)
u.push_back(itr.second);
vector<string> dp(n + 1, "");
rep(i, dp.size()) {
rep(j, u.size()) {
if (i == 0) {
if (f[u[j]] <= n)
dp[f[u[j]]] = to_string(u[j]);
} else if (dp[i] != "") {
string t = dp[i];
string comp = dp[i] + to_string(u[j]);
sort(all(comp), greater<>());
if (i + f[u[j]] <= n) {
if (comp.size() > dp[i + f[u[j]]].size() or
(comp.size() == dp[i + f[u[j]]].size() and
comp > dp[i + f[u[j]]]))
dp[i + f[u[j]]] = comp;
}
}
}
}
cout << dp[n] << endl;
}
| replace | 57 | 58 | 57 | 59 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9;
int N, M;
vector<int> A;
int num[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[100010];
string f() {
string S = "";
int i = N;
while (1) {
if (i == 0) {
return S;
}
for (int j = 0; j < M; j++) {
int k = i - num[A[j]];
if (k >= 0 && dp[k] == dp[i] - 1) {
S = S + to_string(A[j]);
i -= num[A[j]];
break;
}
}
}
return S;
}
void abc118d() {
sort(A.rbegin(), A.rend());
for (int i = 1; i <= N; i++) {
dp[i] = -INF;
}
dp[0] = 0;
for (int i = 1; i <= N; i++) {
int dp_tmp = -INF;
for (int j = 0; j < M; j++) {
int k = i - num[A[j]];
if (k >= 0 && dp[k] != -INF) {
dp_tmp = max(dp_tmp, dp[i - num[A[j]]] + 1);
}
}
dp[i] = dp_tmp;
}
cout << f() << "\n";
return;
}
int main() {
cin >> N >> M;
A.assign(N, 0);
for (int i = 0; i < M; i++) {
cin >> A[i];
}
abc118d();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = (int)1e9;
int N, M;
vector<int> A;
int num[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[100010];
string f() {
string S = "";
int i = N;
while (1) {
if (i == 0) {
return S;
}
for (int j = 0; j < M; j++) {
int k = i - num[A[j]];
if (k >= 0 && dp[k] == dp[i] - 1) {
S = S + to_string(A[j]);
i -= num[A[j]];
break;
}
}
}
return S;
}
void abc118d() {
sort(A.rbegin(), A.rend());
for (int i = 1; i <= N; i++) {
dp[i] = -INF;
}
dp[0] = 0;
for (int i = 1; i <= N; i++) {
int dp_tmp = -INF;
for (int j = 0; j < M; j++) {
int k = i - num[A[j]];
if (k >= 0 && dp[k] != -INF) {
dp_tmp = max(dp_tmp, dp[i - num[A[j]]] + 1);
}
}
dp[i] = dp_tmp;
}
cout << f() << "\n";
return;
}
int main() {
cin >> N >> M;
A.assign(M, 0);
for (int i = 0; i < M; i++) {
cin >> A[i];
}
abc118d();
return 0;
}
| replace | 54 | 55 | 54 | 55 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
using namespace std;
int dp[1009];
signed main() {
int n, m;
cin >> n >> m;
int num[10] = {inf, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int nm[10] = {inf, inf, inf, inf, inf, inf, inf, inf, inf, inf};
for (int i = 0; i < m; i++) {
int x;
cin >> x;
nm[x] = num[x];
}
for (int i = 0; i <= n; i++) {
dp[i] = -inf;
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 10; j++) {
if (i - nm[j] >= 0) {
dp[i] = max(dp[i], dp[i - nm[j]] + 1);
}
}
}
int dig = dp[n];
int cur = n;
// for(int i=0;i<n;i++){cout<<i<<":"<<dp[i]<<endl;}
for (int i = 0; i < dig; i++) {
// cout<<i<<" "<<cur<<endl;
int nex = 0;
for (int j = 0; j < 10; j++) {
if (cur >= nm[j] && (dp[cur - nm[j]] + 1 == dp[cur])) {
nex = max(nex, j);
}
}
cout << nex;
cur -= nm[nex];
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
using namespace std;
int dp[10009];
signed main() {
int n, m;
cin >> n >> m;
int num[10] = {inf, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int nm[10] = {inf, inf, inf, inf, inf, inf, inf, inf, inf, inf};
for (int i = 0; i < m; i++) {
int x;
cin >> x;
nm[x] = num[x];
}
for (int i = 0; i <= n; i++) {
dp[i] = -inf;
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 10; j++) {
if (i - nm[j] >= 0) {
dp[i] = max(dp[i], dp[i - nm[j]] + 1);
}
}
}
int dig = dp[n];
int cur = n;
// for(int i=0;i<n;i++){cout<<i<<":"<<dp[i]<<endl;}
for (int i = 0; i < dig; i++) {
// cout<<i<<" "<<cur<<endl;
int nex = 0;
for (int j = 0; j < 10; j++) {
if (cur >= nm[j] && (dp[cur - nm[j]] + 1 == dp[cur])) {
nex = max(nex, j);
}
}
cout << nex;
cur -= nm[nex];
}
cout << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define BR "\n"
#define SP " "
#define SHOW(x) \
for (int i = 0; i < x.size(); i++) { \
cout << x[i] << SP; \
} \
cout << BR;
#define SHOW2(x) \
for (int j = 0; j < x.size(); j++) { \
SHOW(x[j]); \
} \
cout << BR;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> A(10, 0);
vector<ll> stick = {2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < M; i++) {
int temp;
cin >> temp;
A[temp] = 1;
}
vector<string> dp(1001, "");
for (int i = 1; i < 10; i++) {
if (A[i] == 0)
continue;
ll s = stick[i - 1];
for (int j = 0; j < N; j++) {
if (j + s > N)
break;
if (dp[j] == "" && j > 0)
continue;
string oldString = dp[j + s];
string newString = to_string(i) + dp[j];
if ((newString.length() > oldString.length()) ||
(newString.length() == oldString.length()) &&
(newString > oldString)) {
dp[j + s] = newString;
}
}
}
cout << dp[N] << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define BR "\n"
#define SP " "
#define SHOW(x) \
for (int i = 0; i < x.size(); i++) { \
cout << x[i] << SP; \
} \
cout << BR;
#define SHOW2(x) \
for (int j = 0; j < x.size(); j++) { \
SHOW(x[j]); \
} \
cout << BR;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> A(10, 0);
vector<ll> stick = {2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < M; i++) {
int temp;
cin >> temp;
A[temp] = 1;
}
vector<string> dp(10001, "");
for (int i = 1; i < 10; i++) {
if (A[i] == 0)
continue;
ll s = stick[i - 1];
for (int j = 0; j < N; j++) {
if (j + s > N)
break;
if (dp[j] == "" && j > 0)
continue;
string oldString = dp[j + s];
string newString = to_string(i) + dp[j];
if ((newString.length() > oldString.length()) ||
(newString.length() == oldString.length()) &&
(newString > oldString)) {
dp[j + s] = newString;
}
}
}
cout << dp[N] << "\n";
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p03128 | C++ | Runtime Error | #define DEBUGGING // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)
#ifndef DEBUGGING
#define DEBUG(...)
#else
template <typename T> void debug(T value) { std::cerr << value; }
template <typename T, typename... Ts> void debug(T value, Ts... args) {
std::cerr << value << ", ";
debug(args...);
}
#define DEBUG(...) \
do { \
cerr << " (L" << __LINE__ << ") "; \
cerr << #__VA_ARGS__ << ": "; \
debug(__VA_ARGS__); \
cerr << endl; \
} while (0)
#endif
const int matches[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> A(M);
for (auto &x : A)
cin >> x;
sort(A.begin(), A.end());
vector<vector<int>> dp(N / 2 + 1, vector<int>(N + 1, -1));
REP(k, M) {
int m = matches[A[k]];
dp[0][m] = max(dp[0][m], A[k]);
}
REP(i, N / 2) {
bool placed = false;
REP(j, N + 1) {
if (dp[i][j] < 0)
continue;
REP(k, M) {
int m = matches[A[k]];
if (j + m > N)
continue;
dp[i + 1][j + m] = max(dp[i + 1][j + m], A[k]);
placed = true;
}
}
if (!placed) {
break;
}
}
int mi = -1;
for (int i = N / 2; i >= 0; --i) {
if (dp[i][N] >= 0) {
mi = i;
break;
}
}
assert(mi >= 0);
int s = N;
for (int i = mi; i >= 0; --i) {
int d = dp[i][s];
cout << d;
s -= matches[d];
}
cout << '\n';
}
| #define DEBUGGING // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)
#ifndef DEBUGGING
#define DEBUG(...)
#else
template <typename T> void debug(T value) { std::cerr << value; }
template <typename T, typename... Ts> void debug(T value, Ts... args) {
std::cerr << value << ", ";
debug(args...);
}
#define DEBUG(...) \
do { \
cerr << " (L" << __LINE__ << ") "; \
cerr << #__VA_ARGS__ << ": "; \
debug(__VA_ARGS__); \
cerr << endl; \
} while (0)
#endif
const int matches[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> A(M);
for (auto &x : A)
cin >> x;
sort(A.begin(), A.end());
vector<vector<int>> dp(N / 2 + 1, vector<int>(N + 1, -1));
REP(k, M) {
int m = matches[A[k]];
if (m <= N) {
dp[0][m] = max(dp[0][m], A[k]);
}
}
REP(i, N / 2) {
bool placed = false;
REP(j, N + 1) {
if (dp[i][j] < 0)
continue;
REP(k, M) {
int m = matches[A[k]];
if (j + m > N)
continue;
dp[i + 1][j + m] = max(dp[i + 1][j + m], A[k]);
placed = true;
}
}
if (!placed) {
break;
}
}
int mi = -1;
for (int i = N / 2; i >= 0; --i) {
if (dp[i][N] >= 0) {
mi = i;
break;
}
}
assert(mi >= 0);
int s = N;
for (int i = mi; i >= 0; --i) {
int d = dp[i][s];
cout << d;
s -= matches[d];
}
cout << '\n';
}
| replace | 40 | 41 | 40 | 43 | 0 | |
p03128 | C++ | Runtime Error | // warm heart, wagging tail,and a smile just for you!
// ███████████
// ███╬╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬████╬╬╬╬╬╬███
// ███████████
// ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
// █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
// ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
// ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
// ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
// █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ██████████████
// ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
// ███████ █████
// ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF (1LL << 60)
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// 問題文を読む時間をケチらない!!
int n, m;
cin >> n >> m;
vector<int> a(m);
REP(i, m) cin >> a[i];
sort(a.begin(), a.end());
int num_list[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<P> dp(n + 1, P(-1, -1));
dp[0] = P(0, -1);
REP(i, n) {
REP(j, m)
dp[i + num_list[a[j]]] = max(dp[i + num_list[a[j]]], P(dp[i].fs + 1, a[j]));
}
string ans;
int id = n;
while (id) {
ans += (char)('0' + dp[id].sc);
id -= num_list[dp[id].sc];
}
// reverse(ans.begin(),ans.end());
cout << ans << endl;
return 0;
} | // warm heart, wagging tail,and a smile just for you!
// ███████████
// ███╬╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬████╬╬╬╬╬╬███
// ███████████
// ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
// █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
// ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
// ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
// ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
// █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
// ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
// ██████████████
// ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
// ███████ █████
// ███████████████████
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF (1LL << 60)
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i, a, b) ((a) <= (i) && (i) < (b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int, int> P;
typedef vector<vector<P>> Graph;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// 問題文を読む時間をケチらない!!
int n, m;
cin >> n >> m;
vector<int> a(m);
REP(i, m) cin >> a[i];
sort(a.begin(), a.end());
int num_list[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<P> dp(100000, P(-1, -1));
dp[0] = P(0, -1);
REP(i, n) {
REP(j, m)
dp[i + num_list[a[j]]] = max(dp[i + num_list[a[j]]], P(dp[i].fs + 1, a[j]));
}
string ans;
int id = n;
while (id) {
ans += (char)('0' + dp[id].sc);
id -= num_list[dp[id].sc];
}
// reverse(ans.begin(),ans.end());
cout << ans << endl;
return 0;
} | replace | 59 | 60 | 59 | 60 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
signed main() {
int N, M;
cin >> N >> M;
vi A(M), P = {2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, 0, M) cin >> A[i];
vector<string> dp(N + 1, "-1");
dp[0] = "";
REP(i, 1, N) {
rep(j, 0, M) {
int X = P[A[j] - 1];
if (i - X >= 0 && dp[i - X] != "-1") {
string S = dp[i - X];
S += '0' + A[j];
sort(ALL(S));
reverse(ALL(S));
if (dp[i] == "-1")
dp[i] = S;
else if (S.size() > dp[i].size())
dp[i] = S;
else if (S.size() == dp[i].size() && S > dp[i])
dp[i] = S;
}
}
}
cout << dp[N] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
signed main() {
int N, M;
cin >> N >> M;
vi A(M), P = {2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, 0, M) cin >> A[i];
vector<string> dp(N + 1, "-1");
dp[0] = "";
REP(i, 1, N) {
rep(j, 0, M) {
int X = P[A[j] - 1];
if (i - X >= 0 && dp[i - X] != "-1") {
string S = dp[i - X];
S += '0' + A[j];
sort(ALL(S), greater<char>());
if (dp[i] == "-1")
dp[i] = S;
else if (S.size() > dp[i].size())
dp[i] = S;
else if (S.size() == dp[i].size() && S > dp[i])
dp[i] = S;
}
}
}
cout << dp[N] << endl;
}
| replace | 31 | 33 | 31 | 32 | TLE | |
p03128 | C++ | Runtime Error | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x;
int B[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A(10), C(10);
rep(i, m) {
cin >> x;
A[x] = 1;
C[B[x]] = 1;
}
int dp[5010];
rep(i, 5010) dp[i] = -1;
dp[0] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 2; j <= 7; j++) {
if (C[j] == 1 && i - j >= 0 && dp[i - j] != -1 && dp[i] < dp[i - j] + 1)
dp[i] = dp[i - j] + 1;
}
}
int t = n;
for (int i = 9; i > 0 && t > 0; i--) {
if (A[i] == 0)
continue;
while (t - B[i] >= 0 && dp[t - B[i]] == dp[t] - 1) {
cout << i;
t -= B[i];
}
}
cout << endl;
return 0;
} | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x;
int B[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A(10), C(10);
rep(i, m) {
cin >> x;
A[x] = 1;
C[B[x]] = 1;
}
int dp[10010];
rep(i, 10010) dp[i] = -1;
dp[0] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 2; j <= 7; j++) {
if (C[j] == 1 && i - j >= 0 && dp[i - j] != -1 && dp[i] < dp[i - j] + 1)
dp[i] = dp[i - j] + 1;
}
}
int t = n;
for (int i = 9; i > 0 && t > 0; i--) {
if (A[i] == 0)
continue;
while (t - B[i] >= 0 && dp[t - B[i]] == dp[t] - 1) {
cout << i;
t -= B[i];
}
}
cout << endl;
return 0;
} | replace | 20 | 22 | 20 | 22 | 0 | |
p03128 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
const int C[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int N = 5000 + 100;
int n;
bool can[10];
void readData() {
scanf("%d", &n);
int m, x;
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%d", &x);
can[x] = true;
}
}
string f[N];
bool bigger(string a, string b) {
if (a.length() != b.length())
return a.length() > b.length();
int len = a.length();
for (int i = 0; i < len; i++)
if (a[i] != b[i])
return a[i] > b[i];
return false;
}
void solve() {
for (int i = 1; i <= 9; i++)
if (can[i]) {
char t[] = "x";
t[0] = '0' + i;
f[C[i]] = t;
}
for (int i = 2; i < n; i++)
if (f[i] != "") {
for (int j = 1; j <= 9; j++)
if (can[j]) {
char t[] = "x";
t[0] = '0' + j;
string ns = string(t) + f[i];
if (bigger(ns, f[i + C[j]]))
f[i + C[j]] = ns;
}
}
cout << f[n] << endl;
}
int main() {
readData();
solve();
return 0;
} | #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
const int C[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int N = 10000 + 100;
int n;
bool can[10];
void readData() {
scanf("%d", &n);
int m, x;
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%d", &x);
can[x] = true;
}
}
string f[N];
bool bigger(string a, string b) {
if (a.length() != b.length())
return a.length() > b.length();
int len = a.length();
for (int i = 0; i < len; i++)
if (a[i] != b[i])
return a[i] > b[i];
return false;
}
void solve() {
for (int i = 1; i <= 9; i++)
if (can[i]) {
char t[] = "x";
t[0] = '0' + i;
f[C[i]] = t;
}
for (int i = 2; i < n; i++)
if (f[i] != "") {
for (int j = 1; j <= 9; j++)
if (can[j]) {
char t[] = "x";
t[0] = '0' + j;
string ns = string(t) + f[i];
if (bigger(ns, f[i + C[j]]))
f[i + C[j]] = ns;
}
}
cout << f[n] << endl;
}
int main() {
readData();
solve();
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPI(i, f, n) for (int i = (f); i < (n); ++i)
using namespace std;
typedef long long ll;
int ma[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
// dp[i] : i本使った時の最大値
string dp[10005];
void str_max(string &a, string b) {
if (a.size() < b.size()) {
a = b;
} else if (a.size() == b.size()) {
if (b > a)
a = b;
}
return;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
REP(i, M) { cin >> A[i]; }
// "-"を初期値とする。初期値の場合は、その本数になることがないことを示す。
// はじめは不要かと思ってたけど、dp[0] = "" の状態と、存在しないは違う。
// 存在しない場合はそのdp[i]を起点とすることができない。
REP(i, N) dp[i] = "-";
dp[0] = "";
REP(i, N + 1) {
for (auto x : A) {
// 存在しない場合は飛ばす
if (dp[i] == "-")
continue;
string b = dp[i] + (char)('0' + x);
str_max(dp[i + ma[x]], b);
}
}
cout << dp[N] << endl;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPI(i, f, n) for (int i = (f); i < (n); ++i)
using namespace std;
typedef long long ll;
int ma[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
// dp[i] : i本使った時の最大値
string dp[10020];
void str_max(string &a, string b) {
if (a.size() < b.size()) {
a = b;
} else if (a.size() == b.size()) {
if (b > a)
a = b;
}
return;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
REP(i, M) { cin >> A[i]; }
// "-"を初期値とする。初期値の場合は、その本数になることがないことを示す。
// はじめは不要かと思ってたけど、dp[0] = "" の状態と、存在しないは違う。
// 存在しない場合はそのdp[i]を起点とすることができない。
REP(i, N) dp[i] = "-";
dp[0] = "";
REP(i, N + 1) {
for (auto x : A) {
// 存在しない場合は飛ばす
if (dp[i] == "-")
continue;
string b = dp[i] + (char)('0' + x);
str_max(dp[i + ma[x]], b);
}
}
cout << dp[N] << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
int main() {
#ifndef ONLINE_JUDGE
freopen(".in.txt", "r", stdin);
freopen(".out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, ii;
cin >> n >> m;
vector<int> c = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<bool> can(10);
vector<vector<int>> dp(5001, vector<int>(n + 1, -1));
dp[0][0] = 0;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
can[a] = 1;
}
for (int i = 1; i < 5001; i++)
for (int j = 0; j < n + 1; j++)
for (int k = 9; k; k--)
if (can[k] && j - c[k] > -1 && dp[i - 1][j - c[k]] != -1) {
dp[i][j] = k;
break;
}
for (int i = 5000; i > -1; i--)
if (dp[i][n] != -1) {
ii = i;
break;
}
for (int i = ii; i; i--) {
cout << dp[i][n];
n -= c[dp[i][n]];
}
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
int main() {
// #ifndef ONLINE_JUDGE
// freopen(".in.txt", "r", stdin);
// freopen(".out.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, ii;
cin >> n >> m;
vector<int> c = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<bool> can(10);
vector<vector<int>> dp(5001, vector<int>(n + 1, -1));
dp[0][0] = 0;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
can[a] = 1;
}
for (int i = 1; i < 5001; i++)
for (int j = 0; j < n + 1; j++)
for (int k = 9; k; k--)
if (can[k] && j - c[k] > -1 && dp[i - 1][j - c[k]] != -1) {
dp[i][j] = k;
break;
}
for (int i = 5000; i > -1; i--)
if (dp[i][n] != -1) {
ii = i;
break;
}
for (int i = ii; i; i--) {
cout << dp[i][n];
n -= c[dp[i][n]];
}
return 0;
} | replace | 16 | 20 | 16 | 20 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end()) // O(log n)
#define contains(c, x) (find((c).begin(), (c).end(), x) != (c).end()) // O(n)
#define ill(_x) \
ll _x; \
scanf("%lld", &_x);
#define idb(_x) \
double _x; \
scanf("%lf", &_x);
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b) ((x) >= a && (x) <= b)
#define in1(x, a, b) ((x) > a && (x) < b)
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(), (x).end()
// #define len(array) (sizeof(array)/sizeof((array)[0]))
#define endl '\n'
#define int ll
const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int LLINF = 1000000000000000005LL;
;
const int MOD = (int)(1e9) + 7;
const int MX = 777777 + 5;
const int mod = 1777777777;
const double EPS = 1e-10;
const ll MXP = 8999251775770639633;
const int _500k = 500005;
const int _1m = 1000005;
const int _200k = 200005;
const int _20k = 20005;
const int _100k = 100005;
const int _10k = 10005;
int readint() {
int x;
cin >> x;
return x;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto a : v)
os << a << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto a : v)
os << a << " ";
return os;
}
inline int len(string s) { return s.size(); }
inline int len(int *A) { return (sizeof(A)) / sizeof(A[0]); }
template <typename T> inline int len(vector<T> v) { return v.size(); }
template <typename T> inline int len(set<T> v) { return v.size(); }
template <typename T, typename S> inline int len(map<T, S> v) {
return v.size();
}
int fac[MX + 5];
int power_mod(int x, int y, int p) {
if (y < 0)
return 0;
int res = 1;
x = x % p;
while (y) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int power(int x, int y) {
if (y < 0)
return 0;
int res = 1;
while (y) {
if (y & 1)
res = (res * x);
y = y >> 1;
x *= x;
}
return res;
}
// Returns n^(-1) mod p
int modInverse(int n, int p) { return power_mod(n, p - 2, p); }
int C(int n, int r, int p) {
if (r == 0)
return 1;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
void init(int mod) {
fac[0] = 1;
for (int i = 1; i <= MX; i++)
fac[i] = fac[i - 1] * i % mod;
}
int CC(int a, int b) {
int res = 1;
rep(i, a + 1, a - b + 1) res *= i, res /= a - i + 1;
// rep(i,1,b+1)res /= i;
return res;
}
bool equal(double a, double b) {
return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}
struct UnionFind {
// par[i]:データiが属する木の親の番号。i ==
// par[i]のとき、データiは木の根ノードである
vector<int> par;
// sizes[i]:根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
vector<int> sizes;
UnionFind(int n) : par(n), sizes(n, 1) {
// 最初は全てのデータiがグループiに存在するものとして初期化
rep(i, 0, n) par[i] = i;
}
// データxが属する木の根を得る
int find(int x) {
if (x == par[x])
return x;
return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す
}
// 2つのデータx, yが属する木をマージする
void unite(int x, int y) {
// データの根ノードを得る
x = find(x);
y = find(y);
// 既に同じ木に属しているならマージしない
if (x == y)
return;
// xの木がyの木より大きくなるようにする
if (sizes[x] < sizes[y])
swap(x, y);
// xがyの親になるように連結する
par[y] = x;
sizes[x] += sizes[y];
// sizes[y] = 0; // sizes[y]は無意味な値となるので0を入れておいてもよい
}
// 2つのデータx, yが属する木が同じならtrueを返す
bool same(int x, int y) { return find(x) == find(y); }
// データxが含まれる木の大きさを返す
int size(int x) { return sizes[find(x)]; }
};
// fastest
struct cpmFunctor {
inline bool operator()(const pair<int, int> &p1, const pair<int, int> &p2) {
return p1.first < p2.first ||
(p1.first == p2.first && p1.second < p2.second);
}
};
bool isPrime(int n) {
// Corner case
if (n <= 1)
return false;
if (n == 2 || n == 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
// Check from 2 to n-1
for (int i = 5; i < n; i += 6)
if (n % i == 0)
return false;
for (int i = 7; i < n; i += 6)
if (n % i == 0)
return false;
return true;
}
int cnt(string s, int f) {
int l = INF, r = -1, cnt = 0;
_for(i, s.size() - f + 1) {
if (s[i] == '-' ^ in0(i, l, r))
l = max(r + 1, (ll)i), r = i + f - 1, cnt++;
}
rep(i, s.size() - f + 1, s.size()) if (s[i] == '-' ^ in0(i, l, r)) return -1;
return cnt;
}
set<int> factorize(long long n) {
set<int> factors;
int count = 0;
while (!(n % 2)) {
n >>= 1;
count++;
}
if (count)
factors.insert(2);
for (long long i = 3; i <= 200; i += 2) {
count = 0;
while (n % i == 0) {
count++;
n = n / i;
}
if (count)
factors.insert(i);
}
if (n > 2)
factors.insert(n);
return factors;
}
int A[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
map<int, int, greater<int>> M;
struct cmpMap {
inline bool operator()(const map<int, int> &M1, const map<int, int> &M2) {
int s1 = 0, s2 = 0;
for (auto p1 : M1)
s1 += p1.second;
for (auto p2 : M2)
s2 += p2.second;
if (s1 != s2)
return s1 < s2;
auto p1 = M1.begin(), p2 = M2.begin();
while (*p1 == *p2)
++p1, ++p2;
return p1->first < p2->first ||
(p1->first == p2->first && p1->second < p2->second);
}
};
map<int, int, greater<int>> merge(map<int, int, greater<int>> m1, int t) {
m1[t]++;
return m1;
}
bool les(map<int, int, greater<int>> M1, map<int, int, greater<int>> M2) {
int s1 = 0, s2 = 0;
for (auto p1 : M1)
s1 += p1.second;
for (auto p2 : M2)
s2 += p2.second;
if (s1 != s2)
return s1 < s2;
auto p1 = M1.begin(), p2 = M2.begin();
while (*p1 == *p2)
++p1, ++p2;
return p1->first < p2->first ||
(p1->first == p2->first && p1->second < p2->second);
}
map<int, int, greater<int>> dp[_10k];
bool ok[_10k];
void _() {
int n, m;
cin >> n >> m;
_for(i, m) {
int t = readint();
M[t] = A[t];
}
ok[0] = 1;
_for(i, n + 1) {
if (!i || !dp[i].empty()) {
for (auto m : M)
dp[i + m.second] = les(dp[i + m.second], merge(dp[i], m.first))
? merge(dp[i], m.first)
: dp[i + m.second];
}
}
for (auto p : dp[n])
_for(i, p.second) cout << p.first;
}
#undef int
int main() {
#if __MINGW32__
freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Input.txt", "r",
stdin);
freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Output.txt", "w",
stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
_();
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end()) // O(log n)
#define contains(c, x) (find((c).begin(), (c).end(), x) != (c).end()) // O(n)
#define ill(_x) \
ll _x; \
scanf("%lld", &_x);
#define idb(_x) \
double _x; \
scanf("%lf", &_x);
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b) ((x) >= a && (x) <= b)
#define in1(x, a, b) ((x) > a && (x) < b)
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1)
#define all(x) (x).begin(), (x).end()
// #define len(array) (sizeof(array)/sizeof((array)[0]))
#define endl '\n'
#define int ll
const double PI = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int LLINF = 1000000000000000005LL;
;
const int MOD = (int)(1e9) + 7;
const int MX = 777777 + 5;
const int mod = 1777777777;
const double EPS = 1e-10;
const ll MXP = 8999251775770639633;
const int _500k = 500005;
const int _1m = 1000005;
const int _200k = 200005;
const int _20k = 20005;
const int _100k = 100005;
const int _10k = 10005;
int readint() {
int x;
cin >> x;
return x;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto a : v)
os << a << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto a : v)
os << a << " ";
return os;
}
inline int len(string s) { return s.size(); }
inline int len(int *A) { return (sizeof(A)) / sizeof(A[0]); }
template <typename T> inline int len(vector<T> v) { return v.size(); }
template <typename T> inline int len(set<T> v) { return v.size(); }
template <typename T, typename S> inline int len(map<T, S> v) {
return v.size();
}
int fac[MX + 5];
int power_mod(int x, int y, int p) {
if (y < 0)
return 0;
int res = 1;
x = x % p;
while (y) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int power(int x, int y) {
if (y < 0)
return 0;
int res = 1;
while (y) {
if (y & 1)
res = (res * x);
y = y >> 1;
x *= x;
}
return res;
}
// Returns n^(-1) mod p
int modInverse(int n, int p) { return power_mod(n, p - 2, p); }
int C(int n, int r, int p) {
if (r == 0)
return 1;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
void init(int mod) {
fac[0] = 1;
for (int i = 1; i <= MX; i++)
fac[i] = fac[i - 1] * i % mod;
}
int CC(int a, int b) {
int res = 1;
rep(i, a + 1, a - b + 1) res *= i, res /= a - i + 1;
// rep(i,1,b+1)res /= i;
return res;
}
bool equal(double a, double b) {
return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
}
struct UnionFind {
// par[i]:データiが属する木の親の番号。i ==
// par[i]のとき、データiは木の根ノードである
vector<int> par;
// sizes[i]:根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
vector<int> sizes;
UnionFind(int n) : par(n), sizes(n, 1) {
// 最初は全てのデータiがグループiに存在するものとして初期化
rep(i, 0, n) par[i] = i;
}
// データxが属する木の根を得る
int find(int x) {
if (x == par[x])
return x;
return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す
}
// 2つのデータx, yが属する木をマージする
void unite(int x, int y) {
// データの根ノードを得る
x = find(x);
y = find(y);
// 既に同じ木に属しているならマージしない
if (x == y)
return;
// xの木がyの木より大きくなるようにする
if (sizes[x] < sizes[y])
swap(x, y);
// xがyの親になるように連結する
par[y] = x;
sizes[x] += sizes[y];
// sizes[y] = 0; // sizes[y]は無意味な値となるので0を入れておいてもよい
}
// 2つのデータx, yが属する木が同じならtrueを返す
bool same(int x, int y) { return find(x) == find(y); }
// データxが含まれる木の大きさを返す
int size(int x) { return sizes[find(x)]; }
};
// fastest
struct cpmFunctor {
inline bool operator()(const pair<int, int> &p1, const pair<int, int> &p2) {
return p1.first < p2.first ||
(p1.first == p2.first && p1.second < p2.second);
}
};
bool isPrime(int n) {
// Corner case
if (n <= 1)
return false;
if (n == 2 || n == 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
// Check from 2 to n-1
for (int i = 5; i < n; i += 6)
if (n % i == 0)
return false;
for (int i = 7; i < n; i += 6)
if (n % i == 0)
return false;
return true;
}
int cnt(string s, int f) {
int l = INF, r = -1, cnt = 0;
_for(i, s.size() - f + 1) {
if (s[i] == '-' ^ in0(i, l, r))
l = max(r + 1, (ll)i), r = i + f - 1, cnt++;
}
rep(i, s.size() - f + 1, s.size()) if (s[i] == '-' ^ in0(i, l, r)) return -1;
return cnt;
}
set<int> factorize(long long n) {
set<int> factors;
int count = 0;
while (!(n % 2)) {
n >>= 1;
count++;
}
if (count)
factors.insert(2);
for (long long i = 3; i <= 200; i += 2) {
count = 0;
while (n % i == 0) {
count++;
n = n / i;
}
if (count)
factors.insert(i);
}
if (n > 2)
factors.insert(n);
return factors;
}
int A[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
map<int, int, greater<int>> M;
struct cmpMap {
inline bool operator()(const map<int, int> &M1, const map<int, int> &M2) {
int s1 = 0, s2 = 0;
for (auto p1 : M1)
s1 += p1.second;
for (auto p2 : M2)
s2 += p2.second;
if (s1 != s2)
return s1 < s2;
auto p1 = M1.begin(), p2 = M2.begin();
while (*p1 == *p2)
++p1, ++p2;
return p1->first < p2->first ||
(p1->first == p2->first && p1->second < p2->second);
}
};
map<int, int, greater<int>> merge(map<int, int, greater<int>> m1, int t) {
m1[t]++;
return m1;
}
bool les(map<int, int, greater<int>> M1, map<int, int, greater<int>> M2) {
int s1 = 0, s2 = 0;
for (auto p1 : M1)
s1 += p1.second;
for (auto p2 : M2)
s2 += p2.second;
if (s1 != s2)
return s1 < s2;
auto p1 = M1.begin(), p2 = M2.begin();
while (*p1 == *p2)
++p1, ++p2;
return p1->first < p2->first ||
(p1->first == p2->first && p1->second < p2->second);
}
map<int, int, greater<int>> dp[_10k + 444];
bool ok[_10k];
void _() {
int n, m;
cin >> n >> m;
_for(i, m) {
int t = readint();
M[t] = A[t];
}
ok[0] = 1;
_for(i, n + 1) {
if (!i || !dp[i].empty()) {
for (auto m : M)
dp[i + m.second] = les(dp[i + m.second], merge(dp[i], m.first))
? merge(dp[i], m.first)
: dp[i + m.second];
}
}
for (auto p : dp[n])
_for(i, p.second) cout << p.first;
}
#undef int
int main() {
#if __MINGW32__
freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Input.txt", "r",
stdin);
freopen("C:\\Users\\hiroo\\CLionProjects\\competitive\\Output.txt", "w",
stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
_();
} | replace | 276 | 277 | 276 | 277 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int, int> P;
#define INF 2000000007
#define MINF -2000000007
#define MOD 10e9 + 7
#define MAX 100005
// テンプレ終了
//====================================================================//
int dp[MAX];
// abc118
int main() {
int N, M;
cin >> N >> M;
vector<int> A(N);
REP(i, M) cin >> A[i];
int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
REPS(i, 1, N + 1) dp[i] = MINF;
REPS(i, 2, N + 1) {
REP(j, M) {
if (i - cost[A[j]] < 0)
continue;
dp[i] = max(dp[i], dp[i - cost[A[j]]] + 1);
}
}
sort(ALL(A), [&](int x, int y) { return x > y; });
string str;
for (int i = N; i > 0;) {
REP(j, M) {
if (i - cost[A[j]] < 0)
continue;
if (dp[i - cost[A[j]]] == dp[i] - 1) {
str += to_string(A[j]);
i -= cost[A[j]];
break;
}
}
}
cout << str << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int, int> P;
#define INF 2000000007
#define MINF -2000000007
#define MOD 10e9 + 7
#define MAX 100005
// テンプレ終了
//====================================================================//
int dp[MAX];
// abc118
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
REP(i, M) cin >> A[i];
int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
REPS(i, 1, N + 1) dp[i] = MINF;
REPS(i, 2, N + 1) {
REP(j, M) {
if (i - cost[A[j]] < 0)
continue;
dp[i] = max(dp[i], dp[i - cost[A[j]]] + 1);
}
}
sort(ALL(A), [&](int x, int y) { return x > y; });
string str;
for (int i = N; i > 0;) {
REP(j, M) {
if (i - cost[A[j]] < 0)
continue;
if (dp[i - cost[A[j]]] == dp[i] - 1) {
str += to_string(A[j]);
i -= cost[A[j]];
break;
}
}
}
cout << str << endl;
return 0;
}
| replace | 28 | 29 | 28 | 29 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define reps(i, N) for (int i = 1; i <= (N); i++)
#define repr(i, N) for (int i = (N)-1; i >= 0; i--)
#define pub push_back
template <typename T> void chmax(T &a, T b) { a = max(a, b); };
template <typename T> void chmin(T &a, T b) { a = min(a, b); };
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const int dy[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
//--------------------------------------//
int N, M;
vector<int> A;
const int C[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10000];
void solve() {
rep(i, 10000) { dp[i] = -INF; }
dp[0] = 0;
reps(i, N) {
for (auto a : A) {
if (i - C[a] < 0 or dp[i - C[a]] == -INF)
continue;
chmax(dp[i], dp[i - C[a]] + 1);
}
}
sort(A.begin(), A.end(), greater<int>());
int i = N;
while (i != 0) {
if (dp[i] != -INF) {
for (auto a : A) {
if (i - C[a] >= 0 and dp[i] == dp[i - C[a]] + 1) {
cout << a;
i -= C[a];
break;
}
}
}
}
cout << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
rep(i, M) {
int a;
cin >> a;
A.pub(a);
}
solve();
return 0;
}
| #include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;
#define rep(i, N) for (int i = 0; i < (N); i++)
#define reps(i, N) for (int i = 1; i <= (N); i++)
#define repr(i, N) for (int i = (N)-1; i >= 0; i--)
#define pub push_back
template <typename T> void chmax(T &a, T b) { a = max(a, b); };
template <typename T> void chmin(T &a, T b) { a = min(a, b); };
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const int dy[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
//--------------------------------------//
int N, M;
vector<int> A;
const int C[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10001];
void solve() {
rep(i, 10000) { dp[i] = -INF; }
dp[0] = 0;
reps(i, N) {
for (auto a : A) {
if (i - C[a] < 0 or dp[i - C[a]] == -INF)
continue;
chmax(dp[i], dp[i - C[a]] + 1);
}
}
sort(A.begin(), A.end(), greater<int>());
int i = N;
while (i != 0) {
if (dp[i] != -INF) {
for (auto a : A) {
if (i - C[a] >= 0 and dp[i] == dp[i - C[a]] + 1) {
cout << a;
i -= C[a];
break;
}
}
}
}
cout << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
rep(i, M) {
int a;
cin >> a;
A.pub(a);
}
solve();
return 0;
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
int main() {
int n, m;
cin >> n >> m;
int a[m];
rep(i, m) {
cin >> a[i];
--a[i];
}
int mc[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[n + 1000];
memset(dp, -1, sizeof(dp));
dp[0] = 0;
rep(i, n) {
rep(j, m) {
if (dp[i] != -1) {
dp[i + mc[a[j]]] = max(dp[i] + 1, dp[i + mc[a[j]]]);
}
}
}
sort(a, a + m, greater<int>());
int cur = n;
while (cur) {
rep(i, m) {
if (dp[cur - mc[a[i]]] == dp[cur] - 1) {
cout << a[i] + 1;
cur -= mc[a[i]];
break;
}
}
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
int main() {
int n, m;
cin >> n >> m;
int a[m];
rep(i, m) {
cin >> a[i];
--a[i];
}
int mc[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[n + 1000];
memset(dp, -1, sizeof(dp));
dp[0] = 0;
rep(i, n) {
rep(j, m) {
if (dp[i] != -1) {
dp[i + mc[a[j]]] = max(dp[i] + 1, dp[i + mc[a[j]]]);
}
}
}
sort(a, a + m, greater<int>());
int cur = n;
while (cur) {
rep(i, m) {
if (cur >= mc[a[i]] && dp[cur - mc[a[i]]] == dp[cur] - 1) {
cout << a[i] + 1;
cur -= mc[a[i]];
break;
}
}
}
cout << endl;
}
| replace | 49 | 50 | 49 | 50 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
// 最小本数をマックスまで取る。
// 同じ本数の場合は数字が大きいものだけ。
// priority_queueで1つずつ出して出力っぽい。桁数的に。配列でもいいけど
// ぴったりとれるか判定が難しい・・・。
// 1つの数字をマッチに戻して、最小本数以外で満たす組み合わせがあるか都度確認か
// より少ない本数のものを最大とって、それ以降の探索
// だめなら放流して次の数、とか
// あまり数、
// 3,7とか。あまり1,4,7で7で判定
// 4,6,7とか。余り1,5,9,13で67判定、あまり2,6はんてい,あまり3、7判定
// ぴったりとれる組み合わせがわからぬ
// ひらめかないな
// 457で、57でとりうる組み合わせ。5,7,10,12,14,15くらい用意するとか
// 数字がわかったところでそれがどんな組み合わせかわからねえ
// 0,0 1,0 0,1 1,1 2,0 0,2
// あまりを出す?1とか2とか。3とか。
// 2,5,7だったときに0,1,1になるか。5をとるべきが判定不能
// 4,5,7 0,1,3になるもし余りが1だったら5、3なら7をとる。
// 4,6,7で0,2,3。4ふえたときにずれるからだめ。
// ひらめかないなあ
// ぴったりとる、が鬼門。
// はじめにひくか。
// 使用本数出して、最小以外のものの組み合わせをある程度出す。
// 1個選ぶ場合、2個選ぶ場合。最大2個までかな。
// 3,5,6,7とか。14がきたら、5ひいて3の倍数。16がきたら、7ひいて3のばいすう
// 11がきて、65をとるか74をとるか迫られたとき、つむな。かならず最小をとればいいわけでもなさそうだ
// 最小使用本数の倍数にあるときは、それを並べるのが正解
// そうじゃないとき。
// 13で4,6,7は、67をとる。しかし444+1で3桁まで視野にはいってしまう
// 444+1で出来ない4けた
// 44+5でできない3けた
// 4+9でできない2けた
// 13で67ができたみたいな?
// 14のときは?
// 4442
// 446で完
// 11のとき
// 443でできない
// 47でできた。しかし56が答えだったら終了
// 使える本数で最大組み合わせをだしておくべきか
// 4=4,5=0,6=6,7=7,8=44,9/4=2で2桁、みたいなことか
// 13/4=3,445,
// 15/4=3,447,456とか。この判定どうする
// 何桁なのか定まる必要がある。
// 4,6,7において、9=0 10=2 11=2 12=3 13=2 14=3
// 13の特殊性・・・。
// 4=1,8=2,12=3,16=4・・・としておけば、4+7no11=2,DP的に桁数だせそう
// 9通り*10^4ならすべて検査できそう
// 4,6,7なら、まず4の倍数。次に6+4の倍数。次に7+4の倍数、次に6+6+4の倍数、、、
// 法則違うな。全部やるか。4,6,7, 4+[4,6,7], 6+[4,6,7], 7+[4,6,7];
// D[4]=1,D[6]=1,D[7]=1が初期として。。。どう展開させるのか。
// D[10]=D[6]+1;
// D[4n]=D[4(n-1)]+1;
// D[i]=D[i-n]+1; nは入りうるマッチ数。0<=i<=10000でうめられるかも
// 桁数とったら。数字が何かを探す。
// D[N-A]=D[N]-1になっているようなもののうち、Aの最も数字の大きい値をとる、でいける。
ll N, M, A;
cin >> N >> M;
vector<int> D(N + 1, -10000000), Z(0, 0);
D[0] = 0;
int set[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
unordered_map<int, int> MtoP;
for (int i = 0; i < M; i++) {
int A;
cin >> A;
MtoP[set[A]] = max(MtoP[set[A]], A);
Z.push_back(set[A]);
}
sort(Z.begin(), Z.end());
Z.erase(unique(Z.begin(), Z.end()), Z.end());
int x = Z.size();
for (int i = 0; i < x; i++)
D[Z[i]] = 1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j < x; j++) {
if (i - Z[j] < 0)
continue;
D[i] = max(D[i], D[i - Z[j]] + 1);
}
}
// Zの順番を、数字が大きい順に並べ替えたい
vector<vector<int>> Y(x, vector<int>(2, 0));
for (int i = 0; i < x; i++) {
Y[i][0] = Z[i];
Y[i][1] = MtoP[Z[i]];
}
sort(Y.begin(), Y.end(), [](auto &h, auto &k) { return h[1] > k[1]; });
while (N > 0) {
for (int j = 0; j < x; j++) {
if (N - Y[j][0] < 0)
continue;
if (D[N] == D[N - Y[j][0]] + 1) {
N -= Y[j][0];
cout << Y[j][1];
break;
}
}
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
// 最小本数をマックスまで取る。
// 同じ本数の場合は数字が大きいものだけ。
// priority_queueで1つずつ出して出力っぽい。桁数的に。配列でもいいけど
// ぴったりとれるか判定が難しい・・・。
// 1つの数字をマッチに戻して、最小本数以外で満たす組み合わせがあるか都度確認か
// より少ない本数のものを最大とって、それ以降の探索
// だめなら放流して次の数、とか
// あまり数、
// 3,7とか。あまり1,4,7で7で判定
// 4,6,7とか。余り1,5,9,13で67判定、あまり2,6はんてい,あまり3、7判定
// ぴったりとれる組み合わせがわからぬ
// ひらめかないな
// 457で、57でとりうる組み合わせ。5,7,10,12,14,15くらい用意するとか
// 数字がわかったところでそれがどんな組み合わせかわからねえ
// 0,0 1,0 0,1 1,1 2,0 0,2
// あまりを出す?1とか2とか。3とか。
// 2,5,7だったときに0,1,1になるか。5をとるべきが判定不能
// 4,5,7 0,1,3になるもし余りが1だったら5、3なら7をとる。
// 4,6,7で0,2,3。4ふえたときにずれるからだめ。
// ひらめかないなあ
// ぴったりとる、が鬼門。
// はじめにひくか。
// 使用本数出して、最小以外のものの組み合わせをある程度出す。
// 1個選ぶ場合、2個選ぶ場合。最大2個までかな。
// 3,5,6,7とか。14がきたら、5ひいて3の倍数。16がきたら、7ひいて3のばいすう
// 11がきて、65をとるか74をとるか迫られたとき、つむな。かならず最小をとればいいわけでもなさそうだ
// 最小使用本数の倍数にあるときは、それを並べるのが正解
// そうじゃないとき。
// 13で4,6,7は、67をとる。しかし444+1で3桁まで視野にはいってしまう
// 444+1で出来ない4けた
// 44+5でできない3けた
// 4+9でできない2けた
// 13で67ができたみたいな?
// 14のときは?
// 4442
// 446で完
// 11のとき
// 443でできない
// 47でできた。しかし56が答えだったら終了
// 使える本数で最大組み合わせをだしておくべきか
// 4=4,5=0,6=6,7=7,8=44,9/4=2で2桁、みたいなことか
// 13/4=3,445,
// 15/4=3,447,456とか。この判定どうする
// 何桁なのか定まる必要がある。
// 4,6,7において、9=0 10=2 11=2 12=3 13=2 14=3
// 13の特殊性・・・。
// 4=1,8=2,12=3,16=4・・・としておけば、4+7no11=2,DP的に桁数だせそう
// 9通り*10^4ならすべて検査できそう
// 4,6,7なら、まず4の倍数。次に6+4の倍数。次に7+4の倍数、次に6+6+4の倍数、、、
// 法則違うな。全部やるか。4,6,7, 4+[4,6,7], 6+[4,6,7], 7+[4,6,7];
// D[4]=1,D[6]=1,D[7]=1が初期として。。。どう展開させるのか。
// D[10]=D[6]+1;
// D[4n]=D[4(n-1)]+1;
// D[i]=D[i-n]+1; nは入りうるマッチ数。0<=i<=10000でうめられるかも
// 桁数とったら。数字が何かを探す。
// D[N-A]=D[N]-1になっているようなもののうち、Aの最も数字の大きい値をとる、でいける。
ll N, M, A;
cin >> N >> M;
vector<int> D(N + 100, -1000000), Z(0, 0);
D[0] = 0;
int set[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
unordered_map<int, int> MtoP;
for (int i = 0; i < M; i++) {
int A;
cin >> A;
MtoP[set[A]] = max(MtoP[set[A]], A);
Z.push_back(set[A]);
}
sort(Z.begin(), Z.end());
Z.erase(unique(Z.begin(), Z.end()), Z.end());
int x = Z.size();
for (int i = 0; i < x; i++)
D[Z[i]] = 1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j < x; j++) {
if (i - Z[j] < 0)
continue;
D[i] = max(D[i], D[i - Z[j]] + 1);
}
}
// Zの順番を、数字が大きい順に並べ替えたい
vector<vector<int>> Y(x, vector<int>(2, 0));
for (int i = 0; i < x; i++) {
Y[i][0] = Z[i];
Y[i][1] = MtoP[Z[i]];
}
sort(Y.begin(), Y.end(), [](auto &h, auto &k) { return h[1] > k[1]; });
while (N > 0) {
for (int j = 0; j < x; j++) {
if (N - Y[j][0] < 0)
continue;
if (D[N] == D[N - Y[j][0]] + 1) {
N -= Y[j][0];
cout << Y[j][1];
break;
}
}
}
cout << endl;
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define INF -1e9
typedef long long ll;
ll N;
int M;
int N_digit[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main(void) {
cin >> N >> M;
vector<int> A(N);
ll i;
// dp[i]:i本使って作れる最大の桁数
int j, min, dp[N + 1];
min = 10;
for (i = 0; i < M; i++)
cin >> A[i];
dp[0] = 0;
for (i = 1; i <= N; i++) {
dp[i] = INF;
for (j = 0; j < M; j++) {
if (i >= N_digit[A[j]] && dp[i - N_digit[A[j]]] != INF) {
dp[i] = max(dp[i], dp[i - N_digit[A[j]]] + 1);
}
}
}
sort(A.begin(), A.end(), greater<int>());
ll n = N;
while (n > 0) {
for (i = 0; i < M; i++) {
if (n >= N_digit[A[i]] && dp[n - N_digit[A[i]]] == dp[n] - 1) {
cout << A[i];
n -= (ll)N_digit[A[i]];
break;
}
}
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define INF -1e9
typedef long long ll;
ll N;
int M;
int N_digit[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main(void) {
cin >> N >> M;
vector<int> A(M);
ll i;
// dp[i]:i本使って作れる最大の桁数
int j, min, dp[N + 1];
min = 10;
for (i = 0; i < M; i++)
cin >> A[i];
dp[0] = 0;
for (i = 1; i <= N; i++) {
dp[i] = INF;
for (j = 0; j < M; j++) {
if (i >= N_digit[A[j]] && dp[i - N_digit[A[j]]] != INF) {
dp[i] = max(dp[i], dp[i - N_digit[A[j]]] + 1);
}
}
}
sort(A.begin(), A.end(), greater<int>());
ll n = N;
while (n > 0) {
for (i = 0; i < M; i++) {
if (n >= N_digit[A[i]] && dp[n - N_digit[A[i]]] == dp[n] - 1) {
cout << A[i];
n -= (ll)N_digit[A[i]];
break;
}
}
}
cout << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
vector<int> b = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, m) cin >> a[i];
rep(i, 10) {
bool v = false;
rep(j, m) if (i == a[j]) v = true;
if (!v)
b[i] = -1;
}
vector<string> dp(n + 1, "");
for (int i = 0; i <= n; i++) {
for (int j = 9; j > 0; j--) {
if (b[j] == -1)
continue;
if (i + b[j] > n)
continue;
if (i > 0 && dp[i].size() == 0)
continue;
if (dp[i + b[j]].size() < dp[i].size() + 1) {
char c = '0' + j;
dp[i + b[j]] = dp[i] + c;
} else if (dp[i + b[j]].size() == dp[i].size() + 1) {
char c = '0' + j;
string s = dp[i] + c;
sort(s.begin(), s.end(), greater<char>());
sort(dp[i + b[j]].begin(), dp[i + b[j]].end(), greater<char>());
if (s > dp[i + b[j]])
dp[i + b[j]] = s;
}
}
}
sort(dp[n].begin(), dp[n].end(), greater<char>());
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
vector<int> b = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, m) cin >> a[i];
rep(i, 10) {
bool v = false;
rep(j, m) if (i == a[j]) v = true;
if (!v)
b[i] = -1;
}
vector<string> dp(n + 1, "");
for (int i = 0; i <= n; i++) {
for (int j = 9; j > 0; j--) {
if (b[j] == -1)
continue;
if (i + b[j] > n)
continue;
if (i > 0 && dp[i].size() == 0)
continue;
if (dp[i + b[j]].size() < dp[i].size() + 1) {
char c = '0' + j;
dp[i + b[j]] = dp[i] + c;
} else if (dp[i + b[j]].size() == dp[i].size() + 1) {
char c = '0' + j;
string s = dp[i] + c;
vector<int> cnt1(10), cnt2(10);
rep(k, s.size()) {
cnt1[s[k] - '0']++;
cnt2[dp[i + b[j]][k] - '0']++;
}
for (int k = 9; k > 0; k--) {
if (cnt1[k] > cnt2[k]) {
dp[i + b[j]] = s;
break;
} else if (cnt1[k] < cnt2[k])
break;
}
}
}
}
sort(dp[n].begin(), dp[n].end(), greater<char>());
cout << dp[n] << endl;
} | replace | 35 | 39 | 35 | 47 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return 0;
}
char upper(char c) { return c - 0x20; }
char lower(char c) { return c + 0x20; }
void unique_vector(vector<int> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
// n次元配列の初期化。第2引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
// k!
ll facctorialMethod(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum = sum % MOD * i % MOD;
}
return sum % MOD;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> A(m);
rep(i, m) cin >> A[i];
sort(rall(A));
int Need[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[1010];
Fill(dp, -1);
dp[0] = 0;
rep(i, n + 1) {
rep(j, m) {
int need = Need[A[j] - 1];
if (i < need)
continue;
dp[i] = max(dp[i], dp[i - need] + 1);
}
}
int remain = dp[n];
string ans = "";
while (remain != 0) {
rep(i, m) {
int need = Need[A[i] - 1];
if (n < need)
continue;
if (dp[n - need] == remain - 1) {
ans += to_string(A[i]);
n -= need;
remain--;
break;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n, v) rep(i, n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1, 0, -1, 0}, y_pos[4] = {0, 1, 0, -1};
int ctoi(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return 0;
}
char upper(char c) { return c - 0x20; }
char lower(char c) { return c + 0x20; }
void unique_vector(vector<int> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
// n次元配列の初期化。第2引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
// k!
ll facctorialMethod(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum = sum % MOD * i % MOD;
}
return sum % MOD;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> A(m);
rep(i, m) cin >> A[i];
sort(rall(A));
int Need[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10010];
Fill(dp, -1);
dp[0] = 0;
rep(i, n + 1) {
rep(j, m) {
int need = Need[A[j] - 1];
if (i < need)
continue;
dp[i] = max(dp[i], dp[i - need] + 1);
}
}
int remain = dp[n];
string ans = "";
while (remain != 0) {
rep(i, m) {
int need = Need[A[i] - 1];
if (n < need)
continue;
if (dp[n - need] == remain - 1) {
ans += to_string(A[i]);
n -= need;
remain--;
break;
}
}
}
cout << ans << endl;
}
| replace | 80 | 81 | 80 | 81 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define _ \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
// #define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int mod = (int)1e9 + 7;
const int inf = mod;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) \
{ \
__l(__LINE__); \
__f(#__VA_ARGS__, __VA_ARGS__); \
}
inline void __l(int line) { cerr << "#" << line << ": "; }
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define tr(...)
#endif
template <class T> void smin(T &a, T val) {
if (a > val)
a = val;
}
template <class T> void smax(T &a, T val) {
if (a < val)
a = val;
}
template <typename T>
inline std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
bool first = true;
os << "[";
for (auto i : v) {
if (!first)
os << ", ";
os << i;
first = false;
}
return os << "]";
}
const int N = (int)1e4 + 10;
// make sure N size is correctttt!!!!!!!!!
int n, a[N], m;
vector<int> f;
int dp[15][N];
int solve(int idx, int coins) {
if (coins < 0)
return -inf;
if (idx == m) {
return dp[idx][coins] = ((coins == 0) ? 0 : -inf);
}
int &ans = dp[idx][coins];
if (~ans)
return ans;
ans = 0;
if (f[a[idx]] <= coins) {
smax(ans, 1 + solve(idx, coins - f[a[idx]]));
}
smax(ans, solve(idx + 1, coins));
return ans;
}
void trace(int idx, int coins) {
if (idx == m) {
assert(coins == 0);
exit(0);
}
if (f[a[idx]] <= coins) {
if (solve(idx, coins) == 1 + solve(idx, coins - f[a[idx]])) {
cout << a[idx];
return trace(idx, coins - f[a[idx]]);
}
}
return trace(idx + 1, coins);
}
int32_t main() {
_
cin >>
n >> m;
f = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
memset(dp, -1, sizeof dp);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(a, a + m);
reverse(a, a + m);
int faltu = solve(0, n);
trace(0, n);
// make sure N size is correct!!!!!!!!!
return 0;
} | #include <bits/stdc++.h>
#define _ \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
// #define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int mod = (int)1e9 + 7;
const int inf = mod;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) \
{ \
__l(__LINE__); \
__f(#__VA_ARGS__, __VA_ARGS__); \
}
inline void __l(int line) { cerr << "#" << line << ": "; }
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define tr(...)
#endif
template <class T> void smin(T &a, T val) {
if (a > val)
a = val;
}
template <class T> void smax(T &a, T val) {
if (a < val)
a = val;
}
template <typename T>
inline std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
bool first = true;
os << "[";
for (auto i : v) {
if (!first)
os << ", ";
os << i;
first = false;
}
return os << "]";
}
const int N = (int)1e4 + 10;
// make sure N size is correctttt!!!!!!!!!
int n, a[N], m;
vector<int> f;
int dp[15][N];
int solve(int idx, int coins) {
if (coins < 0)
return -inf;
if (idx == m) {
return dp[idx][coins] = ((coins == 0) ? 0 : -inf);
}
int &ans = dp[idx][coins];
if (~ans)
return ans;
ans = -inf;
if (f[a[idx]] <= coins) {
smax(ans, 1 + solve(idx, coins - f[a[idx]]));
}
smax(ans, solve(idx + 1, coins));
return ans;
}
void trace(int idx, int coins) {
if (idx == m) {
assert(coins == 0);
exit(0);
}
if (f[a[idx]] <= coins) {
if (solve(idx, coins) == 1 + solve(idx, coins - f[a[idx]])) {
cout << a[idx];
return trace(idx, coins - f[a[idx]]);
}
}
return trace(idx + 1, coins);
}
int32_t main() {
_
cin >>
n >> m;
f = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
memset(dp, -1, sizeof dp);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(a, a + m);
reverse(a, a + m);
int faltu = solve(0, n);
trace(0, n);
// make sure N size is correct!!!!!!!!!
return 0;
} | replace | 76 | 77 | 76 | 77 | -6 | d117e5d9-8cd9-4391-8565-42b0c6df7679.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03128/C++/s807083061.cpp:55: void trace(int, int): Assertion `coins == 0' failed.
|
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string MINF = "-";
void chmax(string &a, string b) {
if (a == MINF)
a = b;
else if (b.size() > a.size())
a = b;
else if (b.size() < a.size())
return;
else if (a < b)
a = b;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> a(M);
for (int i = 0; i < M; i++)
cin >> a[i];
int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string MINF = "-";
vector<string> dp(N + 5, MINF);
dp[0] = "";
for (int i = 0; i < N; i++) {
if (dp[i] == MINF)
continue;
for (int j = 0; j < M; j++) {
chmax(dp[i + match[a[j]]], dp[i] + (char)(a[j] + '0'));
chmax(dp[i + match[a[j]]], (char)(a[j] + '0') + dp[i]);
}
}
cout << dp[N] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string MINF = "-";
void chmax(string &a, string b) {
if (a == MINF)
a = b;
else if (b.size() > a.size())
a = b;
else if (b.size() < a.size())
return;
else if (a < b)
a = b;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> a(M);
for (int i = 0; i < M; i++)
cin >> a[i];
int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string MINF = "-";
vector<string> dp(N + 50, MINF);
dp[0] = "";
for (int i = 0; i < N; i++) {
if (dp[i] == MINF)
continue;
for (int j = 0; j < M; j++) {
chmax(dp[i + match[a[j]]], dp[i] + (char)(a[j] + '0'));
chmax(dp[i + match[a[j]]], (char)(a[j] + '0') + dp[i]);
}
}
cout << dp[N] << endl;
} | replace | 28 | 29 | 28 | 29 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, a, d[1001], s[9], t[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<ll> v;
int main(void) {
cin >> n >> k;
for (int i = 0; i < k; i++) {
cin >> s[i];
s[i]--;
}
sort(s, s + k);
reverse(s, s + k);
for (int i = 1; i <= n; i++)
d[i] = -(1LL << 30);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k; j++) {
if (i - t[s[j]] < 0)
continue;
if (d[i - t[s[j]]] < 0)
continue;
d[i] = max(d[i], d[i - t[s[j]]] + 1);
}
}
while (n) {
for (int i = 0; i < k; i++) {
if (n - t[s[i]] < 0)
continue;
if (d[n] - 1 == d[n - t[s[i]]]) {
v.push_back(s[i]);
n -= t[s[i]];
break;
}
}
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
cout << v[i] + 1;
}
cout << endl;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, a, d[10001], s[9], t[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<ll> v;
int main(void) {
cin >> n >> k;
for (int i = 0; i < k; i++) {
cin >> s[i];
s[i]--;
}
sort(s, s + k);
reverse(s, s + k);
for (int i = 1; i <= n; i++)
d[i] = -(1LL << 30);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k; j++) {
if (i - t[s[j]] < 0)
continue;
if (d[i - t[s[j]]] < 0)
continue;
d[i] = max(d[i], d[i - t[s[j]]] + 1);
}
}
while (n) {
for (int i = 0; i < k; i++) {
if (n - t[s[i]] < 0)
continue;
if (d[n] - 1 == d[n - t[s[i]]]) {
v.push_back(s[i]);
n -= t[s[i]];
break;
}
}
}
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
cout << v[i] + 1;
}
cout << endl;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p03128 | C++ | Runtime Error | #include "bits/stdc++.h"
#define Rep(i, n) for (int i = 0; i < n; i++)
#define For(i, n1, n2) for (int i = n1; i < n2; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, n1, n2) for (ll i = n1; i < n2; i++)
#define put(a) cout << a << endl;
#define all(a) (a).begin(), (a).end()
#define SORT(c) sort((c).begin(), (c).end())
#define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int n, m;
int main() {
cin >> n >> m;
vector<int> a(m);
REP(i, m) {
cin >> a[i];
a[i]--;
}
vector<int> b = {2, 5, 5, 4, 5, 6, 3, 7, 6};
map<int, int> mp;
REP(i, m) {
auto itr = mp.find(b[a[i]]);
if (itr != mp.end()) {
if (mp[b[a[i]]] < a[i]) {
mp[b[a[i]]] = a[i];
}
} else {
mp[b[a[i]]] = a[i];
}
}
vector<vector<int>> dp(n + 1);
for (auto itr : mp) {
dp[itr.first].push_back(itr.second);
}
REP(i, n + 1) {
if (!dp[i].empty()) {
for (auto itr : mp) {
if (i + itr.first <= n) {
if (dp[i].size() + 1 > dp[i + itr.first].size()) {
vector<int> temp = dp[i];
temp.push_back(itr.second);
dp[i + itr.first] = temp;
} else if (itr.second > dp[i + itr.first].back()) {
vector<int> temp = dp[i];
temp.push_back(itr.second);
dp[i + itr.first] = temp;
}
}
}
}
}
string res = "";
ll l = dp[n].size();
REP(i, l) { res.push_back((char)(dp[n][l - 1 - i] + 1 + '0')); }
put(res);
return 0;
}
| #include "bits/stdc++.h"
#define Rep(i, n) for (int i = 0; i < n; i++)
#define For(i, n1, n2) for (int i = n1; i < n2; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, n1, n2) for (ll i = n1; i < n2; i++)
#define put(a) cout << a << endl;
#define all(a) (a).begin(), (a).end()
#define SORT(c) sort((c).begin(), (c).end())
#define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int n, m;
int main() {
cin >> n >> m;
vector<int> a(m);
REP(i, m) {
cin >> a[i];
a[i]--;
}
vector<int> b = {2, 5, 5, 4, 5, 6, 3, 7, 6};
map<int, int> mp;
REP(i, m) {
auto itr = mp.find(b[a[i]]);
if (itr != mp.end()) {
if (mp[b[a[i]]] < a[i]) {
mp[b[a[i]]] = a[i];
}
} else {
mp[b[a[i]]] = a[i];
}
}
vector<vector<int>> dp(n + 1);
for (auto itr : mp) {
if (itr.first <= n) {
dp[itr.first].push_back(itr.second);
}
}
REP(i, n + 1) {
if (!dp[i].empty()) {
for (auto itr : mp) {
if (i + itr.first <= n) {
if (dp[i].size() + 1 > dp[i + itr.first].size()) {
vector<int> temp = dp[i];
temp.push_back(itr.second);
dp[i + itr.first] = temp;
} else if (itr.second > dp[i + itr.first].back()) {
vector<int> temp = dp[i];
temp.push_back(itr.second);
dp[i + itr.first] = temp;
}
}
}
}
}
string res = "";
ll l = dp[n].size();
REP(i, l) { res.push_back((char)(dp[n][l - 1 - i] + 1 + '0')); }
put(res);
return 0;
}
| replace | 50 | 51 | 50 | 53 | 0 | |
p03128 | C++ | Runtime Error | #include <iostream>
using namespace std;
int n, m, d[1009];
int h[10] = {0, -2, -5, -5, -4, -5, -6, -3, -7, -6};
bool c[10];
int main(void) {
cin >> n >> m;
fill(c, c + 10, false);
fill(d, d + 1004, -1);
for (int i = 0; i < m; i++) {
int a;
cin >> a;
h[a] *= -1;
c[h[a]] = true;
d[h[a]] = 1;
}
for (int i = 2; i <= n; i++) {
for (int j = 2; j <= 7; j++) {
int p = d[max(0, i - j)];
if (c[j] && p > 0 && d[i] < p + 1)
d[i] = p + 1;
}
// cout<<"--- "<<i<<" : "<<d[i]<<endl;
}
d[0] = 0;
int r = n;
while (r > 0) {
for (int i = 9; i >= 1; i--) {
if (h[i] > 0 && r - h[i] >= 0 && d[r - h[i]] == d[r] - 1) {
r -= h[i];
cout << i;
break;
} else if (i == 1) {
cout << "-" << r << "-" << d[r] << endl;
return 0;
}
}
}
cout << endl;
return 0;
}
| #include <iostream>
using namespace std;
int n, m, d[10009];
int h[10] = {0, -2, -5, -5, -4, -5, -6, -3, -7, -6};
bool c[10];
int main(void) {
cin >> n >> m;
fill(c, c + 10, false);
fill(d, d + 1004, -1);
for (int i = 0; i < m; i++) {
int a;
cin >> a;
h[a] *= -1;
c[h[a]] = true;
d[h[a]] = 1;
}
for (int i = 2; i <= n; i++) {
for (int j = 2; j <= 7; j++) {
int p = d[max(0, i - j)];
if (c[j] && p > 0 && d[i] < p + 1)
d[i] = p + 1;
}
// cout<<"--- "<<i<<" : "<<d[i]<<endl;
}
d[0] = 0;
int r = n;
while (r > 0) {
for (int i = 9; i >= 1; i--) {
if (h[i] > 0 && r - h[i] >= 0 && d[r - h[i]] == d[r] - 1) {
r -= h[i];
cout << i;
break;
} else if (i == 1) {
cout << "-" << r << "-" << d[r] << endl;
return 0;
}
}
}
cout << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
const int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a[i];
sort(a.rbegin(), a.rend());
vector<int> dp(n + 1);
rep(i, m) rep(j, n + 1) if (j - cost[a[i]] >= 0)
chmax(dp[j], dp[j - cost[a[i]]] + 1);
string ans;
int match = n;
int remain = dp[n];
while (match > 0) {
rep(i, m) {
if ((remain != 1 && match - cost[a[i]] >= 0 &&
dp[match - cost[a[i]]] == remain - 1) ||
(remain == 1 && match - cost[a[i]] == 0)) {
match -= cost[a[i]];
ans += '0' + a[i];
remain--;
break;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n - 1; i >= 0; --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
const int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a[i];
sort(a.rbegin(), a.rend());
const int inf = 1001001001;
vector<int> dp(n + 1, -inf);
dp[0] = 0;
rep(i, m) rep(j, n + 1) if (j - cost[a[i]] >= 0)
chmax(dp[j], dp[j - cost[a[i]]] + 1);
string ans;
int match = n;
int remain = dp[n];
while (match > 0) {
rep(i, m) {
if ((remain != 1 && match - cost[a[i]] >= 0 &&
dp[match - cost[a[i]]] == remain - 1) ||
(remain == 1 && match - cost[a[i]] == 0)) {
match -= cost[a[i]];
ans += '0' + a[i];
remain--;
break;
}
}
}
cout << ans << endl;
}
| replace | 44 | 45 | 44 | 47 | TLE | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (int i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N) \
sort(A, A + N, \
[](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
#define endl '\n'
int ctoi(const char c) {
if ('0' <= c && c <= '9')
return (c - '0');
return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v)
is >> x;
return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first;
is >> p.second;
return is;
}
template <typename T, typename U>
ostream &operator>>(ostream &os, const pair<T, U> &p) {
os << p.first << ' ' << p.second;
return os;
}
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
for (auto i = begin(v); i != end(v); ++i) {
if (i != begin(v))
os << ' ';
os << *i;
}
return os;
}
ll dp[1007], C[13];
map<ll, ll> M;
string S, D;
int main() {
ll N, T, A[13], B[13];
D = "0123456789";
B[1] = 2;
B[2] = 5;
B[3] = 5;
B[4] = 4;
B[5] = 5;
B[6] = 6;
B[7] = 3;
B[8] = 7;
B[9] = 6;
cin >> N >> T;
S.clear();
rep(i, T) {
cin >> A[i];
C[A[i]]++;
M[B[A[i]]]++;
}
Rep(i, 1, N + 1) {
Rep(j, 2, 8) {
if (M[j] > 0 && i - j >= 0) {
if (i - j == 0 || dp[i - j] != 0) {
dp[i] = max(dp[i - j] + 1, dp[i]);
}
}
}
}
while (N > 0) {
rRep(i, 9, 1) {
if (N - B[i] >= 0) {
if (C[i] > 0 && dp[N] == dp[N - B[i]] + 1 &&
(dp[N] != 1 || N - B[i] == 0)) {
S = S + D[i];
N = N - B[i];
break;
}
}
}
}
cout << S << endl;
} | #include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
#define cYes cout << "Yes" << endl
#define cNo cout << "No" << endl
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Rep(i, a, b) for (ll i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rRep(i, a, b) for (int i = a; i >= b; i--)
#define crep(i) for (char i = 'a'; i <= 'z'; ++i)
#define psortsecond(A, N) \
sort(A, A + N, \
[](const pii &a, const pii &b) { return a.second < b.second; });
#define ALL(x) (x).begin(), (x).end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
#define endl '\n'
int ctoi(const char c) {
if ('0' <= c && c <= '9')
return (c - '0');
return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v)
is >> x;
return is;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.first;
is >> p.second;
return is;
}
template <typename T, typename U>
ostream &operator>>(ostream &os, const pair<T, U> &p) {
os << p.first << ' ' << p.second;
return os;
}
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
for (auto i = begin(v); i != end(v); ++i) {
if (i != begin(v))
os << ' ';
os << *i;
}
return os;
}
ll dp[10007], C[13];
map<ll, ll> M;
string S, D;
int main() {
ll N, T, A[13], B[13];
D = "0123456789";
B[1] = 2;
B[2] = 5;
B[3] = 5;
B[4] = 4;
B[5] = 5;
B[6] = 6;
B[7] = 3;
B[8] = 7;
B[9] = 6;
cin >> N >> T;
S.clear();
rep(i, T) {
cin >> A[i];
C[A[i]]++;
M[B[A[i]]]++;
}
Rep(i, 1, N + 1) {
Rep(j, 2, 8) {
if (M[j] > 0 && i - j >= 0) {
if (i - j == 0 || dp[i - j] != 0) {
dp[i] = max(dp[i - j] + 1, dp[i]);
}
}
}
}
while (N > 0) {
rRep(i, 9, 1) {
if (N - B[i] >= 0) {
if (C[i] > 0 && dp[N] == dp[N - B[i]] + 1 &&
(dp[N] != 1 || N - B[i] == 0)) {
S = S + D[i];
N = N - B[i];
break;
}
}
}
}
cout << S << endl;
} | replace | 95 | 96 | 95 | 96 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9 + 7)
#define d(x) cerr << #x << "=" << x << endl;
#define p(x) cout << (x) << endl
#define ps(x) cout << (x);
#define pk(x) cout << (x) << " ";
#define pfix(d, x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a, b, c, d, n, m, x[100001], y[100001], z, h, w, k, sum,
mi = inf, ma = -inf, ans, s, t, l, r, res, tmp, itr, p, q;
bool flag;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll, ll>> VP;
ll dp[10000];
ll al[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int main(void) {
cin >> n >> m;
rep(i, n + 1) dp[i] = -inf;
VL v(m);
rep(i, m) cin >> v[i];
dp[0] = 0;
rep(i, n + 1) {
for (ll x : v) {
if (i - al[x - 1] < 0)
continue;
dp[i] = max(dp[i], dp[i - al[x - 1]] + 1);
}
}
sort(all(v));
string ans;
int i = 0;
n++;
rep(tmp, dp[n - 1]) {
rep(j, m) {
if (dp[n - 1 - i - al[v[m - 1 - j] - 1]] < 0 ||
n - 1 - i - al[v[m - 1 - j] - 1] < 0)
continue;
if (dp[n - 1 - i] == dp[n - 1 - i - al[v[m - 1 - j] - 1]] + 1) {
ans += to_string(v[m - 1 - j]);
i += al[v[m - 1 - j] - 1];
break;
}
}
}
p(ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9 + 7)
#define d(x) cerr << #x << "=" << x << endl;
#define p(x) cout << (x) << endl
#define ps(x) cout << (x);
#define pk(x) cout << (x) << " ";
#define pfix(d, x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a, b, c, d, n, m, x[100001], y[100001], z, h, w, k, sum,
mi = inf, ma = -inf, ans, s, t, l, r, res, tmp, itr, p, q;
bool flag;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll, ll>> VP;
ll dp[10010];
ll al[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int main(void) {
cin >> n >> m;
rep(i, n + 1) dp[i] = -inf;
VL v(m);
rep(i, m) cin >> v[i];
dp[0] = 0;
rep(i, n + 1) {
for (ll x : v) {
if (i - al[x - 1] < 0)
continue;
dp[i] = max(dp[i], dp[i - al[x - 1]] + 1);
}
}
sort(all(v));
string ans;
int i = 0;
n++;
rep(tmp, dp[n - 1]) {
rep(j, m) {
if (dp[n - 1 - i - al[v[m - 1 - j] - 1]] < 0 ||
n - 1 - i - al[v[m - 1 - j] - 1] < 0)
continue;
if (dp[n - 1 - i] == dp[n - 1 - i - al[v[m - 1 - j] - 1]] + 1) {
ans += to_string(v[m - 1 - j]);
i += al[v[m - 1 - j] - 1];
break;
}
}
}
p(ans);
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;
vector<int> m = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string comp(string a, string b) {
if (a.length() > b.length())
return a;
else if (a.length() < b.length())
return b;
else {
return a > b ? a : b;
}
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M, 0);
for (int i = 0; i < M; i++)
cin >> A[i];
sort(A.begin(), A.end(), greater<int>());
vector<string> dp(N + 1, "");
for (int i = 0; i < M; i++)
dp[m[A[i]]] = comp(dp[m[A[i]]], to_string(A[i]));
for (int j = 0; j <= N; j++) {
for (int i = 0; i < M; i++) {
if (j - m[A[i]] >= 0 && dp[j - m[A[i]]] != "")
dp[j] = comp(dp[j], dp[j - m[A[i]]] + to_string(A[i]));
}
}
cout << dp[N] << endl;
return 0;
}
| #include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;
vector<int> m = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string comp(string a, string b) {
if (a.length() > b.length())
return a;
else if (a.length() < b.length())
return b;
else {
return a > b ? a : b;
}
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M, 0);
for (int i = 0; i < M; i++)
cin >> A[i];
sort(A.begin(), A.end(), greater<int>());
vector<string> dp(max(N + 1, 10), "");
for (int i = 0; i < M; i++)
dp[m[A[i]]] = comp(dp[m[A[i]]], to_string(A[i]));
for (int j = 0; j <= N; j++) {
for (int i = 0; i < M; i++) {
if (j - m[A[i]] >= 0 && dp[j - m[A[i]]] != "")
dp[j] = comp(dp[j], dp[j - m[A[i]]] + to_string(A[i]));
}
}
cout << dp[N] << endl;
return 0;
}
| replace | 45 | 46 | 45 | 46 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
namespace FastIO {
const char *ln = "\n";
struct Reader {
char buf[1 << 20], *s, *t;
bool EOF_FLG;
Reader() : s(buf), t(buf), EOF_FLG(false){};
char gt() {
return s == t && ((t = (s = buf) + fread(buf, 1, 1 << 20, stdin)) == s)
? EOF
: (*s++);
}
Reader &operator>>(char *str) {
if (EOF_FLG)
return *str = 0, *this;
while ((*str = gt()) != ' ' && *str != '\n' && *str != EOF)
++str;
if (*str == EOF)
EOF_FLG = true;
*str = 0;
return *this;
}
template <typename T> Reader &operator>>(T &x) {
if (EOF_FLG)
return *this;
char c = 0, d;
while (c != EOF && (c < '0' || c > '9'))
d = c, c = gt();
if (c == EOF) {
EOF_FLG = true;
return *this;
} else
x = 0;
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0', c = gt();
if (d == '-')
x = -x;
return *this;
}
} in;
struct Writer {
char buf[1 << 20], *s, *t;
Writer() : s(buf), t(buf + (1 << 20)) {}
~Writer() { fwrite(buf, 1, s - buf, stdout); }
void pt(char c) {
(s == t) ? (fwrite(s = buf, 1, 1 << 20, stdout), *s++ = c) : (*s++ = c);
}
template <typename T> Writer &operator<<(T x) {
if (!x)
return pt('0'), *this;
if (x < 0)
pt('-'), x = -x;
char a[40], t = 0;
while (x)
a[t++] = x % 10, x /= 10;
while (t--)
pt(a[t] + '0');
return *this;
}
Writer &operator<<(const char *s) {
while (*s)
pt(*s++);
return *this;
}
} out;
} // namespace FastIO
using namespace FastIO;
namespace ZDY {
#define ll long long
#define db double
#define sht short
#define MB template <class T>
#define Fur(i, x, y) for (int i = x; i <= y; i++)
#define fur(i, x, y) for (i = x; i <= y; i++)
#define Fdr(i, x, y) for (int i = x; i >= y; i--)
#define fdr(i, x, y) for (i = x; i >= y; i--)
#define clr(x, y) memset(x, y, sizeof(x))
#define cpy(x, y) memcpy(x, y, sizeof(x))
#define inf 0x3f3f3f3f
#define fin(s) freopen(s ".in", "r", stdin)
#define fout(s) freopen(s ".out", "w", stdout)
#define l2(n) (int(log2(n)))
#define fl(i, x) for (int i = head[x], to; to = e[i].to, i; i = e[i].nxt)
#define fcin ios::sync_with_stdio(false)
MB T ABS(T x) { return x > 0 ? x : -x; }
MB T MAX(T x, T y) { return x >= y ? x : y; }
MB T MIN(T x, T y) { return x <= y ? x : y; }
MB T GCD(T x, T y) { return y ? GCD(y, x % y) : x; }
void SWAP(int &x, int &y) {
x ^= y;
y ^= x;
x ^= y;
}
} // namespace ZDY
using namespace ZDY;
using namespace std;
#define N 10001
string f[N];
int n, m, a[10], c[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void upd(string &x, string y) {
if (x == "0")
return (void)(x = y);
if (x.size() < y.size())
x = y;
if (x.size() == y.size() && x < y)
x = y;
}
int main() {
in >> n >> m;
Fur(i, 1, m) in >> a[i];
Fur(i, 0, n) f[i] = "0";
f[0] = "";
Fur(i, 0, n) if (f[i] != "0") Fur(j, 1, m)
upd(f[i + c[a[j]]], f[i] + char(a[j] + 48));
cout << f[n] << endl;
} | #include <bits/stdc++.h>
namespace FastIO {
const char *ln = "\n";
struct Reader {
char buf[1 << 20], *s, *t;
bool EOF_FLG;
Reader() : s(buf), t(buf), EOF_FLG(false){};
char gt() {
return s == t && ((t = (s = buf) + fread(buf, 1, 1 << 20, stdin)) == s)
? EOF
: (*s++);
}
Reader &operator>>(char *str) {
if (EOF_FLG)
return *str = 0, *this;
while ((*str = gt()) != ' ' && *str != '\n' && *str != EOF)
++str;
if (*str == EOF)
EOF_FLG = true;
*str = 0;
return *this;
}
template <typename T> Reader &operator>>(T &x) {
if (EOF_FLG)
return *this;
char c = 0, d;
while (c != EOF && (c < '0' || c > '9'))
d = c, c = gt();
if (c == EOF) {
EOF_FLG = true;
return *this;
} else
x = 0;
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0', c = gt();
if (d == '-')
x = -x;
return *this;
}
} in;
struct Writer {
char buf[1 << 20], *s, *t;
Writer() : s(buf), t(buf + (1 << 20)) {}
~Writer() { fwrite(buf, 1, s - buf, stdout); }
void pt(char c) {
(s == t) ? (fwrite(s = buf, 1, 1 << 20, stdout), *s++ = c) : (*s++ = c);
}
template <typename T> Writer &operator<<(T x) {
if (!x)
return pt('0'), *this;
if (x < 0)
pt('-'), x = -x;
char a[40], t = 0;
while (x)
a[t++] = x % 10, x /= 10;
while (t--)
pt(a[t] + '0');
return *this;
}
Writer &operator<<(const char *s) {
while (*s)
pt(*s++);
return *this;
}
} out;
} // namespace FastIO
using namespace FastIO;
namespace ZDY {
#define ll long long
#define db double
#define sht short
#define MB template <class T>
#define Fur(i, x, y) for (int i = x; i <= y; i++)
#define fur(i, x, y) for (i = x; i <= y; i++)
#define Fdr(i, x, y) for (int i = x; i >= y; i--)
#define fdr(i, x, y) for (i = x; i >= y; i--)
#define clr(x, y) memset(x, y, sizeof(x))
#define cpy(x, y) memcpy(x, y, sizeof(x))
#define inf 0x3f3f3f3f
#define fin(s) freopen(s ".in", "r", stdin)
#define fout(s) freopen(s ".out", "w", stdout)
#define l2(n) (int(log2(n)))
#define fl(i, x) for (int i = head[x], to; to = e[i].to, i; i = e[i].nxt)
#define fcin ios::sync_with_stdio(false)
MB T ABS(T x) { return x > 0 ? x : -x; }
MB T MAX(T x, T y) { return x >= y ? x : y; }
MB T MIN(T x, T y) { return x <= y ? x : y; }
MB T GCD(T x, T y) { return y ? GCD(y, x % y) : x; }
void SWAP(int &x, int &y) {
x ^= y;
y ^= x;
x ^= y;
}
} // namespace ZDY
using namespace ZDY;
using namespace std;
#define N 10001
string f[N + 100];
int n, m, a[10], c[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
void upd(string &x, string y) {
if (x == "0")
return (void)(x = y);
if (x.size() < y.size())
x = y;
if (x.size() == y.size() && x < y)
x = y;
}
int main() {
in >> n >> m;
Fur(i, 1, m) in >> a[i];
Fur(i, 0, n) f[i] = "0";
f[0] = "";
Fur(i, 0, n) if (f[i] != "0") Fur(j, 1, m)
upd(f[i + c[a[j]]], f[i] + char(a[j] + 48));
cout << f[n] << endl;
} | replace | 97 | 98 | 97 | 98 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
詰まった時に、別の分野の問題として考え直す(これdpでは?、グラフとしてみればいいのでは?)
多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
typedef tuple<ll, ll, ll> T;
const string inf = "-";
void chmax(string &a, string b) {
if (a == inf)
a = b;
else if (a.length() < b.length())
a = b;
else if (a.length() == b.length()) {
if (a < b)
a = b;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> a(m);
for (int i = 0; i < m; ++i)
cin >> a[i];
vector<string> dp(1500, inf);
dp[0] = "";
for (int i = 0; i <= n; ++i) {
if (dp[i] == inf)
continue;
for (int j = 0; j < m; ++j) {
chmax(dp[i + match[a[j]]], dp[i] + (char)(a[j] + '0'));
}
}
cout << dp[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return
// true; } return false; } template<class T> inline bool chmin(T& a, T b) { if
// (a > b) { a = b; return true; } return false; }
/* attention
long longのシフト演算には気をつけよう
タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
sizeは(int)とキャストしよう
ごちゃごちゃ場合分けを考える前に全探索は考えましたか?
詰まった時に、別の分野の問題として考え直す(これdpでは?、グラフとしてみればいいのでは?)
多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
*/
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
ll power(ll x, ll n) {
if (n == 0)
return 1;
ll res = power(x, n / 2);
if (n % 2 == 0)
return res * res;
else
return res * res * x;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
/* <--------------------------------------------> */
typedef tuple<ll, ll, ll> T;
const string inf = "-";
void chmax(string &a, string b) {
if (a == inf)
a = b;
else if (a.length() < b.length())
a = b;
else if (a.length() == b.length()) {
if (a < b)
a = b;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> a(m);
for (int i = 0; i < m; ++i)
cin >> a[i];
vector<string> dp(15000, inf);
dp[0] = "";
for (int i = 0; i <= n; ++i) {
if (dp[i] == inf)
continue;
for (int j = 0; j < m; ++j) {
chmax(dp[i + match[a[j]]], dp[i] + (char)(a[j] + '0'));
}
}
cout << dp[n] << endl;
return 0;
} | replace | 82 | 83 | 82 | 83 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string s[1010];
int main() {
int n, m;
cin >> n >> m;
int a[m];
for (int i = 0; i < m; i++)
cin >> a[i];
for (int i = 0; i <= 1010; i++)
s[i] = "0";
s[0] = "";
for (int i = 0; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (s[i] == "0")
continue;
string t = s[i] + to_string(a[j]);
int k = i + num[a[j]];
if (s[k] == "")
s[k] = t;
else if (s[k].length() == t.length()) {
s[k] = max(s[k], t);
} else if (s[k].length() < t.length()) {
s[k] = t;
}
}
}
cout << s[n] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string s[10010];
int main() {
int n, m;
cin >> n >> m;
int a[m];
for (int i = 0; i < m; i++)
cin >> a[i];
for (int i = 0; i <= 1010; i++)
s[i] = "0";
s[0] = "";
for (int i = 0; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (s[i] == "0")
continue;
string t = s[i] + to_string(a[j]);
int k = i + num[a[j]];
if (s[k] == "")
s[k] = t;
else if (s[k].length() == t.length()) {
s[k] = max(s[k], t);
} else if (s[k].length() < t.length()) {
s[k] = t;
}
}
}
cout << s[n] << endl;
return 0;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define etm \
cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define vi vector<int>
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define inf 1e18
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vector<pair<ll, ll>>>
#define vvll vector<vector<ll>>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define pqll priority_queue<ll>
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define umll unordered_map<ll, ll>
#define mll map<ll, ll>
#define input(a, n) \
ll I; \
rep(I, 0, n - 1, 1) cin >> a[I];
#define countbit __builtin_popcount // Number of set bits .
#define fbo(k) find_by_order // K-th element in a set (counting from zero) .
#define ook(k) order_of_key // Number of items strictly smaller than k .
#define lb lower_bound
#define up upper_bound
#define in insert
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll ceil(long double a) {
ll b = a;
if (a == b) {
return b;
} else {
return b + 1;
}
}
ll floor(long double a) {
ll b = a;
return b;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void sieve(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = 26) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
ll nCr(ll n, ll k) {
ll res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (ll i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
class DSU {
public:
vll parent, size;
public:
DSU(ll n) {
parent.resize(n + 1);
size.resize(n + 1);
for (ll i = 1; i <= n; i++) {
parent[i] = i;
size[i] = 1;
}
}
public:
ll find_set(ll x) {
if (parent[x] == x) {
return x;
}
return parent[x] = find_set(parent[x]);
}
public:
void union_set(ll x, ll y) {
x = find_set(x);
y = find_set(y);
if (x != y) {
parent[y] = x;
}
}
};
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.fi == p2.fi) {
return p1.se > p2.se;
}
return p1.fi > p2.fi;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
ll ToInt(char ch) { return ch - '0'; }
char ToChar(ll a) { return a + '0'; }
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void printVectorPair(vpll v) {
for (ll i = 0; i < v.size(); i++) {
cout << v[i].fi << " " << v[i].se << "\n";
}
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
mod = mod * 10 + digit;
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
struct SegmentTree {
ll n;
vll v;
SegmentTree(ll size) {
n = 4 * size + 1;
v.resize(n, 0);
}
void build(ll ar[], ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] = ar[ipos];
else {
ll mid = (ipos + fpos) / 2;
build(ar, ipos, mid, pos * 2);
build(ar, mid + 1, fpos, pos * 2 + 1);
v[pos] = v[pos * 2] + v[pos * 2 + 1];
}
}
void update(ll index, ll val, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] += val;
else {
v[pos] += val;
ll mid = (ipos + fpos) / 2;
if (mid >= index)
update(index, val, ipos, mid, pos * 2);
else
update(index, val, mid + 1, fpos, pos * 2 + 1);
}
}
ll get_sum(ll l, ll r, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return 0;
if (l > r)
return 0;
ll mid = (ipos + fpos) / 2;
if ((l == ipos) && (r == fpos))
return v[pos];
else
return get_sum(l, min(mid, r), ipos, mid, pos * 2) +
get_sum(max(mid + 1, l), r, mid + 1, fpos, pos * 2 + 1);
}
};
struct BIT {
vector<ll> bitree;
ll n;
BIT(ll n) {
this->n = n;
bitree.resize(n + 1, 0);
}
void update(ll idx, ll val) {
idx++;
while (idx <= n) {
bitree[idx] += val;
idx += idx & (-idx);
}
}
ll Sum(ll idx) {
ll sum = 0;
idx++;
while (idx > 0) {
sum += bitree[idx];
idx -= idx & (-idx);
}
return sum;
}
};
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
int ma[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
fastio;
ll n, m;
cin >> n >> m;
vll d(m);
vll dp(10001, 0); // i-->max value with i sticks
vector<string> s(10001, "");
rep(i, 0, m - 1, 1) {
cin >> d[i];
dp[ma[d[i] - 1]] = 1;
s[ma[d[i] - 1]] = (char)(d[i] + '0');
}
sort(all(d));
rep(i, 0, n, 1) {
rep(j, 0, m - 1, 1) {
if (i >= ma[d[j] - 1] and dp[i - ma[d[j] - 1]] > 0) {
ll temp = dp[i];
dp[i] = max(dp[i], dp[i - ma[d[j] - 1]] + 1);
string temps = s[i - ma[d[j] - 1]] + (char)(d[j] + '0');
sort(all(temps), greater<char>());
if (dp[i] > temp)
s[i] = temps;
else if (dp[i - ma[d[j] - 1]] + 1 == temp and
s[i].length() == temps.length())
s[i] = max(s[i], temps);
}
}
}
cout << s[n] << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define etm \
cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define doub long double
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define vi vector<int>
#define mi map<int, int>
#define mull map<ull, ull>
#define stp setprecision(20)
#define N 100005
#define rep(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define repb(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
#define MOD 1000000007
#define ld long double
#define inf 1e18
#define mp make_pair
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vector<pair<ll, ll>>>
#define vvll vector<vector<ll>>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define test \
ll T; \
cin >> T; \
while (T--)
#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define show(w, size) \
for (ll i = 0; i < size; i++) \
cout << w[i] << " ";
#define print(a) cout << a << "\n";
#define pqll priority_queue<ll>
#define mset(dp, no) memset(dp, no, sizeof(dp))
#define umll unordered_map<ll, ll>
#define mll map<ll, ll>
#define input(a, n) \
ll I; \
rep(I, 0, n - 1, 1) cin >> a[I];
#define countbit __builtin_popcount // Number of set bits .
#define fbo(k) find_by_order // K-th element in a set (counting from zero) .
#define ook(k) order_of_key // Number of items strictly smaller than k .
#define lb lower_bound
#define up upper_bound
#define in insert
// #define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
using namespace std;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll isPrime(ll n) {
ll p = (ll)sqrt(n);
rep(i, 2, p, 1) if (n % i == 0) return 0;
return 1;
} // reuturn 1 if prime
ll pow(ll b, ll e) {
if (e == 0)
return 1;
else if (e % 2 == 0) {
ll a = pow(b, e / 2);
return a * a;
} else {
ll a = pow(b, e / 2);
return b * a * a;
}
}
ll powm(ll x, ll y, ll m = MOD) {
x = x % m;
ll res = 1;
while (y) {
if (y & 1)
res = res * x;
res %= m;
y = y >> 1;
x = x * x;
x %= m;
}
return res;
}
ll ceil(long double a) {
ll b = a;
if (a == b) {
return b;
} else {
return b + 1;
}
}
ll floor(long double a) {
ll b = a;
return b;
}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll a, ll m) { return powm(a, m - 2, m); }
bool issq(ll n) {
ll p = sqrt(n);
return p * p == n;
}
vll prime; // if i==prime[i] then prime otherwise smallest prime factor of that
// number
void sieve(ll n) {
prime.resize(n + 1, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i * i <= n; i++)
if (prime[i])
for (ll j = i * i; j <= n; j += i)
prime[j] = 0;
}
ll extended_GCD(ll a, ll b, ll &x, ll &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
ll x1, y1;
ll gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
ll mulInv(ll a, ll mod = 26) {
ll x, y;
extended_GCD(a, mod, x, y);
if (x < 0)
x += mod;
return x;
}
ll find(ll num[], ll rem[], ll k, ll prod) {
// Compute product of all numbers
ll result = 0;
// Apply above formula
for (ll i = 0; i < k; i++) {
ll pp = prod / num[i];
result += rem[i] * mulInv(pp, num[i]) * pp;
}
return result % prod;
}
ll nCr(ll n, ll k) {
ll res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of
// [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
for (ll i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
class DSU {
public:
vll parent, size;
public:
DSU(ll n) {
parent.resize(n + 1);
size.resize(n + 1);
for (ll i = 1; i <= n; i++) {
parent[i] = i;
size[i] = 1;
}
}
public:
ll find_set(ll x) {
if (parent[x] == x) {
return x;
}
return parent[x] = find_set(parent[x]);
}
public:
void union_set(ll x, ll y) {
x = find_set(x);
y = find_set(y);
if (x != y) {
parent[y] = x;
}
}
};
bool cmp(pair<ll, ll> &p1, pair<ll, ll> &p2) {
if (p1.fi == p2.fi) {
return p1.se > p2.se;
}
return p1.fi > p2.fi;
}
bool isPalindrome(string s) {
ll i, j;
for (i = 0, j = s.length() - 1; i <= j; i++, j--) {
if (s[i] != s[j]) {
return 0;
}
}
return 1;
}
ll ToInt(char ch) { return ch - '0'; }
char ToChar(ll a) { return a + '0'; }
bool isSubSeq(string str1, string str2, ll m, ll n) {
// Base Cases
if (m == 0)
return true;
if (n == 0)
return false;
// If last characters of two strings are matching
if (str1[m - 1] == str2[n - 1])
return isSubSeq(str1, str2, m - 1, n - 1);
// If last characters are not matching
return isSubSeq(str1, str2, m, n - 1);
}
void printVectorPair(vpll v) {
for (ll i = 0; i < v.size(); i++) {
cout << v[i].fi << " " << v[i].se << "\n";
}
}
void modBigNumber(string num, ll m) {
// Store the modulus of big number
vector<int> vec;
ll mod = 0;
// Do step by step division
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
mod = mod * 10 + digit;
int quo = mod / m;
if ((vec.size() != 0) || (quo != 0)) // to remove initiale zeros
vec.push_back(quo);
mod = mod % m;
}
// cout << "\nRemainder : " << mod << "\n";
// cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
return;
}
struct SegmentTree {
ll n;
vll v;
SegmentTree(ll size) {
n = 4 * size + 1;
v.resize(n, 0);
}
void build(ll ar[], ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] = ar[ipos];
else {
ll mid = (ipos + fpos) / 2;
build(ar, ipos, mid, pos * 2);
build(ar, mid + 1, fpos, pos * 2 + 1);
v[pos] = v[pos * 2] + v[pos * 2 + 1];
}
}
void update(ll index, ll val, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return;
if (ipos == fpos)
v[pos] += val;
else {
v[pos] += val;
ll mid = (ipos + fpos) / 2;
if (mid >= index)
update(index, val, ipos, mid, pos * 2);
else
update(index, val, mid + 1, fpos, pos * 2 + 1);
}
}
ll get_sum(ll l, ll r, ll ipos, ll fpos, ll pos = 1) {
if (ipos > fpos)
return 0;
if (l > r)
return 0;
ll mid = (ipos + fpos) / 2;
if ((l == ipos) && (r == fpos))
return v[pos];
else
return get_sum(l, min(mid, r), ipos, mid, pos * 2) +
get_sum(max(mid + 1, l), r, mid + 1, fpos, pos * 2 + 1);
}
};
struct BIT {
vector<ll> bitree;
ll n;
BIT(ll n) {
this->n = n;
bitree.resize(n + 1, 0);
}
void update(ll idx, ll val) {
idx++;
while (idx <= n) {
bitree[idx] += val;
idx += idx & (-idx);
}
}
ll Sum(ll idx) {
ll sum = 0;
idx++;
while (idx > 0) {
sum += bitree[idx];
idx -= idx & (-idx);
}
return sum;
}
};
ll sumofdigits(ll a) {
ll val = 0;
while (a > 0) {
val += a % 10;
a /= 10;
}
return val;
}
int ma[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
fastio;
ll n, m;
cin >> n >> m;
vll d(m);
vll dp(20001, 0); // i-->max value with i sticks
vector<string> s(20001, "");
rep(i, 0, m - 1, 1) {
cin >> d[i];
dp[ma[d[i] - 1]] = 1;
s[ma[d[i] - 1]] = (char)(d[i] + '0');
}
sort(all(d));
rep(i, 0, n, 1) {
rep(j, 0, m - 1, 1) {
if (i >= ma[d[j] - 1] and dp[i - ma[d[j] - 1]] > 0) {
ll temp = dp[i];
dp[i] = max(dp[i], dp[i - ma[d[j] - 1]] + 1);
string temps = s[i - ma[d[j] - 1]] + (char)(d[j] + '0');
sort(all(temps), greater<char>());
if (dp[i] > temp)
s[i] = temps;
else if (dp[i - ma[d[j] - 1]] + 1 == temp and
s[i].length() == temps.length())
s[i] = max(s[i], temps);
}
}
}
cout << s[n] << endl;
return 0;
}
| replace | 361 | 363 | 361 | 363 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto &&v : itr)
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T> T minptr(T begin, T end) {
T re = begin;
for (T i = begin + 1; i != end; i++) {
if (*i < *re)
re = i;
}
return re;
}
template <typename T> T maxptr(T begin, T end) {
T re = begin;
for (T i = begin + 1; i != end; i++) {
if (*i > *re)
re = i;
}
return re;
}
int __vmax(int x) { return INT_MAX; }
double __vmax(double x) { return 1e+300; }
ll __vmax(ll x) { return LLONG_MAX; }
int __vmin(int x) { return INT_MIN; }
double __vmin(double x) { return -1e+300; }
ll __vmin(ll x) { return LLONG_MIN; }
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
using V = typename iterator_traits<T>::value_type;
int n = end - begin;
vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
vector<int> id(n);
if (lds && allowequal) {
for (int i = 0; i < n; i++) {
id[i] = n - 1 -
(lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
a[id[i]] = begin[i];
}
} else if (lds) {
for (int i = 0; i < n; i++) {
id[i] = n - 1 -
(upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
a[id[i]] = begin[i];
}
} else if (allowequal) {
for (int i = 0; i < n; i++) {
id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
a[id[i]] = begin[i];
}
} else {
for (int i = 0; i < n; i++) {
id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
a[id[i]] = begin[i];
}
}
int m = *maxptr(id.begin(), id.end());
vector<T> re(m + 1);
for (int i = n - 1; i >= 0; i--) {
if (id[i] == m)
re[m--] = begin + i;
}
return re;
}
bool comp(string a, string b) {
return a.size() > b.size() || (a.size() == b.size() && a > b);
}
string dp[1010];
bool canuse[10];
const int usecount[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int n, m;
cin >> n >> m;
repi(m) {
int x;
cin >> x;
canuse[x] = true;
}
dp[0] = "0";
repi(n) {
if (dp[i] == "")
continue;
string moto = dp[i] == "0" ? "" : dp[i];
repr(j, 1, 10) {
if (!canuse[j])
continue;
string ns = (char)(j + '0') + moto;
if (comp(ns, dp[i + usecount[j]]))
dp[i + usecount[j]] = ns;
ns = moto + (char)(j + '0');
if (comp(ns, dp[i + usecount[j]]))
dp[i + usecount[j]] = ns;
}
}
// repi(n + 1) cout << "dp[" << i << "]:" << dp[i] << endl;
cout << dp[n] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define repi(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define repk(n) for (int k = 0; j < n; k++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (auto i = a; i < b; i++)
#define repv(itr) for (auto &&v : itr)
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T> T minptr(T begin, T end) {
T re = begin;
for (T i = begin + 1; i != end; i++) {
if (*i < *re)
re = i;
}
return re;
}
template <typename T> T maxptr(T begin, T end) {
T re = begin;
for (T i = begin + 1; i != end; i++) {
if (*i > *re)
re = i;
}
return re;
}
int __vmax(int x) { return INT_MAX; }
double __vmax(double x) { return 1e+300; }
ll __vmax(ll x) { return LLONG_MAX; }
int __vmin(int x) { return INT_MIN; }
double __vmin(double x) { return -1e+300; }
ll __vmin(ll x) { return LLONG_MIN; }
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
using V = typename iterator_traits<T>::value_type;
int n = end - begin;
vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
vector<int> id(n);
if (lds && allowequal) {
for (int i = 0; i < n; i++) {
id[i] = n - 1 -
(lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
a[id[i]] = begin[i];
}
} else if (lds) {
for (int i = 0; i < n; i++) {
id[i] = n - 1 -
(upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
a[id[i]] = begin[i];
}
} else if (allowequal) {
for (int i = 0; i < n; i++) {
id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
a[id[i]] = begin[i];
}
} else {
for (int i = 0; i < n; i++) {
id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
a[id[i]] = begin[i];
}
}
int m = *maxptr(id.begin(), id.end());
vector<T> re(m + 1);
for (int i = n - 1; i >= 0; i--) {
if (id[i] == m)
re[m--] = begin + i;
}
return re;
}
bool comp(string a, string b) {
return a.size() > b.size() || (a.size() == b.size() && a > b);
}
string dp[10010];
bool canuse[10];
const int usecount[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int n, m;
cin >> n >> m;
repi(m) {
int x;
cin >> x;
canuse[x] = true;
}
dp[0] = "0";
repi(n) {
if (dp[i] == "")
continue;
string moto = dp[i] == "0" ? "" : dp[i];
repr(j, 1, 10) {
if (!canuse[j])
continue;
string ns = (char)(j + '0') + moto;
if (comp(ns, dp[i + usecount[j]]))
dp[i + usecount[j]] = ns;
ns = moto + (char)(j + '0');
if (comp(ns, dp[i + usecount[j]]))
dp[i + usecount[j]] = ns;
}
}
// repi(n + 1) cout << "dp[" << i << "]:" << dp[i] << endl;
cout << dp[n] << endl;
}
| replace | 75 | 76 | 75 | 76 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
int main() {
int N, M, X[10] = {100, 2, 5, 5, 4, 5, 6, 3, 7, 6}, DP[10010] = {},
INF = 1145141919;
vector<int> V;
cin >> N >> M;
for (int i = 0; i <= N; i++) {
DP[i] = -INF;
}
DP[0] = 0;
for (int i = 0; i < M; i++) {
int A;
cin >> A;
V.emplace_back(A);
}
sort(V.begin(), V.end(), greater<int>());
for (int i = 1; i <= N; i++) {
for (int j : V) {
if (X[j] > i)
continue;
DP[i] = max(DP[i], DP[i - X[j]] + 1);
}
}
int D = N;
while (D != 0) {
for (int j : V) {
if (DP[D - X[j]] == DP[D] - 1) {
cout << j;
D -= X[j];
break;
}
}
}
} | #include "bits/stdc++.h"
using namespace std;
int main() {
int N, M, X[10] = {100, 2, 5, 5, 4, 5, 6, 3, 7, 6}, DP[10010] = {},
INF = 1145141919;
vector<int> V;
cin >> N >> M;
for (int i = 0; i <= N; i++) {
DP[i] = -INF;
}
DP[0] = 0;
for (int i = 0; i < M; i++) {
int A;
cin >> A;
V.emplace_back(A);
}
sort(V.begin(), V.end(), greater<int>());
for (int i = 1; i <= N; i++) {
for (int j : V) {
if (X[j] > i)
continue;
DP[i] = max(DP[i], DP[i - X[j]] + 1);
}
}
int D = N;
while (D != 0) {
for (int j : V) {
if (D >= X[j]) {
if (DP[D - X[j]] == DP[D] - 1) {
cout << j;
D -= X[j];
break;
}
}
}
}
} | replace | 28 | 32 | 28 | 34 | TLE | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
char A[10];
cin >> N >> M;
int C[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < M; i++) {
cin >> A[i];
}
string dp[10010] = {};
bool possible[10010] = {};
possible[0] = true;
for (int i = 2; i <= N; i++) {
string tmp[10] = {};
for (int j = 0; j < M; j++) {
if (i - C[A[j] - '0'] >= 0 && possible[i - C[A[j] - '0']]) {
tmp[j] = dp[i - C[A[j] - '0']] + A[j];
sort(tmp[j].begin(), tmp[j].end(), greater<char>());
possible[i] = true;
}
}
dp[i] = tmp[0];
for (int k = 1; k < M; k++) {
if (tmp[k].size() > dp[i].size() ||
(tmp[k].size() == dp[i].size() && tmp[k] >= dp[i]))
dp[i] = tmp[k];
}
}
cout << dp[N] << endl;
} | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
char A[10];
cin >> N >> M;
int C[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < M; i++) {
cin >> A[i];
}
string dp[10010] = {};
bool possible[10010] = {};
possible[0] = true;
for (int i = 2; i <= N; i++) {
string tmp[10] = {};
for (int j = 0; j < M; j++) {
if (i - C[A[j] - '0'] >= 0 && possible[i - C[A[j] - '0']]) {
tmp[j] = A[j] + dp[i - C[A[j] - '0']];
if (tmp[j].size() > 1 && tmp[j].at(0) < tmp[j].at(1)) {
sort(tmp[j].begin(), tmp[j].end(), greater<char>());
}
possible[i] = true;
}
}
dp[i] = tmp[0];
for (int k = 1; k < M; k++) {
if (tmp[k].size() > dp[i].size() ||
(tmp[k].size() == dp[i].size() && tmp[k] >= dp[i]))
dp[i] = tmp[k];
}
}
cout << dp[N] << endl;
} | replace | 18 | 20 | 18 | 22 | TLE | |
p03128 | C++ | Runtime Error | #include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
ll n, m, a[10];
string str[10010], test[10];
map<ll, ll> mp;
map<ll, string> np;
bool jud[1010], h[10];
int main(void) {
mp[1] = 2, mp[2] = 5, mp[3] = 5, mp[4] = 4;
mp[5] = 5, mp[6] = 6, mp[7] = 3, mp[8] = 7;
mp[9] = 6;
np[1] = "1", np[2] = "2", np[3] = "3", np[4] = "4", np[5] = "5";
np[6] = "6", np[7] = "7", np[8] = "8", np[9] = "9";
jud[0] = true;
cin >> n >> m;
for (ll i = 0; i < m; i++)
cin >> a[i];
for (ll i = 2; i <= n; i++) {
if (i > 10)
str[i - 10] = "9";
for (int j = 0; j < m; j++)
h[j] = false;
for (ll j = 0; j < m; j++) {
if (i < mp[a[j]])
continue;
if (!jud[i - mp[a[j]]])
continue;
h[j] = true;
test[j] = str[i - mp[a[j]]] + np[a[j]];
}
ll len = 0, num = -1;
for (ll j = 0; j < m; j++) {
if (!h[j])
continue;
if (test[j].length() > len) {
len = test[j].length();
num = j;
} else if (test[j].length() == len) {
if (test[j] > test[num]) {
num = j;
}
}
}
if (num == -1)
continue;
str[i] = test[num];
jud[i] = true;
}
for (ll i = 0; i < str[n].length(); i++)
cout << str[n][i];
cout << endl;
}
| #include <iostream>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
ll n, m, a[10];
string str[10010], test[10];
map<ll, ll> mp;
map<ll, string> np;
bool jud[10010], h[10];
int main(void) {
mp[1] = 2, mp[2] = 5, mp[3] = 5, mp[4] = 4;
mp[5] = 5, mp[6] = 6, mp[7] = 3, mp[8] = 7;
mp[9] = 6;
np[1] = "1", np[2] = "2", np[3] = "3", np[4] = "4", np[5] = "5";
np[6] = "6", np[7] = "7", np[8] = "8", np[9] = "9";
jud[0] = true;
cin >> n >> m;
for (ll i = 0; i < m; i++)
cin >> a[i];
for (ll i = 2; i <= n; i++) {
if (i > 10)
str[i - 10] = "9";
for (int j = 0; j < m; j++)
h[j] = false;
for (ll j = 0; j < m; j++) {
if (i < mp[a[j]])
continue;
if (!jud[i - mp[a[j]]])
continue;
h[j] = true;
test[j] = str[i - mp[a[j]]] + np[a[j]];
}
ll len = 0, num = -1;
for (ll j = 0; j < m; j++) {
if (!h[j])
continue;
if (test[j].length() > len) {
len = test[j].length();
num = j;
} else if (test[j].length() == len) {
if (test[j] > test[num]) {
num = j;
}
}
}
if (num == -1)
continue;
str[i] = test[num];
jud[i] = true;
}
for (ll i = 0; i < str[n].length(); i++)
cout << str[n][i];
cout << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using P = pair<ll, ll>;
using namespace std;
template <class T> void vin(vector<T> &v, int n) {
v.resize(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
}
int cost[]{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10101];
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
vin(A, M);
rep(i, N) dp[i] = "X"; // 初期化
dp[0] = "";
for (int i = 0; i < N; ++i) {
if (dp[i] == "X")
continue;
for (int j = 0; j < M; ++j) {
string tmp = dp[i];
if (tmp == "X")
tmp = "";
tmp += to_string(A[j]);
string now = dp[i + cost[A[j]]];
if (now == "X")
now = "";
if (tmp.size() > now.size()) {
dp[i + cost[A[j]]] = tmp;
} else if (tmp.size() < now.size())
continue;
else {
int cnt1[10] = {0};
int cnt2[10] = {0};
rep(k, tmp.size()) {
cnt1[tmp[k] - '0']++;
cnt2[now[k] - '0']++;
}
for (int k = tmp.size() - 1; k >= 0; --k) {
if (cnt1[k] == cnt2[k])
continue;
else if (cnt1[k] > cnt2[k]) {
dp[i + cost[A[j]]] = tmp;
break;
} else
break;
}
}
}
}
sort(dp[N].rbegin(), dp[N].rend());
cout << dp[N] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using P = pair<ll, ll>;
using namespace std;
template <class T> void vin(vector<T> &v, int n) {
v.resize(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
}
int cost[]{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10101];
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
vin(A, M);
rep(i, N) dp[i] = "X"; // 初期化
dp[0] = "";
for (int i = 0; i < N; ++i) {
if (dp[i] == "X")
continue;
for (int j = 0; j < M; ++j) {
string tmp = dp[i];
if (tmp == "X")
tmp = "";
tmp += to_string(A[j]);
string now = dp[i + cost[A[j]]];
if (now == "X")
now = "";
if (tmp.size() > now.size()) {
dp[i + cost[A[j]]] = tmp;
} else if (tmp.size() < now.size())
continue;
else {
int cnt1[10] = {0};
int cnt2[10] = {0};
rep(k, tmp.size()) {
cnt1[tmp[k] - '0']++;
cnt2[now[k] - '0']++;
}
for (int k = 9; k >= 0; --k) {
if (cnt1[k] == cnt2[k])
continue;
else if (cnt1[k] > cnt2[k]) {
dp[i + cost[A[j]]] = tmp;
break;
} else
break;
}
}
}
}
sort(dp[N].rbegin(), dp[N].rend());
cout << dp[N] << endl;
return 0;
}
| replace | 52 | 53 | 52 | 53 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int match_num[10] = {1 << 30, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string num_string[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
string dp[1250] = {};
string calc_bigger(const string &a, const string &b) {
if (a.size() == b.size()) {
for (int i = 0; i < a.size(); i++) {
if (a[i] != b[i]) {
return (a[i] > b[i]) ? a : b;
}
}
return a;
}
return (a.size() > b.size()) ? a : b;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> cda;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
cda.push_back(a);
dp[match_num[a]] = calc_bigger(dp[match_num[a]], num_string[a]);
}
for (int i = 0; i < n; i++) {
if (dp[i].size() == 0)
continue;
for (int j = 0; j < m; j++) {
dp[i + match_num[cda[j]]] =
calc_bigger(dp[i + match_num[cda[j]]], num_string[cda[j]] + dp[i]);
}
}
/*
for(int i = 0; i <= n; i++) {
cout << dp[i] << endl;
}
*/
cout << dp[n] << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int match_num[10] = {1 << 30, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string num_string[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
string dp[12500] = {};
string calc_bigger(const string &a, const string &b) {
if (a.size() == b.size()) {
for (int i = 0; i < a.size(); i++) {
if (a[i] != b[i]) {
return (a[i] > b[i]) ? a : b;
}
}
return a;
}
return (a.size() > b.size()) ? a : b;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> cda;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
cda.push_back(a);
dp[match_num[a]] = calc_bigger(dp[match_num[a]], num_string[a]);
}
for (int i = 0; i < n; i++) {
if (dp[i].size() == 0)
continue;
for (int j = 0; j < m; j++) {
dp[i + match_num[cda[j]]] =
calc_bigger(dp[i + match_num[cda[j]]], num_string[cda[j]] + dp[i]);
}
}
/*
for(int i = 0; i <= n; i++) {
cout << dp[i] << endl;
}
*/
cout << dp[n] << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif
const int MOD = 1000000007, INF = 1111111111;
using namespace std;
typedef long long lint;
inline string chmax(string &lhs, string rhs) {
sort(rhs.begin(), rhs.end(), greater<char>());
if (lhs.size() > rhs.size())
return lhs;
else if (lhs.size() < rhs.size())
return rhs;
else
return lhs > rhs ? lhs : rhs;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> m_num({2, 5, 5, 4, 5, 6, 3, 7, 6});
vector<int> A(M);
for (int i = 0; i < M; i++)
cin >> A[i];
vector<string> dp(N + 1);
int idx;
for (int m = 0; m <= N; m++) {
for (int i = 0; i < M; i++) {
idx = m - m_num[A[i] - 1];
if (idx >= 0 && (dp[idx] != "" | idx == 0)) {
dp[m] = chmax(dp[m], dp[idx] + to_string(A[i]));
}
}
}
cout << dp[N] << "\n";
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <vector>
#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif
const int MOD = 1000000007, INF = 1111111111;
using namespace std;
typedef long long lint;
inline string chmax(string &lhs, string rhs) {
// sort(rhs.begin(), rhs.end(), greater<char>());
if (lhs.size() > rhs.size())
return lhs;
else if (lhs.size() < rhs.size())
return rhs;
else
return lhs > rhs ? lhs : rhs;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<int> m_num({2, 5, 5, 4, 5, 6, 3, 7, 6});
vector<int> A(M);
for (int i = 0; i < M; i++)
cin >> A[i];
vector<string> dp(N + 1);
int idx;
for (int m = 0; m <= N; m++) {
for (int i = 0; i < M; i++) {
idx = m - m_num[A[i] - 1];
if (idx >= 0 && (dp[idx] != "" | idx == 0)) {
dp[m] = chmax(dp[m], dp[idx] + to_string(A[i]));
}
}
}
cout << dp[N] << "\n";
return 0;
} | replace | 22 | 23 | 22 | 23 | TLE | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
string max_string(string a, string b) {
if (a.length() > b.length()) {
return a;
} else if (a.length() < b.length()) {
return b;
} else {
for (int i = 0; i < a.length(); i++) {
if (a[i] > b[i])
return a;
else if (a[i] < b[i])
return b;
}
// 一致
return a;
}
}
int mm[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int a[15];
string dp[10005];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; i++) {
if (dp[mm[a[i]]] == "")
dp[mm[a[i]]] = to_string(a[i]);
else
dp[mm[a[i]]] = max_string(dp[mm[a[i]]], to_string(a[i]));
}
// for (int i = 0; i< 10; i++) {
// printf("%d %s\n", i, dp[i].c_str());
// }
for (int i = 1; i <= n; i++) {
if (dp[i] == "")
continue;
else {
for (int j = 0; j < m; j++) {
if (dp[i + mm[a[j]]] == "")
dp[i + mm[a[j]]] = to_string(a[j]) + dp[i];
else
dp[i + mm[a[j]]] =
max_string(dp[i + mm[a[j]]], to_string(a[j]) + dp[i]);
}
}
}
printf("%s\n", dp[n].c_str());
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
string max_string(string a, string b) {
if (a.length() > b.length()) {
return a;
} else if (a.length() < b.length()) {
return b;
} else {
for (int i = 0; i < a.length(); i++) {
if (a[i] > b[i])
return a;
else if (a[i] < b[i])
return b;
}
// 一致
return a;
}
}
int mm[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int a[15];
string dp[11000];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; i++) {
if (dp[mm[a[i]]] == "")
dp[mm[a[i]]] = to_string(a[i]);
else
dp[mm[a[i]]] = max_string(dp[mm[a[i]]], to_string(a[i]));
}
// for (int i = 0; i< 10; i++) {
// printf("%d %s\n", i, dp[i].c_str());
// }
for (int i = 1; i <= n; i++) {
if (dp[i] == "")
continue;
else {
for (int j = 0; j < m; j++) {
if (dp[i + mm[a[j]]] == "")
dp[i + mm[a[j]]] = to_string(a[j]) + dp[i];
else
dp[i + mm[a[j]]] =
max_string(dp[i + mm[a[j]]], to_string(a[j]) + dp[i]);
}
}
}
printf("%s\n", dp[n].c_str());
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdlib> //絶対値利用のため
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i, n) for (int i = 0; i < n; i++)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)
// const int INF = INT_MAX / 2;
int main() {
int n, m;
cin >> n >> m;
int a[10];
int h[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m, greater<int>());
int dp[10100];
fill(dp, dp + 10100, -1);
dp[0] = 0;
for (int i = 0; i <= n; i++) {
if (dp[i] == -1)
continue;
for (int j = 0; j < m; j++) {
dp[i + h[a[j]]] = max(dp[i + h[a[j]]], dp[i] + 1);
}
}
int k = n;
while (k) {
for (int i = 0; i < m; i++)
if (dp[k - h[a[i]]] == (dp[k] - 1)) {
cout << a[i];
k = k - h[a[i]];
break;
}
}
cout << endl;
return 0;
} | #include <algorithm>
#include <cstdlib> //絶対値利用のため
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define fr(i, n) for (int i = 0; i < n; i++)
#define ifr(i, n) for (int i = n - 1; i >= 0; i--)
// const int INF = INT_MAX / 2;
int main() {
int n, m;
cin >> n >> m;
int a[10];
int h[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + m, greater<int>());
int dp[10100];
fill(dp, dp + 10100, -1);
dp[0] = 0;
for (int i = 0; i <= n; i++) {
if (dp[i] == -1)
continue;
for (int j = 0; j < m; j++) {
dp[i + h[a[j]]] = max(dp[i + h[a[j]]], dp[i] + 1);
}
}
int k = n;
while (k) {
for (int i = 0; i < m; i++)
if (k - h[a[i]] >= 0 && dp[k - h[a[i]]] == (dp[k] - 1)) {
cout << a[i];
k = k - h[a[i]];
break;
}
}
cout << endl;
return 0;
} | replace | 34 | 35 | 34 | 35 | TLE | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <algorithm>
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d", &a)
#define I2(a, b) scanf("%d%d", &a, &b)
#define I3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define L(a) scanf("%lld", &a)
#define L2(a, b) scanf("%lld%lld", &a, &b)
#define L3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define PI(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PT(t) printf("Case %d: ", t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a, 0, sizeof a)
#define SETR(a) memset(a, -1, sizeof a)
#define SZ(a) ((int)a.size()) - 1
#define f(i, a, b) for (int i = a; i <= b; i++)
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define frr(i, a, b) for (int i = a; i >= b; i--)
#define frv(i, a) for (int i = 0; i < a.size(); i++)
#define pi 2.0 * acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
ll ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) { return BM(a, M - 2, M); }
template <class T> inline T PW(T p, T e) {
ll ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p);
p = (p * p);
}
return (T)ret;
}
template <class T> bool ISLEFT(T a, T b, T c) {
if (((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)
return 1; // Uporer dike //A,b,c, x okkher ordera sorted
else
return 0;
}
typedef pair<int, int> P;
//////////////////////////
/////////////////////////
int main() {
int mt[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
I2(n, m);
pair<int, int> ar[m + 2];
for (int i = 1; i <= m; i++) {
I(ar[i].x);
ar[i].y = mt[ar[i].x];
}
int DP[n + 2];
SETR(DP);
DP[0] = 0;
sort(ar + 1, ar + m + 1);
int ans = 0;
int in = 0;
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= m; i++) {
if (j - ar[i].y >= 0 && DP[j - ar[i].y] != -1) {
DP[j] = max(DP[j], DP[j - ar[i].y] + 1);
ans = max(ans, DP[j]);
}
}
}
int cnt = 0;
for (int j = n; j > 0;) {
for (int k = m; k >= 1; k--) {
if ((j - ar[k].y) >= 0 && DP[j - ar[k].y] == ans - 1) {
ans--;
j = j - ar[k].y;
cout << ar[k].x;
cnt++;
break;
}
}
}
cout << endl;
return 0;
} | #include <algorithm>
#include <algorithm>
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d", &a)
#define I2(a, b) scanf("%d%d", &a, &b)
#define I3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define L(a) scanf("%lld", &a)
#define L2(a, b) scanf("%lld%lld", &a, &b)
#define L3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define PI(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PT(t) printf("Case %d: ", t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a, 0, sizeof a)
#define SETR(a) memset(a, -1, sizeof a)
#define SZ(a) ((int)a.size()) - 1
#define f(i, a, b) for (int i = a; i <= b; i++)
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define frr(i, a, b) for (int i = a; i >= b; i--)
#define frv(i, a) for (int i = 0; i < a.size(); i++)
#define pi 2.0 * acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M) {
ll ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M) { return BM(a, M - 2, M); }
template <class T> inline T PW(T p, T e) {
ll ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p);
p = (p * p);
}
return (T)ret;
}
template <class T> bool ISLEFT(T a, T b, T c) {
if (((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)
return 1; // Uporer dike //A,b,c, x okkher ordera sorted
else
return 0;
}
typedef pair<int, int> P;
//////////////////////////
/////////////////////////
int main() {
int mt[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int n, m;
I2(n, m);
pair<int, int> ar[m + 2];
for (int i = 1; i <= m; i++) {
I(ar[i].x);
ar[i].y = mt[ar[i].x];
}
int DP[n + 2];
SETR(DP);
DP[0] = 0;
sort(ar + 1, ar + m + 1);
int ans = 0;
int in = 0;
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= m; i++) {
if (j - ar[i].y >= 0 && DP[j - ar[i].y] != -1) {
DP[j] = max(DP[j], DP[j - ar[i].y] + 1);
ans = max(ans, DP[j]);
}
}
}
in = n;
while (in) {
for (int j = m; j >= 1; j--) {
if (in - ar[j].y >= 0 && DP[in] == DP[in - ar[j].y] + 1) {
cout << ar[j].x;
in -= ar[j].y;
break;
}
}
}
cout << endl;
return 0;
} | replace | 110 | 118 | 110 | 116 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
vector<int> maxvec(vector<int> &a, vector<int> &b) {
if (a[0] > b[0])
return a;
if (a[0] < b[0])
return b;
for (int i = 9; i >= 1; i--) {
if (a[i] > b[i])
return a;
if (a[i] < b[i])
return b;
}
return a;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> Acheck(N, 0);
for (int i = 0; i < M; i++) {
int Ai;
cin >> Ai;
Acheck[Ai] = 1;
}
for (int i = 0; i < 10; i++)
A[i] *= Acheck[i];
vector<vector<int>> dp(N + 1, vector<int>(10, -1));
dp[0] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for (int i = 0; i <= N; i++) {
vector<int> vec = {INT_MIN};
for (int j = 0; j < 10; j++) {
if (A[j] != 0 and i - A[j] >= 0) {
if (dp[i - A[j]][0] != -1) {
vector<int> tmp = dp[i - A[j]];
tmp[0]++;
tmp[j]++;
vec = maxvec(vec, tmp);
}
}
}
dp[i] = maxvec(dp[i], vec);
}
for (int i = 9; i >= 1; i--) {
for (int j = 0; j < dp[N][i]; j++) {
cout << i;
}
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> maxvec(vector<int> &a, vector<int> &b) {
if (a[0] > b[0])
return a;
if (a[0] < b[0])
return b;
for (int i = 9; i >= 1; i--) {
if (a[i] > b[i])
return a;
if (a[i] < b[i])
return b;
}
return a;
}
int main() {
int N, M;
cin >> N >> M;
vector<int> A = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> Acheck(10, 0);
for (int i = 0; i < M; i++) {
int Ai;
cin >> Ai;
Acheck[Ai] = 1;
}
for (int i = 0; i < 10; i++)
A[i] *= Acheck[i];
vector<vector<int>> dp(N + 1, vector<int>(10, -1));
dp[0] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
for (int i = 0; i <= N; i++) {
vector<int> vec = {INT_MIN};
for (int j = 0; j < 10; j++) {
if (A[j] != 0 and i - A[j] >= 0) {
if (dp[i - A[j]][0] != -1) {
vector<int> tmp = dp[i - A[j]];
tmp[0]++;
tmp[j]++;
vec = maxvec(vec, tmp);
}
}
}
dp[i] = maxvec(dp[i], vec);
}
for (int i = 9; i >= 1; i--) {
for (int j = 0; j < dp[N][i]; j++) {
cout << i;
}
}
cout << endl;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
int n, m, c[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10001], p[10001], a[10], inf = 100000;
int f(int n) {
if (n < 0)
return -inf;
if (n == 0)
return 0;
if (dp[n] != -1)
return dp[n];
int md = -inf, mi = -1;
for (int i = 0; i < m; ++i) {
int d = 1 + f(n - c[a[i]]);
if (d > md)
md = d, mi = i;
}
return p[n] = mi, dp[n] = md;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
memset(dp, -1, sizeof dp);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(a, a + m, [](int i, int j) {
// if (c[i] != c[j])
// return c[i] < c[j];
return i > j;
});
while (n) {
cout << a[p[n]];
n -= c[a[p[n]]];
}
}
| #include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
int n, m, c[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10001], p[10001], a[10], inf = 100000;
int f(int n) {
if (n < 0)
return -inf;
if (n == 0)
return 0;
if (dp[n] != -1)
return dp[n];
int md = -inf, mi = -1;
for (int i = 0; i < m; ++i) {
int d = 1 + f(n - c[a[i]]);
if (d > md)
md = d, mi = i;
}
return p[n] = mi, dp[n] = md;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
memset(dp, -1, sizeof dp);
for (int i = 0; i < m; ++i)
cin >> a[i];
sort(a, a + m, [](int i, int j) { return i > j; });
f(n);
while (n) {
cout << a[p[n]];
n -= c[a[p[n]]];
}
}
| replace | 34 | 39 | 34 | 36 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pair;
int main() {
int N, M;
cin >> N >> M;
int tmp;
int bou[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A;
for (int i = 0; i < M; i++) {
cin >> tmp;
A.push_back(tmp);
}
sort(A.begin(), A.end());
int dp[1100];
for (int i = 0; i < 1100; i++) {
dp[i] = -10000;
}
dp[10] = 0;
int maxK;
for (int i = 11; i <= N + 10; i++) {
maxK = -10000;
for (int j = 0; j < A.size(); j++) {
maxK = max(maxK, dp[i - bou[A.at(j)]] + 1);
}
dp[i] = maxK;
}
// cout << dp[N+10] << endl;
int N2 = N;
for (int i = 0; i < dp[N2 + 10]; i++) {
for (int j = A.size() - 1; j >= 0; j--) {
if (dp[N + 10 - bou[A.at(j)]] == dp[N + 10] - 1) {
cout << A.at(j);
N -= bou[A.at(j)];
break;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pair;
int main() {
int N, M;
cin >> N >> M;
int tmp;
int bou[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> A;
for (int i = 0; i < M; i++) {
cin >> tmp;
A.push_back(tmp);
}
sort(A.begin(), A.end());
int dp[11000];
for (int i = 0; i < 11000; i++) {
dp[i] = -10000;
}
dp[10] = 0;
int maxK;
for (int i = 11; i <= N + 10; i++) {
maxK = -10000;
for (int j = 0; j < A.size(); j++) {
maxK = max(maxK, dp[i - bou[A.at(j)]] + 1);
}
dp[i] = maxK;
}
// cout << dp[N+10] << endl;
int N2 = N;
for (int i = 0; i < dp[N2 + 10]; i++) {
for (int j = A.size() - 1; j >= 0; j--) {
if (dp[N + 10 - bou[A.at(j)]] == dp[N + 10] - 1) {
cout << A.at(j);
N -= bou[A.at(j)];
break;
}
}
}
return 0;
} | replace | 15 | 17 | 15 | 17 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
bool cmp(string a, string b) {
if (a == "x")
return true;
if (b == "x")
return false;
if (a.size() < b.size())
return true;
if (a.size() > b.size())
return false;
for (int i = 0; i < a.size(); i++) {
if (a[i] != b[i])
return a[i] < b[i];
}
return false;
}
string cmax(string a, string b) {
if (cmp(a, b))
return b;
else
return a;
}
int main() {
int N, M;
int A[10];
const int req[10] = {INT32_MAX, 2, 5, 5, 4, 5, 6, 3, 7, 6};
cin >> N >> M;
for (int i = 0; i < M; i++)
cin >> A[i];
string dp[10000];
dp[0] = "";
for (int i = 1; i <= N; i++) {
dp[i] = "x";
for (int m = 0; m < M; m++) {
if (req[A[m]] <= i && dp[i - req[A[m]]] != "x") {
dp[i] = cmax(dp[i], dp[i - req[A[m]]] + to_string(A[m]));
}
}
}
cout << dp[N] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
bool cmp(string a, string b) {
if (a == "x")
return true;
if (b == "x")
return false;
if (a.size() < b.size())
return true;
if (a.size() > b.size())
return false;
for (int i = 0; i < a.size(); i++) {
if (a[i] != b[i])
return a[i] < b[i];
}
return false;
}
string cmax(string a, string b) {
if (cmp(a, b))
return b;
else
return a;
}
int main() {
int N, M;
int A[10];
const int req[10] = {INT32_MAX, 2, 5, 5, 4, 5, 6, 3, 7, 6};
cin >> N >> M;
for (int i = 0; i < M; i++)
cin >> A[i];
string dp[10001];
dp[0] = "";
for (int i = 1; i <= N; i++) {
dp[i] = "x";
for (int m = 0; m < M; m++) {
if (req[A[m]] <= i && dp[i - req[A[m]]] != "x") {
dp[i] = cmax(dp[i], dp[i - req[A[m]]] + to_string(A[m]));
}
}
}
cout << dp[N] << endl;
return 0;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define REP(i, n) for (ll i = 0; i < n; i++)
string str_max(string &a, string &b) {
if (a.size() > b.size())
return a;
if (a.size() < b.size())
return b;
REP(i, a.size()) {
if (a[i] != b[i]) {
if (a[i] > b[i])
return a;
if (a[i] < b[i])
return b;
}
}
return a;
}
int main() {
ll n, m;
cin >> n >> m;
vector<ll> a(m);
REP(i, m) {
cin >> a[i];
a[i]--;
}
vector<string> dp(n + 1);
vector<ll> need = {2, 5, 5, 4, 5, 6, 3, 7, 6};
REP(i, m) { dp[need[a[i]]] = to_string(a[i] + 1); }
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j < m; j++) {
if (i >= need[a[j]]) {
if (dp[i - need[a[j]]] == "")
continue;
string t = to_string(a[j] + 1) + dp[i - need[a[j]]];
dp[i] = str_max(dp[i], t);
}
}
// cout << dp[i] << endl;
}
cout << dp[n] << endl;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define REP(i, n) for (ll i = 0; i < n; i++)
string str_max(string &a, string &b) {
if (a.size() > b.size())
return a;
if (a.size() < b.size())
return b;
REP(i, a.size()) {
if (a[i] != b[i]) {
if (a[i] > b[i])
return a;
if (a[i] < b[i])
return b;
}
}
return a;
}
int main() {
ll n, m;
cin >> n >> m;
vector<ll> a(m);
REP(i, m) {
cin >> a[i];
a[i]--;
}
sort(a.begin(), a.end());
vector<string> dp(10005);
vector<ll> need = {2, 5, 5, 4, 5, 6, 3, 7, 6};
REP(i, m) { dp[need[a[i]]] = to_string(a[i] + 1); }
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j < m; j++) {
if (i >= need[a[j]]) {
if (dp[i - need[a[j]]] == "")
continue;
string t = to_string(a[j] + 1) + dp[i - need[a[j]]];
dp[i] = str_max(dp[i], t);
}
}
// cout << dp[i] << endl;
}
cout << dp[n] << endl;
} | replace | 52 | 53 | 52 | 55 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
ll N, M;
cin >> N >> M;
ll A[M];
ll dp[N + 1];
dp[0] = 0;
for (int i = 0; i < M; i++) {
cin >> A[i];
}
sort(A, A + M, greater<ll>());
for (int i = 1; i <= N; i++) {
ll d_max = -1;
for (int j = 0; j < M; j++) {
ll po = i - match[A[j]];
if (po < 0)
continue;
if (dp[po] < 0)
continue;
d_max = max(d_max, dp[po] + 1);
}
dp[i] = d_max;
}
for (int n = N; 0 < n;) {
for (int m = 0; m < M; m++) {
if (A[m] <= n && dp[n - match[A[m]]] == dp[n] - 1) {
n -= match[A[m]];
cout << A[m];
break;
}
}
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
ll N, M;
cin >> N >> M;
ll A[M];
ll dp[N + 1];
dp[0] = 0;
for (int i = 0; i < M; i++) {
cin >> A[i];
}
sort(A, A + M, greater<ll>());
for (int i = 1; i <= N; i++) {
ll d_max = -1;
for (int j = 0; j < M; j++) {
ll po = i - match[A[j]];
if (po < 0)
continue;
if (dp[po] < 0)
continue;
d_max = max(d_max, dp[po] + 1);
}
dp[i] = d_max;
}
for (int n = N; 0 < n;) {
for (int m = 0; m < M; m++) {
if (match[A[m]] <= n && dp[n - match[A[m]]] == dp[n] - 1) {
n -= match[A[m]];
cout << A[m];
break;
}
}
}
cout << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
int n, m;
int a[10];
int nums[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d", &a[i]);
int dp[10000] = {};
for (int i = 0; i <= n; i++)
dp[i] = -1;
dp[0] = 0;
for (int i = 0; i <= n; i++) {
if (dp[i] == -1)
continue;
for (int j = 0; j < m; j++) {
if (dp[i] + 1 > dp[i + nums[a[j]]])
dp[i + nums[a[j]]] = dp[i] + 1;
}
}
// printf("%d\n",dp[n]);
for (int i = 0; i < m; i++)
a[i] = -a[i];
sort(a, a + m);
for (int i = 0; i < m; i++)
a[i] = -a[i];
for (int i = n; i > 0;) {
for (int j = 0; j < m; j++) {
if (i - nums[a[j]] < 0)
continue;
if (dp[i] == dp[i - nums[a[j]]] + 1) {
printf("%d", a[j]);
i -= nums[a[j]];
// fflush(stdout);
break;
}
}
}
printf("\n");
} | #include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
int n, m;
int a[10];
int nums[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d", &a[i]);
int dp[10050] = {};
for (int i = 0; i <= n; i++)
dp[i] = -1;
dp[0] = 0;
for (int i = 0; i <= n; i++) {
if (dp[i] == -1)
continue;
for (int j = 0; j < m; j++) {
if (dp[i] + 1 > dp[i + nums[a[j]]])
dp[i + nums[a[j]]] = dp[i] + 1;
}
}
// printf("%d\n",dp[n]);
for (int i = 0; i < m; i++)
a[i] = -a[i];
sort(a, a + m);
for (int i = 0; i < m; i++)
a[i] = -a[i];
for (int i = n; i > 0;) {
for (int j = 0; j < m; j++) {
if (i - nums[a[j]] < 0)
continue;
if (dp[i] == dp[i - nums[a[j]]] + 1) {
printf("%d", a[j]);
i -= nums[a[j]];
// fflush(stdout);
break;
}
}
}
printf("\n");
} | replace | 14 | 15 | 14 | 15 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n; i > s; i--)
#define rep_re(i, s, n) for (ll i = n; i >= s; i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
ll match[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[100001];
string INF_S = "-";
ll A[10];
string chmax(string s, string t) {
if (s == INF_S)
return t;
else if (s.size() < t.size())
return t;
else if (s.size() == t.size()) {
return ((s < t) ? t : s);
}
}
int main() {
ll n, m;
cin >> n >> m;
rep(i, 0, m) cin >> A[i];
rep(i, 0, 100001) dp[i] = INF_S;
dp[0] = "";
repe(i, 0, n) {
if (dp[i] == INF_S)
continue;
rep(j, 0, m) {
dp[i + match[A[j] - 1]] =
chmax(dp[i + match[A[j] - 1]], dp[i] + (char)('0' + A[j]));
}
}
cout << dp[n] << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n; i > s; i--)
#define rep_re(i, s, n) for (ll i = n; i >= s; i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
ll match[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[100001];
string INF_S = "-";
ll A[10];
string chmax(string s, string t) {
if (s == INF_S)
return t;
else if (s.size() < t.size())
return t;
else if (s.size() > t.size())
return s;
else if (s.size() == t.size()) {
return ((s < t) ? t : s);
}
}
int main() {
ll n, m;
cin >> n >> m;
rep(i, 0, m) cin >> A[i];
rep(i, 0, 100001) dp[i] = INF_S;
dp[0] = "";
repe(i, 0, n) {
if (dp[i] == INF_S)
continue;
rep(j, 0, m) {
dp[i + match[A[j] - 1]] =
chmax(dp[i + match[A[j] - 1]], dp[i] + (char)('0' + A[j]));
}
}
cout << dp[n] << endl;
return 0;
} | insert | 31 | 31 | 31 | 33 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// 14719021122270100109
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;
#define f first
#define s second
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define pb eb
#define mp make_pair
#define forn(i, n) for (register int i = 0; i < n; i++)
#define Forn(i, n) for (register int i = 1; i <= n; i++)
#define foreach(it, a) \
for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define Foreach(it, a) \
for (__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
inline int in() {
char c = getchar();
int neg = 1, x = 0;
while (!isdigit(c))
(c == '-') ? neg = -1, c = getchar() : c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return neg * x;
}
inline int lcm(int a, int b) { return a * b / __gcd(a, b); }
const int mat[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int MAX = 10;
int N, M, a[MAX];
string dp[10005];
int main() {
N = in(), M = in();
forn(i, M) a[i] = in();
Forn(i, 10000) dp[i] = "&";
forn(i, N + 1) forn(j, M) {
if (dp[i] == "&")
continue;
int id = i + mat[a[j]];
string t1 = dp[id], t2 = dp[i] + (char)('0' + a[j]);
if (dp[id] == "&" || t1.size() < t2.size())
dp[id] = t2;
else if (t1.size() == t2.size())
dp[id] = max(t1, t2);
}
cout << dp[N] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// 14719021122270100109
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef unsigned long long ull;
#define f first
#define s second
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define pb eb
#define mp make_pair
#define forn(i, n) for (register int i = 0; i < n; i++)
#define Forn(i, n) for (register int i = 1; i <= n; i++)
#define foreach(it, a) \
for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define Foreach(it, a) \
for (__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
inline int in() {
char c = getchar();
int neg = 1, x = 0;
while (!isdigit(c))
(c == '-') ? neg = -1, c = getchar() : c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return neg * x;
}
inline int lcm(int a, int b) { return a * b / __gcd(a, b); }
const int mat[] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int MAX = 10;
int N, M, a[20005];
string dp[20005];
int main() {
N = in(), M = in();
forn(i, M) a[i] = in();
Forn(i, 10000) dp[i] = "&";
forn(i, N + 1) forn(j, M) {
if (dp[i] == "&")
continue;
int id = i + mat[a[j]];
string t1 = dp[id], t2 = dp[i] + (char)('0' + a[j]);
if (dp[id] == "&" || t1.size() < t2.size())
dp[id] = t2;
else if (t1.size() == t2.size())
dp[id] = max(t1, t2);
}
cout << dp[N] << endl;
return 0;
} | replace | 35 | 37 | 35 | 37 | 0 | |
p03128 | C++ | Runtime Error | #include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int MAXN = 1001;
const int weight[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
struct Stat {
short int cnt[10];
int len;
void push(int key) {
cnt[key]++;
len++;
}
Stat(int num = 0) {
memset(cnt, 0, sizeof(cnt));
len = 0;
if (num)
push(num);
}
Stat &operator=(const Stat &rhs) {
len = rhs.len;
memcpy(cnt, rhs.cnt, sizeof(cnt));
return *this;
}
bool operator<(const Stat &rhs) const {
if (len == rhs.len) {
int pleft = 9, pright = 9;
do {
while (pleft && !cnt[pleft])
pleft--;
while (pright && !rhs.cnt[pright])
pright--;
if (pleft == pright) {
if (cnt[pleft] != rhs.cnt[pright])
return cnt[pleft] < rhs.cnt[pright];
} else
return pleft < pright;
} while (pleft-- && pright--);
}
return len < rhs.len;
}
} dp[MAXN];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int num;
cin >> num;
Stat init(num);
if (dp[weight[num]] < init)
dp[weight[num]] = init;
for (int i = 1; i + weight[num] <= n; i++)
if (dp[i].len) {
Stat nextstat = dp[i];
nextstat.push(num);
if (dp[i + weight[num]] < nextstat)
dp[i + weight[num]] = nextstat;
}
}
// cout<<"Finish dp[n].len "<<dp[n].len<<endl;
string ans = "";
for (int i = 9; i > 0; i--)
while (dp[n].cnt[i]--)
ans += to_string(i);
cout << ans << endl;
return 0;
}
| #include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int MAXN = 10001;
const int weight[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
struct Stat {
short int cnt[10];
int len;
void push(int key) {
cnt[key]++;
len++;
}
Stat(int num = 0) {
memset(cnt, 0, sizeof(cnt));
len = 0;
if (num)
push(num);
}
Stat &operator=(const Stat &rhs) {
len = rhs.len;
memcpy(cnt, rhs.cnt, sizeof(cnt));
return *this;
}
bool operator<(const Stat &rhs) const {
if (len == rhs.len) {
int pleft = 9, pright = 9;
do {
while (pleft && !cnt[pleft])
pleft--;
while (pright && !rhs.cnt[pright])
pright--;
if (pleft == pright) {
if (cnt[pleft] != rhs.cnt[pright])
return cnt[pleft] < rhs.cnt[pright];
} else
return pleft < pright;
} while (pleft-- && pright--);
}
return len < rhs.len;
}
} dp[MAXN];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int num;
cin >> num;
Stat init(num);
if (dp[weight[num]] < init)
dp[weight[num]] = init;
for (int i = 1; i + weight[num] <= n; i++)
if (dp[i].len) {
Stat nextstat = dp[i];
nextstat.push(num);
if (dp[i + weight[num]] < nextstat)
dp[i + weight[num]] = nextstat;
}
}
// cout<<"Finish dp[n].len "<<dp[n].len<<endl;
string ans = "";
for (int i = 9; i > 0; i--)
while (dp[n].cnt[i]--)
ans += to_string(i);
cout << ans << endl;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p03128 | C++ | Runtime Error | #include <stdint.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
using namespace std;
using default_counter_t = int64_t;
// macro
#define let auto const &
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) \
for (default_counter_t i = 0, end_i = default_counter_t(n); i < end_i; ++i)
#define rep2(i, n) \
for (default_counter_t i = 0, end_##i = default_counter_t(n); i < end_##i; \
++i)
#define rep3(i, a, b) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; ++i)
#define rep4(i, a, b, c) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; i += default_counter_t(c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep2(i, n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep3(i, a, b) \
for (default_counter_t i = default_counter_t(b) - 1, \
begin_##i = default_counter_t(a); \
i >= begin_##i; --i)
#define rrep4(i, a, b, c) \
for (default_counter_t \
i = (default_counter_t(b) - default_counter_t(a) - 1) / \
default_counter_t(c) * default_counter_t(c) + \
default_counter_t(a), \
begin_##i = default_counter_t(a); \
i >= begin_##i; i -= default_counter_t(c))
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
// function
template <class C> constexpr C &Sort(C &a) {
std::sort(std::begin(a), std::end(a));
return a;
}
template <class C> constexpr auto &Min(C const &a) {
return *std::min_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto &Max(C const &a) {
return *std::max_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto Total(C const &c) {
return std::accumulate(std::begin(c), std::end(c), C(0));
}
template <typename T> auto CumSum(std::vector<T> const &v) {
std::vector<T> a(v.size() + 1, T(0));
for (std::size_t i = 0; i < a.size() - size_t(1); ++i)
a[i + 1] = a[i] + v[i];
return a;
}
template <typename T> constexpr bool ChMax(T &a, T const &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> constexpr bool ChMin(T &a, T const &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void In(void) { return; }
template <typename First, typename... Rest>
void In(First &first, Rest &...rest) {
cin >> first;
In(rest...);
return;
}
template <class T, typename I> void VectorIn(vector<T> &v, const I n) {
v.resize(size_t(n));
rep(i, v.size()) cin >> v[i];
}
void Out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void Out(First first, Rest... rest) {
cout << first << " ";
Out(rest...);
return;
}
constexpr auto yes(const bool c) { return c ? "yes" : "no"; }
constexpr auto Yes(const bool c) { return c ? "Yes" : "No"; }
constexpr auto YES(const bool c) { return c ? "YES" : "NO"; }
// http://koturn.hatenablog.com/entry/2018/08/01/010000
template <typename T, typename U>
inline std::vector<U> MakeNdVector(T n, U val) noexcept {
static_assert(std::is_integral<T>::value,
"[MakeNdVector] The 1st argument must be an integer");
return std::vector<U>(std::forward<T>(n), std::forward<U>(val));
}
template <typename T, typename... Args>
inline decltype(auto) MakeNdVector(T n, Args &&...args) noexcept {
static_assert(std::is_integral<T>::value,
"[MakeNdVector] The 1st argument must be an integer");
return std::vector<decltype(MakeNdVector(std::forward<Args>(args)...))>(
std::forward<T>(n), MakeNdVector(std::forward<Args>(args)...));
}
template <typename T, std::size_t N,
typename std::enable_if<(N > 0), std::nullptr_t>::type = nullptr>
struct NdvectorImpl {
using type = std::vector<typename NdvectorImpl<T, N - 1>::type>;
}; // struct ndvector_impl
template <typename T> struct NdvectorImpl<T, 1> {
using type = std::vector<T>;
}; // struct ndvector_impl
template <typename T, std::size_t N>
using NdVector = typename NdvectorImpl<T, N>::type;
#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif //__clang__
#endif // USE_STACK_TRACE_LOGGER
signed main(int argc, char *argv[]) {
(void)argc;
#ifdef USE_STACK_TRACE_LOGGER
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
#else
(void)argv;
#endif // USE_STACK_TRACE_LOGGER
int64_t N, M;
In(N, M);
vector<int64_t> A(N);
map<int64_t, int64_t> m;
rep(i, M) In(A[i]);
{
int64_t hon[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, M) {
auto it = m.find(hon[A[i]]);
if (it != m.end()) {
if (m[hon[A[i]]] < A[i]) {
m[hon[A[i]]] = A[i];
}
} else {
m[hon[A[i]]] = A[i];
}
}
}
auto dp = MakeNdVector(N + 1, int64_t(0));
auto ds = MakeNdVector(N + 1, int64_t(0));
auto from = MakeNdVector(N + 1, int64_t(0));
rep(i, N + 1) {
if (i > 0 && dp[i] == 0)
continue;
int64_t e = dp[i] + 1;
for (const auto &v : m) {
int64_t j = v.first;
if (i + j > N)
continue;
int64_t d = v.second;
if (dp[i + j] < e || (dp[i + j] == e && ds[i + j] < d)) {
dp[i + j] = e;
ds[i + j] = d;
from[i + j] = i;
}
}
}
{
int64_t i = N;
while (i > 0) {
cout << ds[i];
i = from[i];
}
cout << endl;
}
return EXIT_SUCCESS;
}
| #include <stdint.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
using namespace std;
using default_counter_t = int64_t;
// macro
#define let auto const &
#define overload4(a, b, c, d, name, ...) name
#define rep1(n) \
for (default_counter_t i = 0, end_i = default_counter_t(n); i < end_i; ++i)
#define rep2(i, n) \
for (default_counter_t i = 0, end_##i = default_counter_t(n); i < end_##i; \
++i)
#define rep3(i, a, b) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; ++i)
#define rep4(i, a, b, c) \
for (default_counter_t i = default_counter_t(a), \
end_##i = default_counter_t(b); \
i < end_##i; i += default_counter_t(c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep2(i, n) \
for (default_counter_t i = default_counter_t(n) - 1; i >= 0; --i)
#define rrep3(i, a, b) \
for (default_counter_t i = default_counter_t(b) - 1, \
begin_##i = default_counter_t(a); \
i >= begin_##i; --i)
#define rrep4(i, a, b, c) \
for (default_counter_t \
i = (default_counter_t(b) - default_counter_t(a) - 1) / \
default_counter_t(c) * default_counter_t(c) + \
default_counter_t(a), \
begin_##i = default_counter_t(a); \
i >= begin_##i; i -= default_counter_t(c))
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define ALL(f, c, ...) \
(([&](decltype((c)) cccc) { \
return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); \
})(c))
// function
template <class C> constexpr C &Sort(C &a) {
std::sort(std::begin(a), std::end(a));
return a;
}
template <class C> constexpr auto &Min(C const &a) {
return *std::min_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto &Max(C const &a) {
return *std::max_element(std::begin(a), std::end(a));
}
template <class C> constexpr auto Total(C const &c) {
return std::accumulate(std::begin(c), std::end(c), C(0));
}
template <typename T> auto CumSum(std::vector<T> const &v) {
std::vector<T> a(v.size() + 1, T(0));
for (std::size_t i = 0; i < a.size() - size_t(1); ++i)
a[i + 1] = a[i] + v[i];
return a;
}
template <typename T> constexpr bool ChMax(T &a, T const &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> constexpr bool ChMin(T &a, T const &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void In(void) { return; }
template <typename First, typename... Rest>
void In(First &first, Rest &...rest) {
cin >> first;
In(rest...);
return;
}
template <class T, typename I> void VectorIn(vector<T> &v, const I n) {
v.resize(size_t(n));
rep(i, v.size()) cin >> v[i];
}
void Out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void Out(First first, Rest... rest) {
cout << first << " ";
Out(rest...);
return;
}
constexpr auto yes(const bool c) { return c ? "yes" : "no"; }
constexpr auto Yes(const bool c) { return c ? "Yes" : "No"; }
constexpr auto YES(const bool c) { return c ? "YES" : "NO"; }
// http://koturn.hatenablog.com/entry/2018/08/01/010000
template <typename T, typename U>
inline std::vector<U> MakeNdVector(T n, U val) noexcept {
static_assert(std::is_integral<T>::value,
"[MakeNdVector] The 1st argument must be an integer");
return std::vector<U>(std::forward<T>(n), std::forward<U>(val));
}
template <typename T, typename... Args>
inline decltype(auto) MakeNdVector(T n, Args &&...args) noexcept {
static_assert(std::is_integral<T>::value,
"[MakeNdVector] The 1st argument must be an integer");
return std::vector<decltype(MakeNdVector(std::forward<Args>(args)...))>(
std::forward<T>(n), MakeNdVector(std::forward<Args>(args)...));
}
template <typename T, std::size_t N,
typename std::enable_if<(N > 0), std::nullptr_t>::type = nullptr>
struct NdvectorImpl {
using type = std::vector<typename NdvectorImpl<T, N - 1>::type>;
}; // struct ndvector_impl
template <typename T> struct NdvectorImpl<T, 1> {
using type = std::vector<T>;
}; // struct ndvector_impl
template <typename T, std::size_t N>
using NdVector = typename NdvectorImpl<T, N>::type;
#ifdef USE_STACK_TRACE_LOGGER
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <glog/logging.h>
#pragma clang diagnostic pop
#endif //__clang__
#endif // USE_STACK_TRACE_LOGGER
signed main(int argc, char *argv[]) {
(void)argc;
#ifdef USE_STACK_TRACE_LOGGER
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
#else
(void)argv;
#endif // USE_STACK_TRACE_LOGGER
int64_t N, M;
In(N, M);
vector<int64_t> A(M);
map<int64_t, int64_t> m;
rep(i, M) In(A[i]);
{
int64_t hon[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
rep(i, M) {
auto it = m.find(hon[A[i]]);
if (it != m.end()) {
if (m[hon[A[i]]] < A[i]) {
m[hon[A[i]]] = A[i];
}
} else {
m[hon[A[i]]] = A[i];
}
}
}
auto dp = MakeNdVector(N + 1, int64_t(0));
auto ds = MakeNdVector(N + 1, int64_t(0));
auto from = MakeNdVector(N + 1, int64_t(0));
rep(i, N + 1) {
if (i > 0 && dp[i] == 0)
continue;
int64_t e = dp[i] + 1;
for (const auto &v : m) {
int64_t j = v.first;
if (i + j > N)
continue;
int64_t d = v.second;
if (dp[i + j] < e || (dp[i + j] == e && ds[i + j] < d)) {
dp[i + j] = e;
ds[i + j] = d;
from[i + j] = i;
}
}
}
{
int64_t i = N;
while (i > 0) {
cout << ds[i];
i = from[i];
}
cout << endl;
}
return EXIT_SUCCESS;
}
| replace | 165 | 166 | 165 | 166 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <iostream>
#include <math.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a[i];
sort(a.begin(), a.end(), greater<int>());
int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[1009] = {0};
int dig_num[1009] = {0};
rep(i, n) {
int max_cnt = -INF;
for (auto aj : a) {
if (i + 1 - num[aj] < 0)
continue;
int tmp_cnt = dp[i + 1 - num[aj]] + 1;
if (tmp_cnt > max_cnt) {
max_cnt = tmp_cnt;
dig_num[i + 1] = aj;
}
}
dp[i + 1] = max_cnt;
}
int cur = n;
rep(i, dp[n]) {
cout << dig_num[cur];
cur -= num[dig_num[cur]];
}
cout << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <iostream>
#include <math.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, x, n) for (int i = x; i < n; ++i)
#define INF 1 << 29;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a[i];
sort(a.begin(), a.end(), greater<int>());
int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int dp[10009] = {0};
int dig_num[10009] = {0};
rep(i, n) {
int max_cnt = -INF;
for (auto aj : a) {
if (i + 1 - num[aj] < 0)
continue;
int tmp_cnt = dp[i + 1 - num[aj]] + 1;
if (tmp_cnt > max_cnt) {
max_cnt = tmp_cnt;
dig_num[i + 1] = aj;
}
}
dp[i + 1] = max_cnt;
}
int cur = n;
rep(i, dp[n]) {
cout << dig_num[cur];
cur -= num[dig_num[cur]];
}
cout << endl;
return 0;
} | replace | 22 | 24 | 22 | 24 | 0 | |
p03128 | C++ | Runtime Error | // #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000 // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T> vector<T> vect(int len, T elem) {
return vector<T>(len, elem);
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.fi << ',' << p.sec;
return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.fi >> p.sec;
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i];
if (i + 1 < vec.size())
os << ' ';
}
return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++)
is >> vec[i];
return is;
}
void fastio() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
}
#define endl "\n"
void solve() {
vector<int> a = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int N, M;
cin >> N >> M;
vector<int> A(M);
cin >> A;
sort(all(A));
reverse(all(A));
int mi = INF;
for (int ele : A) {
chmin(mi, a[ele]);
}
vector<int> dp(N + 1, -INF);
dp[0] = 0;
for (int i = 1; i <= N; i++) {
for (int j : A) {
if (i - a[j] >= 0)
chmax(dp[i], dp[i - a[j]] + 1);
}
}
int cur = N;
vector<int> ans;
for (int i = 0; i < dp[N]; i++) {
for (int j : A) {
if (cur - a[j] >= 0 && dp[cur - a[j]] == dp[cur] - 1) {
ans.push_back(j);
cur -= a[j];
break;
}
}
}
for (int i = 0; i < ans.size(); i++)
cout << ans[i];
cout << endl;
return;
}
signed main() {
fastio();
solve();
// int t; cin >> t; while(t--)solve();
// int t; cin >> t;
// for(int i=1;i<=t;i++){
// cout << "Case #" << i << ": ";
// solve();
// }
return 0;
}
| // #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000 // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;
template <class T> void chmin(T &a, const T &b) {
if (a > b)
a = b;
}
template <class T> void chmax(T &a, const T &b) {
if (a < b)
a = b;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T> vector<T> vect(int len, T elem) {
return vector<T>(len, elem);
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << p.fi << ',' << p.sec;
return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
is >> p.fi >> p.sec;
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i];
if (i + 1 < vec.size())
os << ' ';
}
return os;
}
template <class T> istream &operator>>(istream &is, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++)
is >> vec[i];
return is;
}
void fastio() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
}
#define endl "\n"
void solve() {
vector<int> a = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int N, M;
cin >> N >> M;
vector<int> A(M);
cin >> A;
sort(all(A));
reverse(all(A));
int mi = INF;
for (int ele : A) {
chmin(mi, a[ele]);
}
vector<int> dp(N + 1, -INF);
dp[0] = 0;
for (int i = 1; i <= N; i++) {
for (int j : A) {
if (i - a[j] >= 0)
chmax(dp[i], dp[i - a[j]] + 1);
}
}
int cur = N;
vector<int> ans;
for (int i = 0; i < dp[N]; i++) {
for (int j : A) {
if (cur - a[j] >= 0 && dp[cur - a[j]] == dp[cur] - 1) {
ans.push_back(j);
cur -= a[j];
break;
}
}
}
for (int i = 0; i < ans.size(); i++)
cout << ans[i];
cout << endl;
return;
}
signed main() {
fastio();
solve();
// int t; cin >> t; while(t--)solve();
// int t; cin >> t;
// for(int i=1;i<=t;i++){
// cout << "Case #" << i << ": ";
// solve();
// }
return 0;
}
| replace | 8 | 10 | 8 | 10 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
::std::int64_t gcd(::std::int64_t a, ::std::int64_t b) {
while (b != 0) {
::std::swap(a, b);
b = b % a;
}
return a;
}
int64 need[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool canuse[10] = {};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int64 N, M;
cin >> N >> M;
REP(i, M) {
int32 a;
cin >> a;
canuse[a] = 1;
}
vector<int64> dp(N, -INF);
dp[0] = 0;
REP(i, N) {
for (int32 j = 9; j >= 1; j--) {
if (!canuse[j])
continue;
if (need[j] + i > N)
continue;
chmax(dp[need[j] + i], dp[i] + 1);
}
}
int32 now = N;
string res = "";
while (now > 0) {
for (int32 i = 9; i >= 1; i--) {
if (!canuse[i])
continue;
if (now - need[i] < 0)
continue;
if (dp[now - need[i]] == dp[now] - 1) {
now -= need[i];
res += (char)('0' + i);
break;
}
}
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
::std::int64_t gcd(::std::int64_t a, ::std::int64_t b) {
while (b != 0) {
::std::swap(a, b);
b = b % a;
}
return a;
}
int64 need[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool canuse[10] = {};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int64 N, M;
cin >> N >> M;
REP(i, M) {
int32 a;
cin >> a;
canuse[a] = 1;
}
vector<int64> dp(N + 1, -INF);
dp[0] = 0;
REP(i, N) {
for (int32 j = 9; j >= 1; j--) {
if (!canuse[j])
continue;
if (need[j] + i > N)
continue;
chmax(dp[need[j] + i], dp[i] + 1);
}
}
int32 now = N;
string res = "";
while (now > 0) {
for (int32 i = 9; i >= 1; i--) {
if (!canuse[i])
continue;
if (now - need[i] < 0)
continue;
if (dp[now - need[i]] == dp[now] - 1) {
now -= need[i];
res += (char)('0' + i);
break;
}
}
}
cout << res << endl;
}
| replace | 50 | 51 | 50 | 51 | TLE | |
p03128 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
template <class T, class U> constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) ((n >> k) & 1)
// デバッグ
template <class T> void Vout(vector<T> &V) {
cout << "\nstart\n";
const int sz = V.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << V[i] << '\n';
}
cout << "end\n" << endl;
}
template <class T> void VPout(vector<T> &V) {
cout << "\nstart\n";
const int sz = V.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << V[i].first << " " << V[i].second << '\n';
}
cout << "end\n" << endl;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//__builtin_popcount(S);
// #define int ll
// vector<vector<int>> data(3, vector<int>(4));
// vector.resize(a,vector<int>(b,-1));
// vector<vector<vector<要素の型>>> 変数名(要素数1,
// vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));
int dp[11000];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> A(M);
for (int i = 0; i < M; i++)
cin >> A[i];
int need[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
int x = need[A[j]];
chmax(dp[i + x], dp[i] + 1);
}
}
int now = N;
sort(A.rbegin(), A.rend());
while (now != 0) {
for (int i = 0; i < M; i++) {
int x = need[A[i]];
if (now - x < 0 || (now - x != 0 && dp[now - x] == 0))
continue;
if (dp[now] == dp[now - x] + 1) {
cout << A[i];
now -= x;
break;
}
}
}
cout << endl;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
template <class T, class U> constexpr bool chmin(T &a, const U b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, class U> constexpr bool chmax(T &a, const U b) {
if (a >= b)
return false;
a = b;
return true;
}
#define bit(n, k) ((n >> k) & 1)
// デバッグ
template <class T> void Vout(vector<T> &V) {
cout << "\nstart\n";
const int sz = V.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << V[i] << '\n';
}
cout << "end\n" << endl;
}
template <class T> void VPout(vector<T> &V) {
cout << "\nstart\n";
const int sz = V.size();
for (int i = 0; i < sz; i++) {
cout << i << " " << V[i].first << " " << V[i].second << '\n';
}
cout << "end\n" << endl;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
constexpr int MAX = 1 << 30;
constexpr ll INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1};
//__builtin_popcount(S);
// #define int ll
// vector<vector<int>> data(3, vector<int>(4));
// vector.resize(a,vector<int>(b,-1));
// vector<vector<vector<要素の型>>> 変数名(要素数1,
// vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));
int dp[11000];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<int> A(M);
for (int i = 0; i < M; i++)
cin >> A[i];
int need[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 0; i < N; i++) {
if (i != 0 && dp[i] == 0)
continue;
for (int j = 0; j < M; j++) {
int x = need[A[j]];
chmax(dp[i + x], dp[i] + 1);
}
}
int now = N;
sort(A.rbegin(), A.rend());
while (now != 0) {
for (int i = 0; i < M; i++) {
int x = need[A[i]];
if (now - x < 0 || (now - x != 0 && dp[now - x] == 0))
continue;
if (dp[now] == dp[now - x] + 1) {
cout << A[i];
now -= x;
break;
}
}
}
cout << endl;
} | insert | 72 | 72 | 72 | 74 | TLE | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = 200000000;
const int MOD = 1e9 + 7;
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<int> num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int N, M;
cin >> N >> M;
auto A = make_vec<int>(N);
REP(i, M) { cin >> A.at(i); }
sort(ALL(A), greater<int>());
vector<int> dp(N + 4, -INF);
dp[0] = 0;
REP(i, N + 1) {
REP(j, M) {
if (i >= num[A[j]]) {
dp[i] = max(dp[i], dp[i - num[A[j]]] + 1);
}
};
}
int cur = N;
string S = "";
while (cur > 0) {
for (auto a : A) {
// cout << "cur:" << cur << " a:" << a << endl;
if (cur - num[a] >= 0) {
if (dp[cur - num[a]] == dp[cur] - 1) {
cur = cur - num[a];
S.push_back(a + '0');
break;
}
}
}
}
cout << S << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INF = 200000000;
const int MOD = 1e9 + 7;
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<int> num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int N, M;
cin >> N >> M;
auto A = make_vec<int>(M);
REP(i, M) { cin >> A.at(i); }
sort(ALL(A), greater<int>());
vector<int> dp(N + 4, -INF);
dp[0] = 0;
REP(i, N + 1) {
REP(j, M) {
if (i >= num[A[j]]) {
dp[i] = max(dp[i], dp[i - num[A[j]]] + 1);
}
};
}
int cur = N;
string S = "";
while (cur > 0) {
for (auto a : A) {
// cout << "cur:" << cur << " a:" << a << endl;
if (cur - num[a] >= 0) {
if (dp[cur - num[a]] == dp[cur] - 1) {
cur = cur - num[a];
S.push_back(a + '0');
break;
}
}
}
}
cout << S << endl;
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
signed main() {
int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int N, M;
cin >> N >> M;
vector<int> A(M);
for (int i = 0; i < M; i++) {
cin >> A[i];
}
int dp[1001] = {};
for (int i = 0; i < M; i++) {
dp[num[A[i]]] = 1;
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j < M; j++) {
if (i > num[A[j]]) {
if (dp[i] <= dp[i - num[A[j]]] + 1) {
dp[i] = dp[i - num[A[j]]] + 1;
}
}
}
if (dp[i] == 0)
dp[i] = -1000;
}
sort(A.begin(), A.end(), greater<int>());
string ans = "";
while (N > 0) {
for (int i = 0; i < M; i++) {
if (N - num[A[i]] >= 0) {
if (dp[N - num[A[i]]] != -1000 && dp[N - num[A[i]]] == dp[N] - 1) {
ans += to_string(A[i]);
N -= num[A[i]];
break;
}
}
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
signed main() {
int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int N, M;
cin >> N >> M;
vector<int> A(M);
for (int i = 0; i < M; i++) {
cin >> A[i];
}
int dp[10001] = {};
for (int i = 0; i < M; i++) {
dp[num[A[i]]] = 1;
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j < M; j++) {
if (i > num[A[j]]) {
if (dp[i] <= dp[i - num[A[j]]] + 1) {
dp[i] = dp[i - num[A[j]]] + 1;
}
}
}
if (dp[i] == 0)
dp[i] = -1000;
}
sort(A.begin(), A.end(), greater<int>());
string ans = "";
while (N > 0) {
for (int i = 0; i < M; i++) {
if (N - num[A[i]] >= 0) {
if (dp[N - num[A[i]]] != -1000 && dp[N - num[A[i]]] == dp[N] - 1) {
ans += to_string(A[i]);
N -= num[A[i]];
break;
}
}
}
}
cout << ans << endl;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define DEBUG_MAT(v) \
cerr << #v << endl; \
for (int i = 0; i < v.size(); i++) { \
for (int j = 0; j < v[i].size(); j++) { \
cerr << v[i][j] << " "; \
} \
cerr << endl; \
}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(), c.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
#define fio() \
cin.tie(0); \
ios::sync_with_stdio(false);
// #define mp make_pair
vector<vector<bool>> dp(10001, vector<bool>(5001));
int main() {
int n, m;
cin >> n >> m;
vi use = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vi a(m);
rep(i, m) { cin >> a[i]; }
sort(all(a));
dp[0][0] = 1;
rep(i, n) {
rep(j, 5001) {
if (!dp[i][j])
continue;
rep(k, m) {
int add = use[a[k]];
dp[i + add][j + 1] = true;
}
}
}
int keta;
for (keta = 5000; keta >= 0; keta--) {
if (dp[n][keta])
break;
}
string ans;
while (n > 0) {
rrep(i, m) {
int add = use[a[i]];
if (n < add)
continue;
if (dp[n - add][keta - 1]) {
ans.push_back(a[i] + '0');
keta--;
n -= add;
break;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr << #x << ": " << x << endl;
#define DEBUG_VEC(v) \
cerr << #v << ":"; \
for (int i = 0; i < v.size(); i++) \
cerr << " " << v[i]; \
cerr << endl
#define DEBUG_MAT(v) \
cerr << #v << endl; \
for (int i = 0; i < v.size(); i++) { \
for (int j = 0; j < v[i].size(); j++) { \
cerr << v[i][j] << " "; \
} \
cerr << endl; \
}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
#define pll pair<ll, ll>
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T> ostream &operator<<(ostream &os, pair<S, T> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep1(i, n) for (int i = (n); i > 0; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(), c.end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
#define fio() \
cin.tie(0); \
ios::sync_with_stdio(false);
// #define mp make_pair
vector<vector<bool>> dp(10001, vector<bool>(5001));
int main() {
int n, m;
cin >> n >> m;
vi use = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vi a(m);
rep(i, m) { cin >> a[i]; }
sort(all(a));
dp[0][0] = 1;
rep(i, n) {
rep(j, 5001) {
if (!dp[i][j])
continue;
rep(k, m) {
int add = use[a[k]];
if (i + add > n)
continue;
dp[i + add][j + 1] = true;
}
}
}
int keta;
for (keta = 5000; keta >= 0; keta--) {
if (dp[n][keta])
break;
}
string ans;
while (n > 0) {
rrep(i, m) {
int add = use[a[i]];
if (n < add)
continue;
if (dp[n - add][keta - 1]) {
ans.push_back(a[i] + '0');
keta--;
n -= add;
break;
}
}
}
cout << ans << endl;
}
| insert | 94 | 94 | 94 | 96 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int>> minHeap;
#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d", &n)
#define scnll(n) scanf("%lld", &n)
#define scn2(n, m) scanf("%d%d", &n, &m)
#define scn3(n, m, w) scanf("%d%d%d", &n, &m, &w)
#define scn2ll(n, m) scanf("%lld%lld", &n, &m)
#define atoz(v) v.begin(), v.end()
#define ratoz(v) v.rbegin(), v.rend()
#define Fill(a, v) memset(a, v, sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
inline int addmod(lli x, lli y) { return (x % mod + y % mod) % mod; }
inline int submod(lli x, lli y) { return (x % mod - y % mod + mod) % mod; }
inline int mulmod(lli x, lli y) { return (x % mod * y % mod) % mod; }
inline int nextSubMask(int i, int mask) {
return (i - 1) & mask; /// returns next submask
}
template <typename T> void we_r_done(T mssg) {
cout << mssg;
exit(0);
}
int main() {
/// freopen("output.txt","w",stdout);
// freopen("input.txt","r",stdin);
FastIO;
int n, m;
while (cin >> n >> m) {
int d[m];
for (int i = 0; i < m; i++) {
cin >> d[i];
}
sort(d, d + m);
int dp[n + 1], need[23] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
dp[0] = 0;
for (int i = 1; i <= n; i++)
dp[i] = -1;
for (int make = 1; make <= n; make++) {
for (int i = 0; i < m; i++) {
if (make < need[d[i]])
continue;
if (dp[make - need[d[i]]] == -1)
continue;
if (dp[make - need[d[i]]] + 1 >= dp[make]) {
dp[make] = dp[make - need[d[i]]] + 1;
}
}
}
assert(dp[n] != -1);
vector<int> res;
for (int made = n; made;) {
for (int i = m - 1; i >= 0; i--) {
if (dp[made - need[d[i]]] + 1 == dp[made]) {
res.pb(d[i]);
made -= need[d[i]];
break;
}
}
}
sort(res.rbegin(), res.rend());
for (int t : res)
cout << t;
cout << endl;
}
return 0;
}
/// sin and cos expect input in radians not degrees. so use , sin(degrees * pi /
/// 180) using bs = bitset<MX>; // how many distinct number can be form?
/// sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b :
/// x.a<y.a);});
| #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int>> minHeap;
#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d", &n)
#define scnll(n) scanf("%lld", &n)
#define scn2(n, m) scanf("%d%d", &n, &m)
#define scn3(n, m, w) scanf("%d%d%d", &n, &m, &w)
#define scn2ll(n, m) scanf("%lld%lld", &n, &m)
#define atoz(v) v.begin(), v.end()
#define ratoz(v) v.rbegin(), v.rend()
#define Fill(a, v) memset(a, v, sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mod 1000000007
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
inline int addmod(lli x, lli y) { return (x % mod + y % mod) % mod; }
inline int submod(lli x, lli y) { return (x % mod - y % mod + mod) % mod; }
inline int mulmod(lli x, lli y) { return (x % mod * y % mod) % mod; }
inline int nextSubMask(int i, int mask) {
return (i - 1) & mask; /// returns next submask
}
template <typename T> void we_r_done(T mssg) {
cout << mssg;
exit(0);
}
int main() {
/// freopen("output.txt","w",stdout);
// freopen("input.txt","r",stdin);
FastIO;
int n, m;
while (cin >> n >> m) {
int d[m];
for (int i = 0; i < m; i++) {
cin >> d[i];
}
sort(d, d + m);
int dp[n + 1], need[23] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
dp[0] = 0;
for (int i = 1; i <= n; i++)
dp[i] = -1;
for (int make = 1; make <= n; make++) {
for (int i = 0; i < m; i++) {
if (make < need[d[i]])
continue;
if (dp[make - need[d[i]]] == -1)
continue;
if (dp[make - need[d[i]]] + 1 >= dp[make]) {
dp[make] = dp[make - need[d[i]]] + 1;
}
}
}
assert(dp[n] != -1);
vector<int> res;
for (int made = n; made;) {
for (int i = m - 1; i >= 0; i--) {
if (made < need[d[i]])
continue;
if (dp[made - need[d[i]]] + 1 == dp[made]) {
res.pb(d[i]);
made -= need[d[i]];
break;
}
}
}
sort(res.rbegin(), res.rend());
for (int t : res)
cout << t;
cout << endl;
}
return 0;
}
/// sin and cos expect input in radians not degrees. so use , sin(degrees * pi /
/// 180) using bs = bitset<MX>; // how many distinct number can be form?
/// sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b :
/// x.a<y.a);});
| replace | 90 | 91 | 90 | 92 | TLE | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a[i];
sort(a.begin(), a.end());
vector<string> dp(n + 1);
int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int mn = 9;
rep(i, m) {
dp[cost[a[i]]] = to_string(a[i]);
mn = min(mn, cost[a[i]]);
}
for (int i = 2 * mn; i <= n; i++) {
rep(j, m) {
if (i - cost[a[j]] >= 0) {
string tmp;
if (to_string(a[j])[0] >= dp[i - cost[a[j]]][0])
tmp = to_string(a[j]) + dp[i - cost[a[j]]];
else
tmp = dp[i - cost[a[j]]] + to_string(a[j]);
if (tmp.size() >= dp[i].size())
dp[i] = tmp;
}
}
}
cout << dp[n] << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a[i];
sort(a.begin(), a.end());
vector<string> dp(n + 1);
int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int mn = 9;
rep(i, m) {
if (cost[a[i]] <= n) {
dp[cost[a[i]]] = to_string(a[i]);
mn = min(mn, cost[a[i]]);
}
}
for (int i = 2 * mn; i <= n; i++) {
rep(j, m) {
if (i - cost[a[j]] >= 0) {
string tmp;
if (to_string(a[j])[0] >= dp[i - cost[a[j]]][0])
tmp = to_string(a[j]) + dp[i - cost[a[j]]];
else
tmp = dp[i - cost[a[j]]] + to_string(a[j]);
if (tmp.size() >= dp[i].size())
dp[i] = tmp;
}
}
}
cout << dp[n] << endl;
return 0;
} | replace | 28 | 30 | 28 | 32 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <unordered_map>
#pragma GCC optimize("Ofast")
using namespace std;
#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file \
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) \
cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) \
cerr << #v << ": [ "; \
for (int __ = 0; __ < v.size(); __++) \
cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); \
cerr << ']' << endl
#define debugVP(v) \
cerr << #v << ": [ "; \
for (int ___ = 0; ___ < v.size(); ___++) \
cerr << '{' << v[___].first << ", " << v[___].second << '}' \
<< ((___ != v.size() - 1) ? ", " : ends); \
cerr << ']' << endl
#define debugA(a, n) \
cerr << #a << ": [ "; \
for (int ____ = 0; ____ < n; ____++) \
cerr << a[____] << ((____ != n - 1) ? ", " : ends); \
cerr << ']' << endl
#define print(args...) fprintf(st derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = INF + 7 /* INF - 1755647 */;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) {
return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1));
}
/////////////////////////////////////////////////////////////////////
const int N = 1e4 + 20, M = 2e1 + 2;
vi v;
int a[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool dp[N][N];
int32_t main() {
sync;
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
v.push_back(x);
}
sort(all(v));
reverse(all(v));
dp[0][0] = true;
for (int i = 1; i <= n / 2; i++)
for (int j = 1; j <= n; j++)
for (int k : v)
if (j >= a[k])
dp[i][j] |= dp[i - 1][j - a[k]];
int mx = 0;
for (int i = 1; i <= n / 2; i++)
if (dp[i][n])
mx = i;
vi ans;
for (int i = 1; i <= mx; i++)
for (int k : v)
if (a[k] <= n && dp[mx - i][n - a[k]]) {
n -= a[k];
ans.push_back(k);
break;
}
for (int k : ans)
cout << k;
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast")
using namespace std;
#define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file \
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) \
cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) \
cerr << #v << ": [ "; \
for (int __ = 0; __ < v.size(); __++) \
cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); \
cerr << ']' << endl
#define debugVP(v) \
cerr << #v << ": [ "; \
for (int ___ = 0; ___ < v.size(); ___++) \
cerr << '{' << v[___].first << ", " << v[___].second << '}' \
<< ((___ != v.size() - 1) ? ", " : ends); \
cerr << ']' << endl
#define debugA(a, n) \
cerr << #a << ": [ "; \
for (int ____ = 0; ____ < n; ____++) \
cerr << a[____] << ((____ != n - 1) ? ", " : ends); \
cerr << ']' << endl
#define print(args...) fprintf(st derr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<pii, int> mpii;
typedef set<int> sti;
const int INF = 1e9, MOD = INF + 7 /* INF - 1755647 */;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
int power(int a, int b) {
return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1));
}
/////////////////////////////////////////////////////////////////////
const int N = 1e4 + 20, M = 2e1 + 2;
vi v;
int a[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool dp[N][N];
int32_t main() {
sync;
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
v.push_back(x);
}
sort(all(v));
reverse(all(v));
dp[0][0] = true;
for (int i = 1; i <= n / 2; i++)
for (int j = 1; j <= n; j++)
for (int k : v)
if (j >= a[k])
dp[i][j] |= dp[i - 1][j - a[k]];
int mx = 0;
for (int i = 1; i <= n / 2; i++)
if (dp[i][n])
mx = i;
vi ans;
for (int i = 1; i <= mx; i++)
for (int k : v)
if (a[k] <= n && dp[mx - i][n - a[k]]) {
n -= a[k];
ans.push_back(k);
break;
}
for (int k : ans)
cout << k;
cout << endl;
return 0;
}
| replace | 1 | 3 | 1 | 2 | TLE | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
int dp[1010];
fill(dp, dp + n, -1);
dp[0] = 0;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
int need[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (i - need[a[j]] >= 0) {
dp[i] = max(dp[i], dp[i - need[a[j]]] + 1);
}
}
}
sort(a.begin(), a.end(), greater<int>());
string ans;
for (int j = n; dp[j];) {
for (int i = 0; i < m; i++) {
if (j - need[a[i]] >= 0) {
if (dp[j] == dp[j - need[a[i]]] + 1) {
j -= need[a[i]];
ans += a[i] + '0';
break;
}
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
int dp[10010];
fill(dp, dp + n, -1);
dp[0] = 0;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
int need[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (i - need[a[j]] >= 0) {
dp[i] = max(dp[i], dp[i - need[a[j]]] + 1);
}
}
}
sort(a.begin(), a.end(), greater<int>());
string ans;
for (int j = n; dp[j];) {
for (int i = 0; i < m; i++) {
if (j - need[a[i]] >= 0) {
if (dp[j] == dp[j - need[a[i]]] + 1) {
j -= need[a[i]];
ans += a[i] + '0';
break;
}
}
}
}
cout << ans << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p03128 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
signed main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (auto &ai : a)
cin >> ai;
vector<int> need = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
auto add = [](string s, int a) {
s += to_string(a);
sort(s.begin(), s.end(), greater<>());
return s;
};
auto cmp = [](string &s, string &t) {
// operator <
int n = s.size();
int m = t.size();
if (n < m)
return true;
if (n > m)
return false;
assert(n == m);
for (int i = 0; i < n; ++i) {
if (s[i] < t[i]) {
return true;
}
if (s[i] > t[i]) {
return false;
}
}
return false;
};
auto chmax = [&cmp](string &s, string t) {
if (cmp(s, t))
s = t;
};
vector<string> dp(n + 1);
for (int i = 0; i <= n; ++i) {
for (auto const &ai : a) {
if (i - need[ai] < 0)
continue;
if (dp[i - need[ai]] == "" && i - need[ai] != 0)
continue;
chmax(dp[i], add(dp[i - need[ai]], ai));
}
}
cout << (dp[n]) << endl;
} | #include <bits/stdc++.h>
using namespace std;
signed main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
for (auto &ai : a)
cin >> ai;
vector<int> need = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
auto add = [](string s, int a) {
s += to_string(a);
int n = s.size();
for (int i = n - 1; i - 1 >= 0; --i) {
if (s[i - 1] > s[i])
break;
swap(s[i - 1], s[i]);
}
return s;
};
auto cmp = [](string &s, string &t) {
// operator <
int n = s.size();
int m = t.size();
if (n < m)
return true;
if (n > m)
return false;
assert(n == m);
for (int i = 0; i < n; ++i) {
if (s[i] < t[i]) {
return true;
}
if (s[i] > t[i]) {
return false;
}
}
return false;
};
auto chmax = [&cmp](string &s, string t) {
if (cmp(s, t))
s = t;
};
vector<string> dp(n + 1);
for (int i = 0; i <= n; ++i) {
for (auto const &ai : a) {
if (i - need[ai] < 0)
continue;
if (dp[i - need[ai]] == "" && i - need[ai] != 0)
continue;
chmax(dp[i], add(dp[i - need[ai]], ai));
}
}
cout << (dp[n]) << endl;
} | replace | 15 | 16 | 15 | 21 | TLE | |
p03128 | C++ | Runtime Error | // includes
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using namespace std;
// types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
// solve
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int ma[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string maxs(string a, string b) {
if (a == "a")
return b;
if (b == "a")
return a;
if (a.size() != b.size()) {
if (a.size() > b.size())
return a;
else
return b;
}
for (int i = 0; i < sz(a); i++) {
if (a[i] != b[i]) {
if (a[i] < b[i])
return b;
else
return a;
}
}
return a;
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<string> dp;
for (int i = 0; i <= 1001; i++)
dp.pb("a");
vector<int> a(m);
rep(i, m) cin >> a[i];
rep(i, m) { dp[ma[a[i] - 1]] = maxs(dp[ma[a[i] - 1]], to_string(a[i])); }
dp[0] = "";
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (i - ma[a[j] - 1] >= 0 && dp[i - ma[a[j] - 1]] != "a") {
dp[i] = maxs(dp[i], dp[i - ma[a[j] - 1]] + to_string(a[j]));
}
}
}
cout << dp[n] << endl;
return 0;
}
| // includes
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using namespace std;
// types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;
// solve
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int ma[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string maxs(string a, string b) {
if (a == "a")
return b;
if (b == "a")
return a;
if (a.size() != b.size()) {
if (a.size() > b.size())
return a;
else
return b;
}
for (int i = 0; i < sz(a); i++) {
if (a[i] != b[i]) {
if (a[i] < b[i])
return b;
else
return a;
}
}
return a;
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<string> dp;
for (int i = 0; i <= 10001; i++)
dp.pb("a");
vector<int> a(m);
rep(i, m) cin >> a[i];
rep(i, m) { dp[ma[a[i] - 1]] = maxs(dp[ma[a[i] - 1]], to_string(a[i])); }
dp[0] = "";
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
if (i - ma[a[j] - 1] >= 0 && dp[i - ma[a[j] - 1]] != "a") {
dp[i] = maxs(dp[i], dp[i - ma[a[j] - 1]] + to_string(a[j]));
}
}
}
cout << dp[n] << endl;
return 0;
}
| replace | 91 | 92 | 91 | 92 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool dp[10005][5005];
ll use[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
for (int i = 0; i < 10005; i++) {
for (int j = 0; j < 5005; j++)
dp[i][j] = false;
}
dp[0][0] = true;
ll n, m;
cin >> n >> m;
vector<ll> v;
for (int i = 0; i < m; i++) {
ll a;
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end(), greater<ll>());
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5000; j++) {
if (dp[i][j]) {
for (int k = 0; k < m; k++) {
dp[i + use[v[k]]][j + 1] = true;
}
}
}
}
vector<ll> vec;
int kt;
for (kt = 5004; kt >= 0; kt--) {
if (dp[n][kt])
break;
}
vector<ll> ans;
ll ks = n;
for (; kt > 0; kt--) {
for (int i = 0; i < m; i++) {
if (ks - use[v[i]] >= 0) {
if (dp[ks - use[v[i]]][kt - 1]) {
ans.push_back(v[i]);
ks -= use[v[i]];
break;
}
}
}
}
for (int i = 0; i < ans.size(); i++)
cout << ans[i];
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool dp[10005][5005];
ll use[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
for (int i = 0; i < 10005; i++) {
for (int j = 0; j < 5005; j++)
dp[i][j] = false;
}
dp[0][0] = true;
ll n, m;
cin >> n >> m;
vector<ll> v;
for (int i = 0; i < m; i++) {
ll a;
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end(), greater<ll>());
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5000; j++) {
if (dp[i][j]) {
for (int k = 0; k < m; k++) {
if (i + use[v[k]] < 10005)
dp[i + use[v[k]]][j + 1] = true;
}
}
}
}
vector<ll> vec;
int kt;
for (kt = 5004; kt >= 0; kt--) {
if (dp[n][kt])
break;
}
vector<ll> ans;
ll ks = n;
for (; kt > 0; kt--) {
for (int i = 0; i < m; i++) {
if (ks - use[v[i]] >= 0) {
if (dp[ks - use[v[i]]][kt - 1]) {
ans.push_back(v[i]);
ks -= use[v[i]];
break;
}
}
}
}
for (int i = 0; i < ans.size(); i++)
cout << ans[i];
cout << endl;
}
| replace | 24 | 25 | 24 | 26 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
/** FOR VECTOR DEBUG */
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
if (!v.empty()) {
out << '[';
copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
out << "\b\b]";
}
return out;
}
/* template end */
const int limit = 11729;
string dp[limit];
int match[10] = {-INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.precision(16);
int n, m;
cin >> n >> m;
vector<pair<int, string>> al(m);
REP(i, m) {
int t;
cin >> t;
al[i] = mp(t, to_string(t));
}
sort(al.begin(), al.end(), [](auto a, auto b) { return b.first > a.first; });
REP(i, limit) { dp[i] = "-1"; }
dp[0] = "";
REP(i, limit) {
if (dp[i].find("-") != string::npos) {
continue;
}
for (auto j : al) {
int idx = i + match[j.first];
dp[idx] = [&](string s, string t) {
if (s.find("-") != string::npos || t.size() > s.size() || t > s) {
return t;
}
return s;
}(dp[idx], dp[i] + j.second);
}
}
cout << dp[n] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
/** FOR VECTOR DEBUG */
template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
if (!v.empty()) {
out << '[';
copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
out << "\b\b]";
}
return out;
}
/* template end */
const int limit = 11729;
string dp[limit];
int match[10] = {-INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.precision(16);
int n, m;
cin >> n >> m;
vector<pair<int, string>> al(m);
REP(i, m) {
int t;
cin >> t;
al[i] = mp(t, to_string(t));
}
sort(al.begin(), al.end(), [](auto a, auto b) { return b.first > a.first; });
REP(i, limit) { dp[i] = "-1"; }
dp[0] = "";
REP(i, n) {
if (dp[i].find("-") != string::npos) {
continue;
}
for (auto j : al) {
int idx = i + match[j.first];
dp[idx] = [&](string s, string t) {
if (s.find("-") != string::npos || t.size() > s.size() || t > s) {
return t;
}
return s;
}(dp[idx], dp[i] + j.second);
}
}
cout << dp[n] << endl;
return 0;
} | replace | 58 | 59 | 58 | 59 | 0 | |
p03128 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
string MAX(string x, string y) {
if (x.size() > y.size())
return x;
if (x.size() < y.size())
return y;
return max(x, y);
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a.at(i);
vector<int> nums = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<string> dp(2000, ""); // dp[i]->i本のマッチを使って作れる最大の整数
rep(i, n) {
if (i != 0 && dp.at(i) == "")
continue;
rep(j, m) {
int A = a.at(j);
int N = nums.at(A);
dp.at(i + N) = MAX(dp.at(i + N), dp.at(i) + to_string(A));
}
}
cout << dp.at(n) << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define repi(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
string MAX(string x, string y) {
if (x.size() > y.size())
return x;
if (x.size() < y.size())
return y;
return max(x, y);
}
int main() {
int n, m;
cin >> n >> m;
vector<int> a(m);
rep(i, m) cin >> a.at(i);
vector<int> nums = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<string> dp(20000, ""); // dp[i]->i本のhマッチを使って作れる最大の整数
rep(i, n) {
if (i != 0 && dp.at(i) == "")
continue;
rep(j, m) {
int A = a.at(j);
int N = nums.at(A);
dp.at(i + N) = MAX(dp.at(i + N), dp.at(i) + to_string(A));
}
}
cout << dp.at(n) << endl;
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p03128 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i < n + 1; i++)
int main() {
int N, M;
int A[9];
cin >> N >> M;
rep(i, M) {
cin >> A[i];
A[i]--;
}
int num[9];
num[0] = 2;
num[1] = 5;
num[2] = 5;
num[3] = 4;
num[4] = 5;
num[5] = 6;
num[6] = 3;
num[7] = 7;
num[8] = 6;
int d[8];
rep(i, 8) d[i] = -1;
rep(i, M) { d[num[A[i]]] = max(d[num[A[i]]], A[i] + 1); }
string dp[10000];
rep(i, N + 1) dp[i] = "a";
dp[0] = "";
Rep(i, N) {
rep(j, 8) {
if (d[j] < 0)
continue;
if (i - j < 0)
continue;
if (dp[i - j][0] == 'a')
continue;
if (dp[i][0] == 'a')
dp[i] = to_string(d[j]) + dp[i - j];
else {
if (dp[i].size() > 1 + dp[i - j].size())
continue;
else if (dp[i].size() == 1 + dp[i - j].size()) {
if (dp[i][0] < to_string(d[j])[0])
dp[i] = to_string(d[j]) + dp[i - j];
} else
dp[i] = to_string(d[j]) + dp[i - j];
}
}
}
cout << dp[N] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, n) for (int i = 1; i < n + 1; i++)
int main() {
int N, M;
int A[9];
cin >> N >> M;
rep(i, M) {
cin >> A[i];
A[i]--;
}
int num[9];
num[0] = 2;
num[1] = 5;
num[2] = 5;
num[3] = 4;
num[4] = 5;
num[5] = 6;
num[6] = 3;
num[7] = 7;
num[8] = 6;
int d[8];
rep(i, 8) d[i] = -1;
rep(i, M) { d[num[A[i]]] = max(d[num[A[i]]], A[i] + 1); }
string dp[10001];
rep(i, N + 1) dp[i] = "a";
dp[0] = "";
Rep(i, N) {
rep(j, 8) {
if (d[j] < 0)
continue;
if (i - j < 0)
continue;
if (dp[i - j][0] == 'a')
continue;
if (dp[i][0] == 'a')
dp[i] = to_string(d[j]) + dp[i - j];
else {
if (dp[i].size() > 1 + dp[i - j].size())
continue;
else if (dp[i].size() == 1 + dp[i - j].size()) {
if (dp[i][0] < to_string(d[j])[0])
dp[i] = to_string(d[j]) + dp[i - j];
} else
dp[i] = to_string(d[j]) + dp[i - j];
}
}
}
cout << dp[N] << endl;
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p03128 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> sticks{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> can(m);
for (int i = 0; i < m; i++)
cin >> can[i];
sort(can.begin(), can.end());
reverse(can.begin(), can.end());
vector<int> dp(n + 1); // dp[i]=i本でできる最大桁数
for (int i = 1; i <= n; i++) {
for (auto x : can) {
if (i - sticks[x] >= 0)
dp[i] = max(dp[i], dp[i - sticks[x]] + 1);
}
}
int remain = n;
while (remain > 0) {
for (auto x : can) {
if (dp[remain - sticks[x]] == dp[remain] - 1)
if (dp[remain - sticks[x]] > 0 || remain - sticks[x] == 0) {
remain -= sticks[x];
cout << x;
break;
}
}
}
cout << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> sticks{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<int> can(m);
for (int i = 0; i < m; i++)
cin >> can[i];
sort(can.begin(), can.end());
reverse(can.begin(), can.end());
vector<int> dp(n + 1); // dp[i]=i本でできる最大桁数
for (int i = 1; i <= n; i++)
dp[i] = -1145141919;
for (int i = 1; i <= n; i++) {
for (auto x : can) {
if (i - sticks[x] >= 0)
dp[i] = max(dp[i], dp[i - sticks[x]] + 1);
}
}
int remain = n;
while (remain > 0) {
for (auto x : can) {
if (dp[remain - sticks[x]] == dp[remain] - 1)
if (dp[remain - sticks[x]] > 0 || remain - sticks[x] == 0) {
remain -= sticks[x];
cout << x;
break;
}
}
}
cout << endl;
return 0;
} | insert | 18 | 18 | 18 | 20 | TLE | |
p03129 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int N;
int K;
cin >> N >> K;
if (N % 2 == 1)
N = (N + 1) / 2;
else
N /= 2;
if (N >= K)
printf("YES");
else
printf("NO");
while (1)
;
} | #include <iostream>
using namespace std;
int main() {
int N;
int K;
cin >> N >> K;
if (N % 2 == 1)
N = (N + 1) / 2;
else
N /= 2;
if (N >= K)
printf("YES");
else
printf("NO");
} | delete | 15 | 17 | 15 | 15 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.