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
p03127
C++
Time Limit Exceeded
#include <iostream> #include <string> #include <vector> using namespace std; int INF = (1 << 30); int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int main() { // int N; cin >> N; int A[N]; for (int i = 0; i < N; ++i) { cin >> A[i]; } int ans = INF; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { ans = min(ans, gcd(A[i], A[j])); } } // cout << ans << endl; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int INF = (1 << 30); int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; } int main() { // int N; cin >> N; int A[N]; for (int i = 0; i < N; ++i) { cin >> A[i]; } int ans = INF; for (int i = 1; i < N; ++i) { ans = min(ans, gcd(A[0], A[i])); // for (int j = i+1; j < N; ++j) { // } } // cout << ans << endl; return 0; }
replace
22
26
22
26
TLE
p03127
C++
Runtime Error
#include <iostream> using namespace std; long gcd(long a, long b) { if (a == 0) { return a; } else { return gcd(b, a % b); } } int main() { int n; cin >> n; long A[n]; int i; for (i = 0; i < n; i++) { cin >> A[i]; } long ans = A[0]; for (i = 1; i < n; i++) { ans = gcd(ans, A[i]); } cout << ans; }
#include <iostream> using namespace std; long gcd(long a, long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { int n; cin >> n; long A[n]; int i; for (i = 0; i < n; i++) { cin >> A[i]; } long ans = A[0]; for (i = 1; i < n; i++) { ans = gcd(ans, A[i]); } cout << ans; }
replace
3
4
3
4
-8
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, x) for (__typeof(x) i = 0; i < x; i++) #define mp make_pair #define pb push_back #define fi first #define se second #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() #define sci(x) \ int x; \ scanf("%d", &x); #define scii(x, y) \ int x, y; \ scanf("%d %d", &x, &y); #define sciii(x, y, z) \ int x, y, z; \ scanf("%d %d %d", &x, &y, &z); #define TC(x) \ sci(x); \ while (x--) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #define debug(x) \ { cerr << #x << " = " << x << endl; } #define repi(i, x) for (__typeof(x) i = x - 1; i >= 0; i--) #define fore(itr, x) \ for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr++) #define forei(itr, x) \ for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr--) typedef long long ll; typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vector<int>> vvi; const int infi = numeric_limits<int>::max(); const double eps = 0; const int ms = 0; int gcd(int a, int b) { if (b == 0) return a; if (a < b) return gcd(b, a); return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); // endl->"\n" cin.tie(0); int N; cin >> N; vi A(N); rep(i, N) cin >> A[i]; int ans = infi; rep(i, N) { for (int j = i + 1; j < N; j++) { ans = min(ans, gcd(A[i], A[j])); } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, x) for (__typeof(x) i = 0; i < x; i++) #define mp make_pair #define pb push_back #define fi first #define se second #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() #define sci(x) \ int x; \ scanf("%d", &x); #define scii(x, y) \ int x, y; \ scanf("%d %d", &x, &y); #define sciii(x, y, z) \ int x, y, z; \ scanf("%d %d %d", &x, &y, &z); #define TC(x) \ sci(x); \ while (x--) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #define debug(x) \ { cerr << #x << " = " << x << endl; } #define repi(i, x) for (__typeof(x) i = x - 1; i >= 0; i--) #define fore(itr, x) \ for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr++) #define forei(itr, x) \ for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr--) typedef long long ll; typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vector<int>> vvi; const int infi = numeric_limits<int>::max(); const double eps = 0; const int ms = 0; int gcd(int a, int b) { if (b == 0) return a; if (a < b) return gcd(b, a); return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); // endl->"\n" cin.tie(0); int N; cin >> N; vi A(N); rep(i, N) cin >> A[i]; int ans = gcd(A[0], A[1]); for (int i = 3; i < N; i++) { ans = gcd(A[i], ans); } cout << ans << "\n"; return 0; }
replace
60
65
60
65
TLE
p03127
C++
Time Limit Exceeded
#include <iostream> #include <queue> using namespace std; int main() { vector<int> dtom{-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int n, m; cin >> n; long long int min = 10000000000; priority_queue<int> pq; int temp; for (int i = 0; i < n; i++) { cin >> temp; pq.push(temp); } while (pq.size() != 1) { int n1 = pq.top(); pq.pop(); int n2 = pq.top(); pq.pop(); n1 = n1 - n2; if (n1 != 0) pq.push(n1); pq.push(n2); } cout << pq.top(); return 0; }
#include <iostream> #include <queue> using namespace std; int main() { vector<int> dtom{-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int n, m; cin >> n; long long int min = 10000000000; priority_queue<int> pq; int temp; for (int i = 0; i < n; i++) { cin >> temp; pq.push(temp); } while (pq.size() != 1) { int n1 = pq.top(); pq.pop(); int n2 = pq.top(); pq.pop(); n1 = n1 % n2; if (n1 != 0) pq.push(n1); pq.push(n2); } cout << pq.top(); return 0; }
replace
21
22
21
22
TLE
p03127
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <vector> #define ll long long using namespace std; ll gcd(ll a, ll b) { if (a < b) { ll temp = a; a = b; b = temp; } ll r = a % b; while (r > 0) { a = b; b = r; r = a % b; } return 0; } int main() { ll n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { ll g = gcd(a[i], a[i + 1]); a[i + 1] = g; } cout << a.back() << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <vector> #define ll long long using namespace std; ll gcd(ll a, ll b) { if (a < b) { ll temp = a; a = b; b = temp; } ll r = a % b; while (r > 0) { a = b; b = r; r = a % b; } return b; } int main() { ll n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { ll g = gcd(a[i], a[i + 1]); a[i + 1] = g; } cout << a.back() << endl; return 0; }
replace
19
20
19
20
-8
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (auto &a : A) { cin >> a; } sort(A.begin(), A.end()); int s = 0; while (s < N - 1) { if (A[s] == 1) { break; } for (int ii = s + 1; ii < N; ii++) { A[ii] -= A[s]; } sort(A.begin(), A.end()); while (A[s] == 0) { s++; } } cout << A[s] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (auto &a : A) { cin >> a; } sort(A.begin(), A.end()); int s = 0; while (s < N - 1) { if (A[s] == 1) { break; } for (int ii = s + 1; ii < N; ii++) { A[ii] %= A[s]; } sort(A.begin(), A.end()); while (A[s] == 0) { s++; } } cout << A[s] << endl; return 0; }
replace
18
19
18
19
TLE
p03127
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> #define ll long long using namespace std; int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<ll>::iterator min_it; int minIndex; ll min; while (a.size() > 1) { min_it = min_element(a.begin(), a.end()); minIndex = distance(a.begin(), min_it); min = a[minIndex]; for (int i = 0; i < a.size(); i++) { if (i != minIndex) { a[i] = a[i] % min; } } for (int i = 0; i < a.size(); i++) { if (a[i] == 0) { a.erase(a.begin() + i); } } } cout << a[0]; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> #define ll long long using namespace std; int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<ll>::iterator min_it; int minIndex; ll min; while (a.size() > 1) { min_it = min_element(a.begin(), a.end()); minIndex = distance(a.begin(), min_it); min = a[minIndex]; for (int i = 0; i < a.size(); i++) { if (i != minIndex) { a[i] = a[i] % min; } } for (int i = 0; i < a.size(); i++) { if (a[i] == 0) { a.erase(a.begin() + i); i--; } } } cout << a[0]; return 0; }
insert
31
31
31
32
-8
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, mi = 1000000000; bool bou = true; cin >> n; vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec[i]; } sort(vec.begin(), vec.end()); int a = 1; while (1) { a *= 2; for (int i = 0; i < vec.size(); i += a) { // cout<<vec[i]<<" "<<vec[i+a/2]<<endl; if (vec[i + a / 2] <= vec.size()) { vec[i] = __gcd(vec[i + a / 2], vec[i]); } // cout<<vec[i]<<endl; } if (a * 2 > vec.size()) break; } cout << vec[0] << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, mi = 1000000000; bool bou = true; cin >> n; vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec[i]; } sort(vec.begin(), vec.end()); int a = 1; while (1) { a *= 2; for (int i = 0; i < vec.size(); i += a) { // cout<<vec[i]<<" "<<vec[i+a/2]<<endl; if (i + a / 2 <= vec.size()) { vec[i] = __gcd(vec[i + a / 2], vec[i]); } // cout<<vec[i]<<endl; } if (a * 2 > vec.size()) break; } cout << vec[0] << endl; }
replace
18
19
18
19
0
p03127
C++
Runtime Error
//---------------------------------------------------------------------- #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) //---------------------------------------------------------------------- using namespace std; using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; int main(void) { int n; vector<int> a(n); rep(i, n) cin >> a[i]; int ans = a[0]; rep(i, n) ans = __gcd(ans, a[i]); cout << ans << endl; return 0; }
//---------------------------------------------------------------------- #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) //---------------------------------------------------------------------- using namespace std; using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; int main(void) { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; int ans = a[0]; rep(i, n) ans = __gcd(ans, a[i]); cout << ans << endl; return 0; }
insert
12
12
12
13
0
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int GCD(int x, int y) { return x ? GCD(y % x, x) : y; } int main() { int n; cin >> n; vector<int> k; for (int i = 0; i < n; i++) cin >> k.at(i); int s = k[0]; for (int i = 0; i < n; i++) s = GCD(s, k.at(i)); cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int GCD(int x, int y) { return x ? GCD(y % x, x) : y; } int main() { int n; cin >> n; vector<int> k(n); for (int i = 0; i < n; i++) cin >> k.at(i); int s = k[0]; for (int i = 0; i < n; i++) s = GCD(s, k.at(i)); cout << s << endl; }
replace
6
7
6
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
p03127
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int N_MAX = 2000; long gcd(long m, long n) { while (m > 0 && n > 0) { n = n % m; if (n > 0) m = m % n; } if (n == 0) return m; else return n; } int main() { int n; cin >> n; int a[N_MAX]; for (int i = 0; i < n; i++) cin >> a[i]; long res = gcd(a[0], a[1]); for (int i = 2; i < n; i++) res = gcd(res, a[i]); cout << res << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int N_MAX = 100000; long gcd(long m, long n) { while (m > 0 && n > 0) { n = n % m; if (n > 0) m = m % n; } if (n == 0) return m; else return n; } int main() { int n; cin >> n; int a[N_MAX]; for (int i = 0; i < n; i++) cin >> a[i]; long res = gcd(a[0], a[1]); for (int i = 2; i < n; i++) res = gcd(res, a[i]); cout << res << endl; return 0; }
replace
3
4
3
4
0
p03127
C++
Runtime Error
//--------------------------------------------------------------- #include <bits/stdc++.h> using namespace std; #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdlib> #include <iostream> #include <math.h> #include <numeric> #include <sstream> #include <vector> //--------------------------------------------------------------- #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define SIZE 100005 #define INF 1000000000000000LL #define all(x) x.begin(), x.end() #define fi first #define se second using pint = pair<int, int>; using vec = vector<int>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; //--------------------------------------------------------------- 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 int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //--------------------------------------------------------------- // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; sort(all(a), greater<ll>()); rep(i, n - 1) { a[i + 1] %= a[i]; } cout << a[n - 1] << endl; }
//--------------------------------------------------------------- #include <bits/stdc++.h> using namespace std; #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdlib> #include <iostream> #include <math.h> #include <numeric> #include <sstream> #include <vector> //--------------------------------------------------------------- #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define SIZE 100005 #define INF 1000000000000000LL #define all(x) x.begin(), x.end() #define fi first #define se second using pint = pair<int, int>; using vec = vector<int>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; //--------------------------------------------------------------- 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 int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //--------------------------------------------------------------- // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; sort(all(a)); ll ans; rep(i, n - 1) { a[i + 1] = __gcd(a[i], a[i + 1]); } cout << a[n - 1] << endl; }
replace
58
60
58
62
0
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; int calc_min(int x, int y) { return x % y == 0 ? y : calc_min(y, x % y); } int main(void) { int n; int mon[100000]; int min = 1000000000; int fmin = 0; scanf("%d", &n); for (int num = 0; num < n; num++) { scanf("%d", &mon[num]); } for (int a = 0; a < n; a++) { for (int b = a + 1; b < n; b++) { fmin = calc_min(max(mon[a], mon[b]), std::min(mon[a], mon[b])); if (fmin < min) min = fmin; } if (min == 1) break; } printf("%d", min); scanf("%d"); return 0; }
#include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; int calc_min(int x, int y) { return x % y == 0 ? y : calc_min(y, x % y); } int main(void) { int n; int mon[100000]; int min = 1000000000; int fmin = 0; scanf("%d", &n); for (int num = 0; num < n; num++) { scanf("%d", &mon[num]); } for (int a = 1; a < n; a++) { fmin = calc_min(max(mon[a], mon[a - 1]), std::min(mon[a], mon[a - 1])); if (fmin < min) min = fmin; if (min == 1) break; } printf("%d", min); scanf("%d"); return 0; }
replace
19
25
19
24
TLE
p03127
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; pair<ll, ll> mininarray(vector<ll> a, int n) { ll mina = a.at(0); int ind = 0; rep(p, n) { if (a.at(p) != 0) { if (mina > a.at(p)) { mina = a.at(p); ind = p; } } } return make_pair(mina, ind); } int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a.at(i); pair<ll, ll> minind; ll mina, inda; bool flag = 1; while (flag) { flag = 0; minind = mininarray(a, n); mina = minind.first; inda = minind.second; rep(i, n) { if (i != inda) { a.at(i) = a.at(i) % mina; if (a.at(i) != 0) flag = 1; } // cout << a.at(i) << ' '; } // cout << endl; } cout << mina << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; pair<ll, ll> mininarray(vector<ll> a, int n) { ll mina = 1000000000; int ind = 0; rep(p, n) { if (a.at(p) != 0) { if (mina > a.at(p)) { mina = a.at(p); ind = p; } } } return make_pair(mina, ind); } int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a.at(i); pair<ll, ll> minind; ll mina, inda; bool flag = 1; while (flag) { flag = 0; minind = mininarray(a, n); mina = minind.first; inda = minind.second; rep(i, n) { if (i != inda) { a.at(i) = a.at(i) % mina; if (a.at(i) != 0) flag = 1; } // cout << a.at(i) << ' '; } // cout << endl; } cout << mina << endl; }
replace
6
7
6
7
0
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define ONLINE_JUDGE #define ll long long #define PI 3.14159265359 #define fore(i, l, r) for (int i = int(l); i < int(r); ++i) #define pb(a) push_back(a) //////////// Solution ///////////////////////////////// const int MAX = 1e5 + 1; void solve() { int n; cin >> n; int a[MAX]; int g = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; g = __gcd(g, a[i]); } cout << g << '\n'; } /////////// End Solution /////////////////////////////////////// //////// Initialization //////////////////////////////////// int main() { #ifndef ONLINE_JUDGE FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin); clock_t time_start = clock(); #endif ios::sync_with_stdio(false); cin.tie(NULL); solve(); #ifndef ONLINE_JUDGE fclose(FIN); cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m"; #endif return 0; } //////// End Initialization ///////////////////////////////////////
#include <bits/stdc++.h> using namespace std; #define ONLINE_JUDGE #define ll long long #define PI 3.14159265359 #define fore(i, l, r) for (int i = int(l); i < int(r); ++i) #define pb(a) push_back(a) //////////// Solution ///////////////////////////////// const int MAX = 1e5 + 1; void solve() { int n; cin >> n; int a[MAX]; int g = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; g = __gcd(g, a[i]); } cout << g << '\n'; } /////////// End Solution /////////////////////////////////////// //////// Initialization //////////////////////////////////// int main() { #ifndef ONLINE_JUDGE FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin); clock_t time_start = clock(); #endif ios::sync_with_stdio(false); cin.tie(NULL); solve(); #ifndef ONLINE_JUDGE fclose(FIN); cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock() - time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m"; #endif return 0; } //////// End Initialization ///////////////////////////////////////
replace
3
4
3
4
-11
p03127
C++
Time Limit Exceeded
#include <stdio.h> long long int gcd(long long int a, long long int b) { long long int tmp; while (1) { if (a % b == 0) { return b; break; } else { if (a > b) a = a - b; tmp = a; a = b; b = tmp; } } } int main(void) { long long int n, i, j, ans; scanf("%lld", &n); int a[n]; for (i = 0; i < n; i++) scanf("%lld", &a[i]); ans = a[0]; for (i = 0; i < n; i++) ans = gcd(ans, a[i]); printf("%lld", ans); }
#include <stdio.h> long long int gcd(long long int a, long long int b) { long long int tmp; while (1) { if (a % b == 0) { return b; break; } else { a = a % b; tmp = a; a = b; b = tmp; } } } int main(void) { long long int n, i, j, ans; scanf("%lld", &n); int a[n]; for (i = 0; i < n; i++) scanf("%lld", &a[i]); ans = a[0]; for (i = 0; i < n; i++) ans = gcd(ans, a[i]); printf("%lld", ans); }
replace
9
11
9
10
TLE
p03127
C++
Runtime Error
// AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // // AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #define _USE_MATH_DEFINES #include <math.h> // #include<cmath> #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> // #include "Ants.h" using namespace std; typedef long long ll; #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < n; i++) #define show(s) cout << s << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define LINF (1000000000000000000ll) // typedef pair < int, int> P; ll gcd(ll a, ll b) { // 最大公約数を求める///最大公倍数a*b/gcd(a,b) if (b == 0) return a; return gcd(b, a % b); } ll lcd(ll a, ll b) { // 最小公倍数を求める b=0のときaを返す if (b == 0) return a; return (a / gcd(a, b)) * b; } vector<int> divnum(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p; } int digiter(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p.size(); } vector<int> convertstring(string s) { vector<int> d; ll n = s.size(); rep(i, n) { d.push_back(s[i] - '0'); } return d; } map<int64_t, int> prime_factor(int64_t n) { map<int64_t, int> ret; for (int64_t i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; i++) { if (n % i != 0) continue; res.push_back(i); if (i * i != n) res.push_back(n / i); } return res; } ll MOD = 1000000007; ll myPow(ll x, ll n, ll m) { if (n == 0) return 1; if (n % 2 == 0) return myPow(x * x % m, n / 2, m); else return x * myPow(x, n - 1, m) % m; } int N, A[10000]; int main() { cin >> N; rep(i, N) cin >> A[i]; int ans = A[0]; rep(i, N) { ans = gcd(ans, A[i]); } cout << ans << endl; }
// AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // // AtCoder.cpp : このファイルには 'main' // 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #define _USE_MATH_DEFINES #include <math.h> // #include<cmath> #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> // #include "Ants.h" using namespace std; typedef long long ll; #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < n; i++) #define show(s) cout << s << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define LINF (1000000000000000000ll) // typedef pair < int, int> P; ll gcd(ll a, ll b) { // 最大公約数を求める///最大公倍数a*b/gcd(a,b) if (b == 0) return a; return gcd(b, a % b); } ll lcd(ll a, ll b) { // 最小公倍数を求める b=0のときaを返す if (b == 0) return a; return (a / gcd(a, b)) * b; } vector<int> divnum(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p; } int digiter(ll num) { int dig; vector<int> p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p.size(); } vector<int> convertstring(string s) { vector<int> d; ll n = s.size(); rep(i, n) { d.push_back(s[i] - '0'); } return d; } map<int64_t, int> prime_factor(int64_t n) { map<int64_t, int> ret; for (int64_t i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> res; for (ll i = 1; i * i <= n; i++) { if (n % i != 0) continue; res.push_back(i); if (i * i != n) res.push_back(n / i); } return res; } ll MOD = 1000000007; ll myPow(ll x, ll n, ll m) { if (n == 0) return 1; if (n % 2 == 0) return myPow(x * x % m, n / 2, m); else return x * myPow(x, n - 1, m) % m; } int N, A[200000]; int main() { cin >> N; rep(i, N) cin >> A[i]; int ans = A[0]; rep(i, N) { ans = gcd(ans, A[i]); } cout << ans << endl; }
replace
117
118
117
118
0
p03127
C++
Time Limit Exceeded
// INCLUDE //------------------------------------------ #include <bits/stdc++.h> // DEFINE //------------------------------------------ #define ll long long #define ld long double #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> // CONST //------------------------------------------ #define INF 1010000000000000017LL #define MOD 1000000007LL #define EPS 1e-12 #define PI 3.14159265358979323846 // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) //----------------------------------------- #define dcml(n) fixed << setprecision(n) using namespace std; ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n--; return m; } ll modPow(ll x, ll n, ll mod = MOD) { return (!n ? 1 : !n % 2 ? modPow(x * x, n / 2, mod) % mod : x % mod * modPow(x, n - 1, mod) % mod); } int main(void) { ll N; cin >> N; ll ans = INF; ll A; vi v; REP(i, N) { cin >> A; for (auto it = v.begin(); 1;) { if (it == v.end()) { v.push_back(A); break; } if (*it % A == 0) { it = v.erase(it); } else { ans = min(ans, GCD(*it, A)); ++it; } ans = min(ans, A); } } cout << ans << "\n"; }
// INCLUDE //------------------------------------------ #include <bits/stdc++.h> // DEFINE //------------------------------------------ #define ll long long #define ld long double #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> // CONST //------------------------------------------ #define INF 1010000000000000017LL #define MOD 1000000007LL #define EPS 1e-12 #define PI 3.14159265358979323846 // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) //----------------------------------------- #define dcml(n) fixed << setprecision(n) using namespace std; ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n--; return m; } ll modPow(ll x, ll n, ll mod = MOD) { return (!n ? 1 : !n % 2 ? modPow(x * x, n / 2, mod) % mod : x % mod * modPow(x, n - 1, mod) % mod); } int main(void) { ll N; cin >> N; vi v(N); REP(i, N) cin >> v[i]; REPS(i, N - 1) { v[i] = GCD(v[i], v[i - 1]); } cout << v[N - 1] << "\n"; }
replace
45
65
45
49
TLE
p03127
C++
Runtime Error
#include <iostream> #include <utility> int n; int a; int gcd(int x, int y) { if (x > y) std::swap(x, y); return (x == 1) ? y : gcd(y % x, x); } int main() { std::cin >> n; std::cin >> a; int g = a; for (int i = 0; i < n - 1; ++i) { std::cin >> a; g = gcd(g, a); } std::cout << g << std::endl; return 0; }
#include <iostream> #include <utility> int n; int a; int gcd(int x, int y) { if (x > y) std::swap(x, y); return (x == 0) ? y : gcd(y % x, x); } int main() { std::cin >> n; std::cin >> a; int g = a; for (int i = 0; i < n - 1; ++i) { std::cin >> a; g = gcd(g, a); } std::cout << g << std::endl; return 0; }
replace
10
11
10
11
-8
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { int c; c = a % b; a = b; b = c; if (c == 0) { return a; } else { return GCD(a, b); } } int main() { int N, i, j, mn = 1000000000; cin >> N; vector<int> A(N); for (i = 0; i < N; i++) cin >> A[i]; for (i = 0; i < N; i++) { for (j = i + 1; j < N; j++) { mn = min(mn, GCD(A[i], A[j])); } } cout << mn << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { int c; c = a % b; a = b; b = c; if (c == 0) { return a; } else { return GCD(a, b); } } int main() { int N, i, j, mn = 1000000000; cin >> N; vector<int> A(N); for (i = 0; i < N; i++) cin >> A[i]; for (i = 0; i < N - 1; i++) { mn = min(mn, GCD(A[i], A[i + 1])); } cout << mn << endl; return 0; }
replace
24
28
24
26
TLE
p03127
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG // TLEの原因になるので注意!!!!!!!!!!! #include <bits/stdc++.h> #include <cmath> typedef long long ll; using namespace std; vector<int> arr; stack<int> st; queue<int> qu; queue<pair<int, int>> qu2; priority_queue<int> pq; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, n) for (int i = 1; i <= (int)(n); i++) typedef set<int> set_t; typedef set<string> set_g; typedef complex<double> xy_t; static const int NIL = -1; static const int INF = 1000000007; #define mp make_pair /*int P[10010]; void init(int n){//Union-find for(int i=0;i<n;++i)P[i]=i; } int root(int a) { if(P[a]==a)return a; return (P[a]=root(P[a])); } bool is_same_set(int a,int b){ return root(a) == root(b);//代表元を求める } void unite(int a,int b){ P[root(a)]=root(b); }//対set,グラフ? //セグメント木?? */ // Unionfind ,Disjointset 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)]; } // AとBをくっつける int connect(int A, int B) { // AとBを直接ではなくAのrootとBのrootをくっつける A = root(A); B = root(B); if (A == B) { return false; // すでにくっついている } if (size(A) < size(B)) swap(A, B); // Aのサイズ更新 Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); } // 内積 double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } // 外積 xy_t projection(xy_t p, xy_t b) { return b * dot_product(p, b) / norm(b); } // 投影 // 対図形 #define mod 1000000007 /*ll f[2001]; //int n,k とかしておく ll pw(ll x, ll y){//euclidの互除法より ll a= 1; while(y){ if(y&1){//奇数なら a = a*x%mod; } x = x*x%mod; y /= 2; } return a; } ll modinv(ll x){//逆元を求める return pw(x, mod - 2 ); } ll comb(int n,int r){ if(n<r){ return 0; } return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod; }//対combination//ただしfは用意してね */ struct BIT { vector<int> dat; int sz; BIT(int n) { for (sz = 1; sz < n; sz *= 2) ; dat.resize(++sz); } int q(int n) { int ret = 0; for (int i = n; i > 0; i -= i & -i) ret += dat[i]; // 和の計算 iから最後の1のbit(i&-i // 多分&はビット積)を減算 for (int i = n; i < sz; i += i & -i) dat[i]++; // 値の加算 iから最後mの1のbitを加算 return ret; } }; /* // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this;//thisポインター thisで自分自身のアドレス } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; */ int main() { int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } sort(a.begin(), a.end(), greater<int>()); // cout<<a[0]; while (a[1] != 0) { rep(i, n - 1) { int temp = 0; a[i] = a[i] % a[n - 1]; if (a[i] <= 0) { a[i] = 0; temp++; } n -= temp; } // cout<<a[0]; sort(a.begin(), a.end(), greater<int>()); } cout << a[0] << endl; return 0; }
#include <bits/stdc++.h> #include <cmath> typedef long long ll; using namespace std; vector<int> arr; stack<int> st; queue<int> qu; queue<pair<int, int>> qu2; priority_queue<int> pq; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, n) for (int i = 1; i <= (int)(n); i++) typedef set<int> set_t; typedef set<string> set_g; typedef complex<double> xy_t; static const int NIL = -1; static const int INF = 1000000007; #define mp make_pair /*int P[10010]; void init(int n){//Union-find for(int i=0;i<n;++i)P[i]=i; } int root(int a) { if(P[a]==a)return a; return (P[a]=root(P[a])); } bool is_same_set(int a,int b){ return root(a) == root(b);//代表元を求める } void unite(int a,int b){ P[root(a)]=root(b); }//対set,グラフ? //セグメント木?? */ // Unionfind ,Disjointset 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)]; } // AとBをくっつける int connect(int A, int B) { // AとBを直接ではなくAのrootとBのrootをくっつける A = root(A); B = root(B); if (A == B) { return false; // すでにくっついている } if (size(A) < size(B)) swap(A, B); // Aのサイズ更新 Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; double dot_product(xy_t a, xy_t b) { return (conj(a) * b).real(); } // 内積 double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); } // 外積 xy_t projection(xy_t p, xy_t b) { return b * dot_product(p, b) / norm(b); } // 投影 // 対図形 #define mod 1000000007 /*ll f[2001]; //int n,k とかしておく ll pw(ll x, ll y){//euclidの互除法より ll a= 1; while(y){ if(y&1){//奇数なら a = a*x%mod; } x = x*x%mod; y /= 2; } return a; } ll modinv(ll x){//逆元を求める return pw(x, mod - 2 ); } ll comb(int n,int r){ if(n<r){ return 0; } return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod; }//対combination//ただしfは用意してね */ struct BIT { vector<int> dat; int sz; BIT(int n) { for (sz = 1; sz < n; sz *= 2) ; dat.resize(++sz); } int q(int n) { int ret = 0; for (int i = n; i > 0; i -= i & -i) ret += dat[i]; // 和の計算 iから最後の1のbit(i&-i // 多分&はビット積)を減算 for (int i = n; i < sz; i += i & -i) dat[i]++; // 値の加算 iから最後mの1のbitを加算 return ret; } }; /* // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this;//thisポインター thisで自分自身のアドレス } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; */ int main() { int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } sort(a.begin(), a.end(), greater<int>()); // cout<<a[0]; while (a[1] != 0) { rep(i, n - 1) { int temp = 0; a[i] = a[i] % a[n - 1]; if (a[i] <= 0) { a[i] = 0; temp++; } n -= temp; } // cout<<a[0]; sort(a.begin(), a.end(), greater<int>()); } cout << a[0] << endl; return 0; }
delete
0
1
0
0
TLE
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<int, P> P3; const ll MOD = ll(1e9) + 7; const int IINF = INT_MAX; const ll LLINF = LLONG_MAX; const int MAX_N = int(1e5 + 5); const double EPS = 1e-11; const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0}; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define SORT(v) sort((v).begin(), (v).end()) #define ALL(v) (v).begin(), (v).end() int gcd(int p, int q) { if (p % q == 0) return q; else return gcd(q, p % q); } int main() { int n, ans = 0; cin >> n; REP(i, n) { int a; cin >> a; ans = gcd(a, ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<int, P> P3; const ll MOD = ll(1e9) + 7; const int IINF = INT_MAX; const ll LLINF = LLONG_MAX; const int MAX_N = int(1e5 + 5); const double EPS = 1e-11; const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0}; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define SORT(v) sort((v).begin(), (v).end()) #define ALL(v) (v).begin(), (v).end() int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } int main() { int n, ans = 0; cin >> n; REP(i, n) { int a; cin >> a; ans = gcd(a, ans); } cout << ans << endl; return 0; }
replace
17
19
17
19
-8
p03127
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> int gcd(int a, int b); int gcd(std::vector<int> a); int main() { int n; std::vector<int> v(n); for (int &x : v) { std::cin >> x; } std::cout << gcd(v) << std::endl; return 0; } int gcd(int a, int b) { if (a % b == 0) { return b; } else { return (gcd(b, a % b)); } } int gcd(std::vector<int> a) { int ans = a[0]; for (int i = 0; i < a.size(); i++) { ans = gcd(ans, a[i]); } return ans; }
#include <algorithm> #include <iostream> #include <vector> int gcd(int a, int b); int gcd(std::vector<int> a); int main() { int n; std::cin >> n; std::vector<int> v(n); for (int &x : v) { std::cin >> x; } std::cout << gcd(v) << std::endl; return 0; } int gcd(int a, int b) { if (a % b == 0) { return b; } else { return (gcd(b, a % b)); } } int gcd(std::vector<int> a) { int ans = a[0]; for (int i = 0; i < a.size(); i++) { ans = gcd(ans, a[i]); } return ans; }
insert
9
9
9
11
-8
p03127
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int ans = A[0]; for (int i = 0; i < N - 1; i++) { for (int j = i; j < N; j++) { ans = min(ans, gcd(A[i], A[j])); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; int ans = A[0]; for (int i = 0; i < N - 1; i++) { ans = min(ans, gcd(A[i], A[i + 1])); } cout << ans << endl; return 0; }
replace
26
29
26
27
TLE
p03127
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() #define PRI(n) cout << n << endl; #define PRI2(n, m) cout << n << " " << m << " " << endl; #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, t, n) for (int i = t; i <= (int)n; ++i) const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; const ll MOD = (ll)1e9 + 7; const int MAX_INT = 1 << 17; struct edge { int to, cost; bool flag = false; }; bool isPrime(ll x) { if (x == 0) return 0; if (x == 1) return 0; if (x == 2) return 1; if (x % 2 == 0) return 0; FOR(i, 3, x - 1) { if (x % i == 0) return 0; } return 1; } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { ll gcd = GCD(a, b); return a / gcd * b; } ll nCr(int n, int r) { vector<ll> C(r + 1); C[0] = 1; FOR(i, 1, n) for (int j = min(i, r); j < 1; --j) C[j] = (C[j] + C[j - 1]) % MOD; return C[r]; } template <class T> class SegTree { int n; vector<T> data; T def; function<T(T, T)> operation; function<T(T, T)> update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } } public: SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int N) { for (int i = 0; i < N; ++i) { par.push_back(i); rank.push_back(0); } } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; ll M, N; struct pa { double x, y; }; string S; int main() { ifstream in("C://Users/Uaer/CLionProjects/Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; ll c = A[0]; FOR(i, 1, N - 1) { c = GCD(c, A[i]); } PRI(c) return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() #define PRI(n) cout << n << endl; #define PRI2(n, m) cout << n << " " << m << " " << endl; #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, t, n) for (int i = t; i <= (int)n; ++i) const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; const ll MOD = (ll)1e9 + 7; const int MAX_INT = 1 << 17; struct edge { int to, cost; bool flag = false; }; bool isPrime(ll x) { if (x == 0) return 0; if (x == 1) return 0; if (x == 2) return 1; if (x % 2 == 0) return 0; FOR(i, 3, x - 1) { if (x % i == 0) return 0; } return 1; } ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { ll gcd = GCD(a, b); return a / gcd * b; } ll nCr(int n, int r) { vector<ll> C(r + 1); C[0] = 1; FOR(i, 1, n) for (int j = min(i, r); j < 1; --j) C[j] = (C[j] + C[j - 1]) % MOD; return C[r]; } template <class T> class SegTree { int n; vector<T> data; T def; function<T(T, T)> operation; function<T(T, T)> update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } } public: SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int N) { for (int i = 0; i < N; ++i) { par.push_back(i); rank.push_back(0); } } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; ll M, N; struct pa { double x, y; }; string S; int main() { cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; ll c = A[0]; FOR(i, 1, N - 1) { c = GCD(c, A[i]); } PRI(c) return 0; }
delete
155
157
155
155
-11
p03127
C++
Runtime Error
#include <iostream> using namespace std; #define MAX 10000 int N; long int A[MAX]; bool one_survive() { int survive = 0; for (int i = 0; i < N; i++) { if (A[i] > 0) { survive += 1; } } if (survive == 1) { return true; } else { return false; } } int main() { cin >> N; for (int i = 0; i < N; i++) { long int a; cin >> a; A[i] = a; } // long int minimum = A[0]; long int min_val = A[0]; int min_idx = 0; while (true) { if (one_survive()) { break; } for (int i = 0; i < N; i++) { if (A[i] > 0 && min_val >= A[i]) { min_val = A[i]; min_idx = i; } } for (int i = 0; i < N; i++) { if (i == min_idx || A[i] <= 0) { continue; } else { A[i] %= min_val; } } } cout << min_val << endl; return 0; }
#include <iostream> using namespace std; #define MAX 100000 int N; long int A[MAX]; bool one_survive() { int survive = 0; for (int i = 0; i < N; i++) { if (A[i] > 0) { survive += 1; } } if (survive == 1) { return true; } else { return false; } } int main() { cin >> N; for (int i = 0; i < N; i++) { long int a; cin >> a; A[i] = a; } // long int minimum = A[0]; long int min_val = A[0]; int min_idx = 0; while (true) { if (one_survive()) { break; } for (int i = 0; i < N; i++) { if (A[i] > 0 && min_val >= A[i]) { min_val = A[i]; min_idx = i; } } for (int i = 0; i < N; i++) { if (i == min_idx || A[i] <= 0) { continue; } else { A[i] %= min_val; } } } cout << min_val << endl; return 0; }
replace
2
3
2
3
0
p03127
C++
Runtime Error
// // Created by yuu on 2019-06-30. // #include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } // int lcm(int a, int b) { // return a * b / gcd(a, b); // } // // // long long c_lcm(long a, long b){ // long long x = a *b; // long long tmp, r; // if(a<b){ // tmp = a; // a = b; // b = tmp; // } // // r = a % b; // while(r!=0){ // a = b; // b = r; // r = a % b; // } // // return x/b; // } int A[10010]; int main(void) { int N; cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i]; } // sort(A,A+N); // int min = A[0]; // if(min>lcm(A[0], A[1])){ // min = lcm(A[0], A[1]); // } int temp = A[0]; for (int i = 1; i < N; ++i) { temp = gcd(temp, A[i]); // cout<<A[i]<<endl; // if(min>temp && temp > 0){ // min = temp; // } } cout << temp << endl; return 0; }
// // Created by yuu on 2019-06-30. // #include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } // int lcm(int a, int b) { // return a * b / gcd(a, b); // } // // // long long c_lcm(long a, long b){ // long long x = a *b; // long long tmp, r; // if(a<b){ // tmp = a; // a = b; // b = tmp; // } // // r = a % b; // while(r!=0){ // a = b; // b = r; // r = a % b; // } // // return x/b; // } int A[100010]; int main(void) { int N; cin >> N; for (int i = 0; i < N; ++i) { cin >> A[i]; } // sort(A,A+N); // int min = A[0]; // if(min>lcm(A[0], A[1])){ // min = lcm(A[0], A[1]); // } int temp = A[0]; for (int i = 1; i < N; ++i) { temp = gcd(temp, A[i]); // cout<<A[i]<<endl; // if(min>temp && temp > 0){ // min = temp; // } } cout << temp << endl; return 0; }
replace
48
49
48
49
0
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <numeric> using namespace std; int main() { int n; cin >> n; vector<int> monsters(n); for (int i = 0; i < monsters.size(); i++) { cin >> monsters[i]; } int min = monsters[0]; for (int pow : monsters) { min = __gcd(min, pow); } cout << min << endl; }
#include <bits/stdc++.h> #include <numeric> using namespace std; int main() { int n; cin >> n; vector<int> monsters(n); for (int i = 0; i < monsters.size(); i++) { cin >> monsters[i]; } int min = monsters[0]; for (int i = 0; i < monsters.size(); i++) { min = __gcd(min, monsters[i]); } cout << min << endl; }
replace
12
14
12
14
TLE
p03127
C++
Runtime Error
#include "bits/stdc++.h" #define REP(i, num) for (int i = 0; i < (num); ++i) #define ALL(c) c.begin(), c.end() #define PRINTALL(c) \ for (auto &x : c) { \ cout << x << ' '; \ } \ cout << endl; using namespace std; using ll = long long; template <typename T = int> T in() { T x; cin >> x; return (x); } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = in(); vector<int> s(N); int mp = 1e9 + 7; REP(i, N) { s[i] = in(); } do { auto res = min_element( ALL(s), [](int l, int r) { return (l < r && l != 0 && r != 0); }); mp = *res; int index = distance(s.begin(), res); REP(i, N) { if (i != index) s[i] %= mp; } } while (count(ALL(s), 0) < N - 1); cout << mp << endl; return 0; }
#include "bits/stdc++.h" #define REP(i, num) for (int i = 0; i < (num); ++i) #define ALL(c) c.begin(), c.end() #define PRINTALL(c) \ for (auto &x : c) { \ cout << x << ' '; \ } \ cout << endl; using namespace std; using ll = long long; template <typename T = int> T in() { T x; cin >> x; return (x); } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = in(); vector<int> s(N); int mp = 1e9 + 7; REP(i, N) { s[i] = in(); } do { int index; REP(i, N) { if (s[i] > 0 && mp > s[i]) { mp = s[i]; index = i; } } REP(i, N) { if (i != index) s[i] %= mp; } } while (count(ALL(s), 0) < N - 1); cout << mp << endl; return 0; }
replace
28
32
28
35
0
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (a != b) { if (a > b) a = a - b; if (a < b) b = b - a; } return a; } int main() { int N; cin >> N; vector<int> S(N); for (int i = 0; i < N; i++) { cin >> S.at(i); } for (int i = 1; i < N; i++) { S.at(i) = gcd(S.at(i - 1), S.at(i)); } cout << S.at(N - 1) << endl; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { while (a != b) { if (a > b) { if (a % b == 0) return b; else a = a % b; } if (a < b) { if (b % a == 0) return a; else b = b % a; } } return a; } int main() { int N; cin >> N; vector<int> S(N); for (int i = 0; i < N; i++) { cin >> S.at(i); } for (int i = 1; i < N; i++) { S.at(i) = gcd(S.at(i - 1), S.at(i)); } cout << S.at(N - 1) << endl; }
replace
5
9
5
17
TLE
p03127
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define ll long long ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(b, a % b); } int main() { int n; cin >> n; vector<ll> a; for (int i = 0; i < n; i++) cin >> a[i]; ll ans = a[0]; for (int i = 0; i < n; i++) { ans = gcd(ans, a[i]); } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define ll long long ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(b, a % b); } int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; ll ans = a[0]; for (int i = 0; i < n; i++) { ans = gcd(ans, a[i]); } cout << ans << endl; }
replace
24
25
24
25
-11
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define SORT(i) sort((i).begin(), (i).end()) #define INF 2000000000 constexpr ll mod = 1000000007; ll gcd(ll x, ll y) { return y != 0 ? gcd(y, x % y) : x; } int main() { int N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } SORT(A); ll ans = A[0]; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { ans = min(ans, gcd(A[i], A[j])); } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define SORT(i) sort((i).begin(), (i).end()) #define INF 2000000000 constexpr ll mod = 1000000007; ll gcd(ll x, ll y) { return y != 0 ? gcd(y, x % y) : x; } int main() { int N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } ll ans = INF; for (int i = 0; i < N - 1; ++i) { A[i + 1] = gcd(A[i], A[i + 1]); ans = min(ans, A[i + 1]); } cout << ans << "\n"; return 0; }
replace
16
22
16
20
TLE
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (x = 0 || y == 0) return max(x, y); else { if (x < y) return gcd(x, y % x); else if (y < x) return gcd(y, x % y); else return x; } } int main() { int N; cin >> N; int Min; cin >> Min; for (int i = 0; i < N - 1; i++) { int a; cin >> a; Min = gcd(a, Min); } cout << Min << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (x == 0 || y == 0) return max(x, y); else { if (x < y) return gcd(x, y % x); else if (y < x) return gcd(y, x % y); else return x; } } int main() { int N; cin >> N; int Min; cin >> Min; for (int i = 0; i < N - 1; i++) { int a; cin >> a; Min = gcd(a, Min); } cout << Min << endl; return 0; }
replace
3
4
3
4
-8
p03127
C++
Time Limit Exceeded
#include <iostream> #include <stdio.h> #include <string> using namespace std; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } int main(void) { int n; cin >> n; long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long gcdmin = 10000000000; for (int i = 0; i < n - 1; i++) { for (int t = i + 1; t < n; t++) { long newvalue = euclidean_gcd(a[i], a[t]); gcdmin = min(gcdmin, newvalue); } } cout << gcdmin << endl; return 0; }
#include <iostream> #include <stdio.h> #include <string> using namespace std; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } int main(void) { int n; cin >> n; long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; long gcdmin = 10000000000; gcdmin = euclidean_gcd(a[0], a[1]); for (int i = 2; i < n; i++) { gcdmin = euclidean_gcd(gcdmin, a[i]); } cout << gcdmin << endl; return 0; }
replace
27
32
27
31
TLE
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int Solve() { int n; cin >> n; int res = INT_MAX; priority_queue<int> que; for (int i = 0, a; i < n; ++i) { cin >> a; que.push(a); res = min(res, a); } while (1 < que.size()) { int cur = que.top(); que.pop(); res = min(res, cur); if (1 <= cur - que.top()) que.push(cur - que.top()); } return min(res, que.top()); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << Solve() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int Solve() { int n; cin >> n; int res = INT_MAX; priority_queue<int> que; for (int i = 0, a; i < n; ++i) { cin >> a; que.push(a); res = min(res, a); } while (1 < que.size()) { int cur = que.top(); que.pop(); res = min(res, cur); int a = cur - (int)((cur - 1) / que.top()) * que.top(); if (1 <= cur - que.top() && a < cur) que.push(a); } return min(res, que.top()); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << Solve() << endl; return 0; }
replace
22
24
22
25
TLE
p03127
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; ll gcd(ll m, ll n) { if (m == 0 || n == 0) return 0; // ユークリッドの方法 while (m != n) { if (m > n) m = m - n; else n = n - m; } return m; } int main(void) { int N; cin >> N; vector<ll> A(N); vector<bool> used(N, false); for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = gcd(A[0], A[1]); used[0] = used[1] = true; for (int i = 2; i < N; i++) { if (A[i] % A[0] == 0 || A[i] % A[1] == 0) used[i] = true; } // remove Ai s.t. Ai % A[0] == 0 or Ai % A[1] == 0 for (int i = 2; i < N; i++) { if (!used[i]) { ans = gcd(ans, A[i]); used[i] = true; for (int k = i + 1; k < N; k++) { if (used[k]) continue; if (A[k] % A[i] == 0) { used[k] = true; } } } } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; ll gcd(ll m, ll n) { if (m == 0 || n == 0) return 0; // ユークリッドの方法 while (m != n) { if (m > n) m = m - n; else n = n - m; } return m; } int main(void) { int N; cin >> N; vector<ll> A(N); vector<bool> used(N, false); for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = gcd(A[0], A[1]); used[0] = used[1] = true; for (int i = 2; i < N; i++) { if (A[i] % A[0] == 0 || A[i] % A[1] == 0) used[i] = true; } // remove Ai s.t. Ai % A[0] == 0 or Ai % A[1] == 0 for (int i = 2; i < N; i++) { if (!used[i]) { ans = gcd(ans, A[i]); used[i] = true; for (int k = i + 1; k < N; k++) { if (A[k] % ans == 0) { used[k] = true; } } } } cout << ans << endl; }
replace
47
50
47
48
TLE
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long int gcd(long int m, long int n) { if ((0 == m) || (0 == n)) return 0; while (m != n) { if (m > n) m = m - n; else n = n - m; } return m; } int main() { int n; cin >> n; long int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int g = 1; if (a[0] == 1 || a[1] == 1) { cout << 1; return 0; } g = gcd(a[0], a[1]); if (n > 2) { for (int i = 2; i < n; ++i) { g = gcd(g, a[i]); if (g == 1) { break; } } } cout << g; }
#include <bits/stdc++.h> using namespace std; long int gcd(long int m, long int n) { if ((0 == m) || (0 == n)) return 0; while (m != n) { if (m > n) { if (m % n == 0) { m = n; } else { m = m % n; } } else { if (n % m == 0) { n = m; } else { n = n % m; } } } return m; } int main() { int n; cin >> n; long int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int g = 1; if (a[0] == 1 || a[1] == 1) { cout << 1; return 0; } g = gcd(a[0], a[1]); if (n > 2) { for (int i = 2; i < n; ++i) { g = gcd(g, a[i]); if (g == 1) { break; } } } cout << g; }
replace
7
11
7
20
TLE
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long GCD(long long A, long long B) { long long R = A % B; while (R != 0) { A = B; B = R; R = A % B; } return B; } int main(void) { int N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); long long MaxG = 1000000000; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) MaxG = min(MaxG, GCD(A[j], A[i])); } cout << MaxG << endl; }
#include <bits/stdc++.h> using namespace std; long long GCD(long long A, long long B) { long long R = A % B; while (R != 0) { A = B; B = R; R = A % B; } return B; } int main(void) { int N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); long long MaxG = 1000000000; for (int i = 0; i < N - 1; i++) MaxG = min(MaxG, GCD(A[i + 1], A[i])); cout << MaxG << endl; }
replace
19
23
19
21
TLE
p03127
C++
Time Limit Exceeded
#include <algorithm> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; #define rep(i, a, n) for (int i = (a); i < (n); i++) #define ll long long #define llint long long int #define sort(s) sort(s.begin(), s.end()) #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) \ if (ans) \ cout << "Yes" << endl; \ else \ cout << "No" << endl; #define YES(ans) \ if (ans) \ cout << "YES" << endl; \ else \ cout << "NO" << endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define rt \ (a); \ return (a); #define Pint pair<int, int> #define keta(a) fixed << setprecision(a) constexpr auto INF = 1000000000; constexpr auto mod = 1000000007; // 辞書順はnext_permutation( begin( v ), end( v ) );やで! // 2のn乗を求めるよ!!! int ni(int n) { if (n == 0) return 1; int x = ni(n / 2); x *= x; if (n % 2 == 1) x *= 2; return x; } // フィボナッチ数列のx番目を求めるよ! llint f(int x, vector<llint> &s) { if (x == 0) return 0; if (x == 1) return 1; if (s[x] != 0) return s[x]; return s[x] = f(x - 1, s) + f(x - 2, s); } // aとbの最大公約数を求めるよ! llint gcd(llint a, llint b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // mod. m での a の逆元 a^{-1} を計算するよ! long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // aCbをmod.mで割った余りを求める ll int c(ll int a, ll int b, ll int m) { ll int ans = 1; for (ll int i = 0; i < b; i++) { ans *= a - i; ans %= m; } for (ll int i = 1; i <= b; i++) { ans *= modinv(i, m); ans %= m; } return ans; } // m進数のn桁を全列挙やで void dfs(int m, int n, llint k, hei(llint) a) { stack<string> st; st.push(""); while (!st.empty()) { string now = st.top(); st.pop(); if (now.size() == n) { cout << now << endl; } else { for (int i = m - 1; i >= 0; i--) { string next = now + to_string(i); st.push(next); } } } } void press(vector<int> &v) { v.erase(unique((v).begin(), (v).end()), v.end()); } void press(vector<char> &v) { v.erase(unique((v).begin(), (v).end()), v.end()); } struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int size(int a) { return par[root(a)]; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; struct segmenttree { hei(int) seg; int s; segmenttree(int n) : seg(n * 2 - 1) { for (int i = 0; i < n * 2 - 1; i++) seg[i] = 0; s = n; } // k番目の値をaに変更 void update(int k, int a) { k += s - 1; seg[k] += a; while (k > 0) { k = (k - 1) / 2; seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]); } } // 最初はquery(a,b,0,0,n)で呼ぶよ!!!! int query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 1000000; if (a <= l && r <= b) return seg[k]; else { int v1 = query(a, b, k * 2 + 1, l, (l + r) / 2); int v2 = query(a, b, k * 2 + 2, (l + r) / 2, r); return min(v1, v2); } } }; int main() { int n; cin >> n; hei(int) a(n); rep(i, 0, n) cin >> a[i]; sort(a); int ans = a[n - 1]; rep(i, 0, n - 1) { rep(j, i + 1, n) { int x = gcd(a[i], a[j]); ans = min(ans, x); } } cout << ans << endl; return 0; }
#include <algorithm> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; #define rep(i, a, n) for (int i = (a); i < (n); i++) #define ll long long #define llint long long int #define sort(s) sort(s.begin(), s.end()) #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) \ if (ans) \ cout << "Yes" << endl; \ else \ cout << "No" << endl; #define YES(ans) \ if (ans) \ cout << "YES" << endl; \ else \ cout << "NO" << endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define rt \ (a); \ return (a); #define Pint pair<int, int> #define keta(a) fixed << setprecision(a) constexpr auto INF = 1000000000; constexpr auto mod = 1000000007; // 辞書順はnext_permutation( begin( v ), end( v ) );やで! // 2のn乗を求めるよ!!! int ni(int n) { if (n == 0) return 1; int x = ni(n / 2); x *= x; if (n % 2 == 1) x *= 2; return x; } // フィボナッチ数列のx番目を求めるよ! llint f(int x, vector<llint> &s) { if (x == 0) return 0; if (x == 1) return 1; if (s[x] != 0) return s[x]; return s[x] = f(x - 1, s) + f(x - 2, s); } // aとbの最大公約数を求めるよ! llint gcd(llint a, llint b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // mod. m での a の逆元 a^{-1} を計算するよ! long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // aCbをmod.mで割った余りを求める ll int c(ll int a, ll int b, ll int m) { ll int ans = 1; for (ll int i = 0; i < b; i++) { ans *= a - i; ans %= m; } for (ll int i = 1; i <= b; i++) { ans *= modinv(i, m); ans %= m; } return ans; } // m進数のn桁を全列挙やで void dfs(int m, int n, llint k, hei(llint) a) { stack<string> st; st.push(""); while (!st.empty()) { string now = st.top(); st.pop(); if (now.size() == n) { cout << now << endl; } else { for (int i = m - 1; i >= 0; i--) { string next = now + to_string(i); st.push(next); } } } } void press(vector<int> &v) { v.erase(unique((v).begin(), (v).end()), v.end()); } void press(vector<char> &v) { v.erase(unique((v).begin(), (v).end()), v.end()); } struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int size(int a) { return par[root(a)]; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; struct segmenttree { hei(int) seg; int s; segmenttree(int n) : seg(n * 2 - 1) { for (int i = 0; i < n * 2 - 1; i++) seg[i] = 0; s = n; } // k番目の値をaに変更 void update(int k, int a) { k += s - 1; seg[k] += a; while (k > 0) { k = (k - 1) / 2; seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]); } } // 最初はquery(a,b,0,0,n)で呼ぶよ!!!! int query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 1000000; if (a <= l && r <= b) return seg[k]; else { int v1 = query(a, b, k * 2 + 1, l, (l + r) / 2); int v2 = query(a, b, k * 2 + 2, (l + r) / 2, r); return min(v1, v2); } } }; int main() { int n; cin >> n; hei(int) a(n); rep(i, 0, n) cin >> a[i]; sort(a); int ans = gcd(a[0], a[1]); rep(i, 1, n - 1) { int x = gcd(a[i], a[i + 1]); ans = min(ans, x); } cout << ans << endl; return 0; }
replace
207
213
207
211
TLE
p03127
C++
Runtime Error
#include <bits/stdc++.h> #include <numeric> long long int GCD(long long int a, long long int b) { long long int c; while (b != 0) { c = a % b; a = b; b = c; } return a; } using namespace std; int main() { int n; long long int a[n + 1]; for (int i = 0; i != n; i++) { cin >> a[i]; } long long int x; x = a[0]; for (int i = 1; i != n; i++) { x = GCD(x, a[i]); } cout << x << endl; }
#include <bits/stdc++.h> #include <numeric> long long int GCD(long long int a, long long int b) { long long int c; while (b != 0) { c = a % b; a = b; b = c; } return a; } using namespace std; int main() { int n; cin >> n; long long int a[n + 1]; for (int i = 0; i != n; i++) { cin >> a[i]; } long long int x; x = a[0]; for (int i = 1; i != n; i++) { x = GCD(x, a[i]); } cout << x << endl; }
insert
15
15
15
16
0
p03127
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N; int A[200]; int Min = 1000000000; cin >> N; int beforemin = 12345; int aftermin = 56789; for (int i = 0; i < N; ++i) cin >> A[i]; while (true) { for (int i = 0; i < N; ++i) if ((A[i] != 0) && (A[i] < Min)) Min = A[i]; if (beforemin == Min) break; for (int i = 0; i < N; ++i) if (A[i] != Min) A[i] = A[i] % Min; beforemin = Min; } cout << Min << endl; }
#include <iostream> using namespace std; int main() { int N; int A[1000002]; int Min = 1000000000; cin >> N; int beforemin = 12345; int aftermin = 56789; for (int i = 0; i < N; ++i) cin >> A[i]; while (true) { for (int i = 0; i < N; ++i) if ((A[i] != 0) && (A[i] < Min)) Min = A[i]; if (beforemin == Min) break; for (int i = 0; i < N; ++i) if (A[i] != Min) A[i] = A[i] % Min; beforemin = Min; } cout << Min << endl; }
replace
5
6
5
6
0
p03127
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int yg(int a, int b) { int tmp; if (a < b) { tmp = a; a = b; b = tmp; } int r = a % b; while (r != 0) { a = b; b = r; } return b; } int v[110000]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> v[i]; } for (int i = 0; i < n - 1; ++i) { v[i + 1] = yg(v[i], v[i + 1]); } cout << v[n - 1] << endl; }
#include <iostream> #include <vector> using namespace std; int yg(int a, int b) { int tmp; if (a < b) { tmp = a; a = b; b = tmp; } int r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } int v[110000]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> v[i]; } for (int i = 0; i < n - 1; ++i) { v[i + 1] = yg(v[i], v[i + 1]); } cout << v[n - 1] << endl; }
insert
14
14
14
15
TLE
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a.at(i); } sort(a.begin(), a.end()); vector<long long> r(105, 1); int count = 0; for (long long i = 1; i * i <= a.at(0); i++) { if (a.at(0) % i == 0) { r.at(2 * count) = i; r.at(2 * count + 1) = a.at(0) / i; count++; } } sort(r.begin(), r.end(), greater<long long>()); int test = 1; long long cv; for (int i = 0; i < r.size(); i++) { if (test == 1) { for (int j = 1; j < n; j++) { if (a.at(j) % r.at(i) != 0) { test = 1; break; } if (j == (n - 1) && a.at(j) % r.at(i) == 0) { test = 0; cv = r.at(i); } } } else { break; } } cout << cv << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a.at(i); } sort(a.begin(), a.end()); vector<long long> r(10000, 1); int count = 0; for (long long i = 1; i * i <= a.at(0); i++) { if (a.at(0) % i == 0) { r.at(2 * count) = i; r.at(2 * count + 1) = a.at(0) / i; count++; } } sort(r.begin(), r.end(), greater<long long>()); int test = 1; long long cv; for (int i = 0; i < r.size(); i++) { if (test == 1) { for (int j = 1; j < n; j++) { if (a.at(j) % r.at(i) != 0) { test = 1; break; } if (j == (n - 1) && a.at(j) % r.at(i) == 0) { test = 0; cv = r.at(i); } } } else { break; } } cout << cv << endl; }
replace
16
17
16
17
0
p03127
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) #define NIL -1 using namespace std; typedef long long ll; typedef long long int lli; static const int MOD = 10000007; static const int MAX = 100005; string s; int N; int gcd(int a, int b) { if (b > a) swap(a, b); int r = 1; while (r > 0) { r = a % b; a = b; b = r; } return a; } int main() { cin >> N; vector<int> A(N, 0); rep(i, N) { cin >> A[i]; } int minv = A[0]; rep(i, N) { for (int j = i + 1; j < N; j++) { int r = gcd(A[i], A[j]); if (minv > r) minv = r; } } cout << minv << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) #define NIL -1 using namespace std; typedef long long ll; typedef long long int lli; static const int MOD = 10000007; static const int MAX = 100005; string s; int N; int gcd(int a, int b) { if (b > a) swap(a, b); int r = 1; while (r > 0) { r = a % b; a = b; b = r; } return a; } int main() { cin >> N; vector<int> A(N, 0); rep(i, N) { cin >> A[i]; } int minv = A[0]; rep(i, N - 1) { minv = min(gcd(minv, A[i + 1]), minv); } cout << minv << endl; }
replace
43
50
43
44
TLE
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int lld; typedef unsigned long long int llu; #define rep(i, n) for (lld i = 0; i < n; i++) lld N; lld hp[10010]; int main() { cin >> N; rep(i, N) { scanf("%lld", &hp[i]); if (hp[i] == 1) { cout << 1 << endl; return 0; } } rep(i, N - 1) { lld big = hp[i]; lld little = hp[i + 1]; lld tmp; if (big < little) { tmp = big; big = little; little = tmp; } while (big % little != 0) { big %= little; tmp = big; big = little; little = tmp; } hp[i + 1] = little; if (hp[i + 1] == 1) { cout << 1 << endl; return 0; } } cout << hp[N - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int lld; typedef unsigned long long int llu; #define rep(i, n) for (lld i = 0; i < n; i++) lld N; lld hp[100010]; int main() { cin >> N; rep(i, N) { scanf("%lld", &hp[i]); if (hp[i] == 1) { cout << 1 << endl; return 0; } } rep(i, N - 1) { lld big = hp[i]; lld little = hp[i + 1]; lld tmp; if (big < little) { tmp = big; big = little; little = tmp; } while (big % little != 0) { big %= little; tmp = big; big = little; little = tmp; } hp[i + 1] = little; if (hp[i + 1] == 1) { cout << 1 << endl; return 0; } } cout << hp[N - 1] << endl; return 0; }
replace
10
11
10
11
0
p03127
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N, ans = 100000100; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; while (A.size() > 1) { sort(A.begin(), A.end()); if (A[A.size() - 1] % A[A.size() - 2] == 0) A.pop_back(); else A[A.size() - 1] %= A[A.size() - 2]; } cout << A[0] << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N, ans = 100000100; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); for (int i = 0; i < A.size() - 1; i++) { if (A[i + 1] % A[i] == 0) { A.erase(A.begin() + i + 1); i--; } else A[i + 1] %= A[i]; } sort(A.begin(), A.end()); int s = 1; while (s != A.size()) { if (A[s - 1] == A[s]) A.erase(A.begin() + s); else s++; } while (A.size() > 1) { sort(A.begin(), A.end()); if (A[A.size() - 1] % A[A.size() - 2] == 0) A.pop_back(); else A[A.size() - 1] %= A[A.size() - 2]; } cout << A[0] << endl; return 0; }
insert
12
12
12
28
TLE
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repl(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define reprl(i, n) for (ll i = n; i >= 0; i--) #define fori(i, m, n) for (int i = m; i < (int)n; i++) #define forl(i, m, n) for (ll i = m; i < (ll)n; i++) #define all(v) v.begin(), v.end() ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } bool isLowerCase(char c) { return (c >= 'a' && c <= 'z'); } const string yesno(bool ans) { return (ans ? "Yes" : "No"); } int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) { cin >> a[i]; } sort(all(a)); int idx = 0; while (idx < n - 1) { fori(i, 1, n) { a[i] %= a[idx]; } sort(all(a)); auto firstNonZero = upper_bound(all(a), 0); idx = firstNonZero - a.begin(); } std::cout << a[n - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repl(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define reprl(i, n) for (ll i = n; i >= 0; i--) #define fori(i, m, n) for (int i = m; i < (int)n; i++) #define forl(i, m, n) for (ll i = m; i < (ll)n; i++) #define all(v) v.begin(), v.end() ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } bool isLowerCase(char c) { return (c >= 'a' && c <= 'z'); } const string yesno(bool ans) { return (ans ? "Yes" : "No"); } int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) { cin >> a[i]; } sort(all(a)); int idx = 0; while (idx < n - 1) { fori(i, idx + 1, n) { a[i] %= a[idx]; } sort(all(a)); auto firstNonZero = upper_bound(all(a), 0); idx = firstNonZero - a.begin(); } std::cout << a[n - 1] << endl; return 0; }
replace
25
26
25
26
0
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 3005 #define REP(i, n) for (int i = 0; i < n; i++) long n; long a[10000]; long ans, en; long cou; long gcd(long i, long j) { if (i < j) { int tmp = i; i = j; j = tmp; } /* ユークリッドの互除法 */ long r = i % j; while (r != 0) { i = j; j = r; r = i % j; } return j; } int main() { cin >> n; REP(i, n) { cin >> a[i]; } sort(a, a + n); ans = gcd(a[0], a[1]); for (int i = 2; i < n; i++) { ans = gcd(a[0], a[i]); if (ans == 1) break; } printf("%ld", ans); }
#include <bits/stdc++.h> using namespace std; #define N 3005 #define REP(i, n) for (int i = 0; i < n; i++) long n; long a[100000]; long ans, en; long cou; long gcd(long i, long j) { if (i < j) { int tmp = i; i = j; j = tmp; } /* ユークリッドの互除法 */ long r = i % j; while (r != 0) { i = j; j = r; r = i % j; } return j; } int main() { cin >> n; REP(i, n) { cin >> a[i]; } sort(a, a + n); ans = gcd(a[0], a[1]); for (int i = 2; i < n; i++) { ans = gcd(a[0], a[i]); if (ans == 1) break; } printf("%ld", ans); }
replace
5
6
5
6
0
p03127
C++
Time Limit Exceeded
#include <iostream> using namespace std; int GCD(int x, int y) { int gcd; for (int i = 1; i <= x && i <= y; i++) { if (x % i == 0 && y % i == 0) gcd = i; } return gcd; } int main() { int N; int ans; cin >> N; N -= 2; int x, y; cin >> x >> y; ans = GCD(x, y); for (int i = 0; i < N; i++) { int A; cin >> A; ans = GCD(ans, A); } cout << ans; return 0; }
#include <iostream> using namespace std; int GCD(int x, int y) { if (y == 0) return x; return GCD(y, x % y); } int main() { int N; int ans; cin >> N; N -= 2; int x, y; cin >> x >> y; ans = GCD(x, y); for (int i = 0; i < N; i++) { int A; cin >> A; ans = GCD(ans, A); } cout << ans; return 0; }
replace
6
12
6
9
TLE
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { while (1) { int N; cin >> N; if (N == 0) break; vector<int> tairyoku(N); for (int i = 0; i < N; i++) cin >> tairyoku[N]; int gcds = 0; for (int i = 0; i < N; i++) gcds = gcd(gcds, tairyoku[i]); cout << gcds << endl; } }
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int main() { int N; cin >> N; vector<int> tairyoku(N); for (int i = 0; i < N; i++) cin >> tairyoku[i]; int gcds = 0; for (int i = 0; i < N; i++) gcds = gcd(gcds, tairyoku[i]); cout << gcds << endl; }
replace
9
22
9
18
TLE
p03127
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> int N, temp; std::vector<int> A; int main() { std::cin >> N; for (int i = 0; i < N; ++i) { std::cin >> temp; A.push_back(temp); } std::sort(A.begin(), A.end()); auto begin = A.begin(); auto next = std::next(begin); while (next != A.end() && *begin != 1) { *next = *next % *begin; if (*next < *begin) { temp = *next; *next = *begin; *begin = temp; } else if (*next == 0) { next++; } } std::cout << *begin << std::endl; }
#include <algorithm> #include <iostream> #include <vector> int N, temp; std::vector<int> A; int main() { std::cin >> N; for (int i = 0; i < N; ++i) { std::cin >> temp; A.push_back(temp); } std::sort(A.begin(), A.end()); auto begin = A.begin(); auto next = std::next(begin); while (next != A.end() && *begin != 1) { *next = *next % *begin; if (*next < *begin && *next != 0) { temp = *next; *next = *begin; *begin = temp; } else if (*next == 0) { next++; } } std::cout << *begin << std::endl; }
replace
21
22
21
22
-8
p03127
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int c; c = a % b; if (c == 0) return b; a = b; b = c; } int main() { int n, a[111111], i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; int ans = a[0]; for (i = 1; i < n; i++) ans = gcd(a[i], ans); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int c; while (1) { c = a % b; if (c == 0) return b; a = b; b = c; } } int main() { int n, a[111111], i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; int ans = a[0]; for (i = 1; i < n; i++) ans = gcd(a[i], ans); cout << ans << endl; }
replace
4
9
4
11
0
p03127
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> using namespace std; int main() { int N, A[100000]; int min; bool same_min = false; scanf("%d", &N); for (int i = 0; i < N; i++) scanf("%d", &A[i]); while (!same_min) { min = *min_element(A, &A[N]); for (int i = 0; i < N; i++) { if (A[i] != min) break; else if (i == N - 1 && A[i] == min) same_min = true; } for (int i = 0; i < N; i++) { while (A[i] > min) A[i] -= min; } } printf("%d\n", min); return 0; }
#include <algorithm> #include <cstdio> using namespace std; int main() { int N, A[100000]; int min; bool same_min = false; scanf("%d", &N); for (int i = 0; i < N; i++) scanf("%d", &A[i]); while (!same_min) { min = *min_element(A, &A[N]); for (int i = 0; i < N; i++) { if (A[i] != min) break; else if (i == N - 1 && A[i] == min) same_min = true; } for (int i = 0; i < N; i++) { if (A[i] > min) { A[i] = A[i] % min; if (A[i] == 0) A[i] = min; } } } printf("%d\n", min); return 0; }
replace
20
22
20
25
TLE
p03127
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; uint64_t gcd(uint64_t u, uint64_t v) { while (v != 0) { uint64_t r = u % v; u = v; v = r; } return u; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a.begin(), a.end()); for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { int g = gcd(a[i], a[j]); a[i] = gcd(a[i], g); } } int ans = INT_MAX; for (int i = 0; i < n; ++i) { ans = min(ans, a[i]); } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; uint64_t gcd(uint64_t u, uint64_t v) { while (v != 0) { uint64_t r = u % v; u = v; v = r; } return u; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int ans = gcd(a[0], a[1]); for (int i = 1; i < n; ++i) { ans = gcd(ans, a[i]); } cout << ans << "\n"; }
replace
21
31
21
24
TLE
p03127
Python
Runtime Error
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from math import gcd from functools import reduce def solve(string): n, *a = map(int, string.split()) return str(reduce(gcd, a)) if __name__ == "__main__": print(solve("\n".join([input(), input()])))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from fractions import gcd from functools import reduce def solve(string): n, *a = map(int, string.split()) return str(reduce(gcd, a)) if __name__ == "__main__": print(solve("\n".join([input(), input()])))
replace
3
4
3
4
0
p03127
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); int enemy_min = A[0]; int enemy_next = A[1]; int i = 0; while (1) { A[i + 1] = A[i + 1] - A[i]; if (A[i + 1] < A[i]) { int tmp; tmp = A[i]; A[i] = A[i + 1]; A[i + 1] = tmp; } if (A[i] < 1) { i++; } if (A[N - 2] == 0) { break; } } cout << A[N - 1] << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); int enemy_min = A[0]; int enemy_next = A[1]; int i = 0; while (1) { A[i + 1] = A[i + 1] % A[i]; if (A[i + 1] < A[i]) { int tmp; tmp = A[i]; A[i] = A[i + 1]; A[i + 1] = tmp; } if (A[i] < 1) { i++; } if (A[N - 2] == 0) { break; } } cout << A[N - 1] << endl; return 0; }
replace
20
21
20
21
TLE
p03127
Python
Runtime Error
from math import gcd n = int(input()) A = list(map(int, input().split())) ans = A[0] for a in A[1:]: ans = gcd(ans, a) print(ans)
from fractions import gcd n = int(input()) A = list(map(int, input().split())) ans = A[0] for a in A[1:]: ans = gcd(ans, a) print(ans)
replace
0
1
0
1
0
p03127
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split())) a.sort() while len(a) >= 2: k = a[1] % a[0] if k == 0: a.pop(1) else: a[1] = k a.sort() if a[0] == 1: break print(a[0])
n = int(input()) a = list(map(int, input().split())) a.sort() while len(a) >= 2: k = a[1] % a[0] if k == 0: a.pop(1) else: a[1] = k a[0], a[1] = a[1], a[0] print(a[0])
replace
9
12
9
10
TLE
p03127
Python
Runtime Error
from math import gcd N = int(input()) A = sorted([int(n) for n in input().split()], reverse=True) x = A[0] for i in range(1, N): x = gcd(x, A[i]) print(x)
from fractions import gcd N = int(input()) A = sorted([int(n) for n in input().split()], reverse=True) x = A[0] for i in range(1, N): x = gcd(x, A[i]) print(x)
replace
0
1
0
1
0
p03127
Python
Runtime Error
import sys readline = sys.stdin.buffer.readline def sss(A, N): A.sort() if A[0] == 0: A.remove(0) for i in range(1, len(A)): A[i] = A[i] % A[0] if A[0] == sum(A): print(sum(A)) else: return sss(A, N) def main(): N = int(readline()) A = list(map(int, readline().split())) sss(A, N) main()
import sys readline = sys.stdin.buffer.readline def sss(A, N): A.sort() while A[0] == 0: A.remove(0) for i in range(1, len(A)): A[i] = A[i] % A[0] if A[0] == sum(A): print(sum(A)) else: return sss(A, N) def main(): N = int(readline()) A = list(map(int, readline().split())) sss(A, N) main()
replace
7
8
7
8
0
p03127
Python
Time Limit Exceeded
# -*- coding: utf-8 -*- N = map(int, input()) A = list(map(int, input().split())) while len(A) >= 2: x = A.pop(A.index(max(A))) y = min(A) n = x % y if n == 0: pass else: A.append(n) print(A[0])
# -*- coding: utf-8 -*- N = map(int, input()) A = list(map(int, input().split())) while len(A) >= 2: idx = A.index(min(A)) x = A.pop(idx) B = list() for i in range(len(A)): if A[i] % x != 0: B.append(A[i] % x) B.append(x) A = B[:] print(A[0])
replace
5
12
5
13
TLE
p03127
Python
Runtime Error
from functools import reduce from math import gcd if __name__ == "__main__": n = int(input()) a = [int(s) for s in input().split()] print(reduce(gcd, a))
from functools import reduce def gcd(a, b): if b == 0: return a return gcd(b, a % b) if __name__ == "__main__": n = int(input()) a = [int(s) for s in input().split()] print(reduce(gcd, a))
replace
1
2
1
8
0
p03127
Python
Runtime Error
from math import gcd N = int(input()) A = [int(x) for x in input().split()] ans = A[0] for i in range(1, N): ans = gcd(ans, A[i]) print(ans)
def gcd(a, b): if b == 0: return a return gcd(b, a % b) N = int(input()) A = [int(x) for x in input().split()] ans = A[0] for i in range(1, N): ans = gcd(ans, A[i]) print(ans)
replace
0
1
0
5
0
p03127
Python
Runtime Error
import sys sys.setrecursionlimit(20000) def inpl(): return list(map(int, input().split())) def gcd(a, b): la = max(a, b) sm = min(a, b) if la % sm == 0: return sm else: return gcd(sm, la - sm) n = int(input()) A = inpl() ans = gcd(A[0], A[1]) for a in A: ans = gcd(ans, a) print(ans)
import sys sys.setrecursionlimit(20000) def inpl(): return list(map(int, input().split())) def gcd(a, b): la = max(a, b) sm = min(a, b) if la % sm == 0: return sm else: return gcd(sm, la - sm) n = int(input()) A = inpl() A.sort() ans = gcd(A[0], A[1]) for a in A: ans = gcd(ans, a) print(ans)
replace
20
21
20
21
0
p03127
Python
Runtime Error
from functools import reduce from functools import gcd N = int(input()) A = [int(i) for i in input().split()] print(reduce(gcd, A))
from functools import reduce from fractions import gcd N = int(input()) A = [int(i) for i in input().split()] print(reduce(gcd, A))
replace
1
2
1
2
ImportError: cannot import name 'gcd' from 'functools' (/usr/lib/python3.10/functools.py)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03127/Python/s208362126.py", line 2, in <module> from functools import gcd ImportError: cannot import name 'gcd' from 'functools' (/usr/lib/python3.10/functools.py)
p03127
Python
Time Limit Exceeded
N = int(input()) A = list(map(int, input().split())) while True: if len(A) == 1: break max_i = A.index(max(A)) min_i = A.index(min(A)) life = A[max_i] % A[min_i] if life == 0: A.pop(max_i) else: A[max_i] = life print(A[0])
N = int(input()) A = list(map(int, input().split())) while True: if len(A) == 1: break pop_i = [] A.sort() for i in range(1, len(A)): life = A[i] % A[0] if life == 1: print(life) exit() else: A[i] = life A = [n for n in A if n > 0] print(A[0])
replace
6
13
6
16
TLE
p03128
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, x) for (int i = 0; i < x; i++) #define pb push_back #define mp make_pair typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; const ll N = 1e9 + 7; const int n_max = 1e5 + 10; const vi num = {2, 5, 5, 4, 5, 6, 3, 7, 6}; int main() { int n, m; cin >> n >> m; vi a(m); rep(i, m) { cin >> a.at(i); a.at(i)--; } vi dp(n + 1, 0); rep(i, n + 1) { rep(j, m) { if (i < num.at(a.at(j))) continue; dp.at(i) = max(dp.at(i), dp.at(i - num.at(a.at(j))) + 1); } } // rep(i,dp.size())cout << dp.at(i) << " "; // cout << endl; vi ans; sort(a.begin(), a.end(), greater<int>()); int count = n; while (0 < count) { rep(j, m) { if (count < num.at(a.at(j))) continue; if (dp.at(count) == 1) { if (count != num.at(a.at(j))) continue; } if (dp.at(count) == dp.at(count - num.at(a.at(j))) + 1) { ans.pb(a.at(j) + 1); // cout << count << " " << a.at(j) + 1 << endl; count -= num.at(a.at(j)); break; } } } rep(i, ans.size()) cout << ans.at(i); cout << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define rep(i, x) for (int i = 0; i < x; i++) #define pb push_back #define mp make_pair typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; const ll N = 1e9 + 7; const int n_max = 1e5 + 10; const vi num = {2, 5, 5, 4, 5, 6, 3, 7, 6}; int main() { int n, m; cin >> n >> m; vi a(m); rep(i, m) { cin >> a.at(i); a.at(i)--; } vi dp(n + 1, -INT_MAX); dp.at(0) = 0; rep(i, n + 1) { rep(j, m) { if (i < num.at(a.at(j))) continue; dp.at(i) = max(dp.at(i), dp.at(i - num.at(a.at(j))) + 1); } } // rep(i,dp.size())cout << dp.at(i) << " "; // cout << endl; vi ans; sort(a.begin(), a.end(), greater<int>()); int count = n; while (0 < count) { rep(j, m) { if (count < num.at(a.at(j))) continue; if (dp.at(count) == 1) { if (count != num.at(a.at(j))) continue; } if (dp.at(count) == dp.at(count - num.at(a.at(j))) + 1) { ans.pb(a.at(j) + 1); // cout << count << " " << a.at(j) + 1 << endl; count -= num.at(a.at(j)); break; } } } rep(i, ans.size()) cout << ans.at(i); cout << endl; return 0; }
replace
31
32
31
33
TLE
p03128
C++
Runtime Error
#include <bits/stdc++.h> #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 all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long int; 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; } const ll INF = 1e11; const ll MOD = 1000000007; typedef pair<int, int> P; ll match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; string big(string s, string t) { string res = ""; rep(i, s.length()) { if (s[i] - '0' > t[i] - '0') { res = s; break; } else if (s[i] - '0' < t[i] - '0') { res = t; break; } } if (res == "") res = s; return res; } int main() { ll n, m, a; cin >> n >> m; ll num[9] = {0}; rep(i, m) { cin >> a; chmax(num[match[a]], a); } string s[2005]; string c; ll l; s[0] = ""; rep(i, n) { l = s[i].length() + 1; if (i != 0 && s[i] == "") continue; rep(j, 2, 8) { if (num[j] != 0) { if (i == 0 || num[j] < s[i][0] - '0') { c = s[i] + (char)(num[j] + '0'); } else c = (char)(num[j] + '0') + s[i]; // PRINT(i+j << " " << c << " " << s[i+j]); if (l > s[i + j].length()) s[i + j] = c; else if (l == s[i + j].length()) s[i + j] = big(s[i + j], c); } } } PRINT(s[n]); }
#include <bits/stdc++.h> #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 all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long int; 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; } const ll INF = 1e11; const ll MOD = 1000000007; typedef pair<int, int> P; ll match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; string big(string s, string t) { string res = ""; rep(i, s.length()) { if (s[i] - '0' > t[i] - '0') { res = s; break; } else if (s[i] - '0' < t[i] - '0') { res = t; break; } } if (res == "") res = s; return res; } int main() { ll n, m, a; cin >> n >> m; ll num[9] = {0}; rep(i, m) { cin >> a; chmax(num[match[a]], a); } string s[20005]; string c; ll l; s[0] = ""; rep(i, n) { l = s[i].length() + 1; if (i != 0 && s[i] == "") continue; rep(j, 2, 8) { if (num[j] != 0) { if (i == 0 || num[j] < s[i][0] - '0') { c = s[i] + (char)(num[j] + '0'); } else c = (char)(num[j] + '0') + s[i]; // PRINT(i+j << " " << c << " " << s[i+j]); if (l > s[i + j].length()) s[i + j] = c; else if (l == s[i + j].length()) s[i + j] = big(s[i + j], c); } } } PRINT(s[n]); }
replace
52
53
52
53
0
p03128
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <utility> #include <vector> using namespace std; // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " "; #define END cout << endl; #else #define DEB(X) \ {} #define ARDEB(i, X) \ {} #define END \ {} #endif typedef long long int ll; #define int long long typedef pair<int, int> P; struct edge { int to, cost; }; #define REP(i, n) for (int i = 0; i < (n); i++) const int INF = 100000000000000000; int N, M; int A[1010]; int V[11] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; string dp[1010]; bool F[1010]; string comp(string s, string t) { if (s.size() > t.size()) { return s; } else if (s.size() < t.size()) { return t; } else { if (s > t) { return s; } else { return t; } } } string DP(int a) { string res; vector<string> v, v2; if (F[a] != false) { return dp[a]; } if (a >= N) { if (a == N) { return "s"; } else { return "!"; } } REP(i, M) { string s; s = DP(a + V[A[i] - 1]) + to_string(A[i]); bool flag = false; REP(j, s.size()) { if (s[j] == '!') { flag = true; } } if (flag != true) { v.push_back(s); } } REP(i, v.size()) { if (comp(res, v[i]) == v[i]) { res = v[i]; } } F[a] = true; return dp[a] = res; } signed main() { cin >> N >> M; REP(i, M) { cin >> A[i]; } string ans = DP(0); string ans2; REP(i, ans.size()) { if (ans[i] != 's') { ans2 += ans[i]; } } cout << ans2 << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_set> #include <utility> #include <vector> using namespace std; // #define MODE 1 #ifdef MODE #define DEB(X) cout << #X << ": " << X << " "; #define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " "; #define END cout << endl; #else #define DEB(X) \ {} #define ARDEB(i, X) \ {} #define END \ {} #endif typedef long long int ll; #define int long long typedef pair<int, int> P; struct edge { int to, cost; }; #define REP(i, n) for (int i = 0; i < (n); i++) const int INF = 100000000000000000; int N, M; int A[1010]; int V[11] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; string dp[1000000]; bool F[1000000]; string comp(string s, string t) { if (s.size() > t.size()) { return s; } else if (s.size() < t.size()) { return t; } else { if (s > t) { return s; } else { return t; } } } string DP(int a) { string res; vector<string> v, v2; if (F[a] != false) { return dp[a]; } if (a >= N) { if (a == N) { return "s"; } else { return "!"; } } REP(i, M) { string s; s = DP(a + V[A[i] - 1]) + to_string(A[i]); bool flag = false; REP(j, s.size()) { if (s[j] == '!') { flag = true; } } if (flag != true) { v.push_back(s); } } REP(i, v.size()) { if (comp(res, v[i]) == v[i]) { res = v[i]; } } F[a] = true; return dp[a] = res; } signed main() { cin >> N >> M; REP(i, M) { cin >> A[i]; } string ans = DP(0); string ans2; REP(i, ans.size()) { if (ans[i] != 's') { ans2 += ans[i]; } } cout << ans2 << endl; return 0; }
replace
40
42
40
42
0
p03128
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; 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; } const ll INF = 1e18; int main() { ll n, m; ll d[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; cin >> n >> m; vector<pll> a(m); rep(i, m) { cin >> a[i].fi; a[i].se = d[a[i].fi - 1]; } sort(a.rbegin(), a.rend()); vector<ll> dp(n + 1, -1); dp[0] = 0; rep(i, n + 1) { if (dp[i] != -1) { rep(j, m) { if (i + a[i].se <= n) { dp[i + a[j].se] = max(dp[i + a[j].se], dp[i] + 1); } } } } ll match = n, remain = dp[n]; string ans = ""; while (match > 0) { rep(i, m) { if (match >= a[i].se && dp[match - a[i].se] == remain - 1) { match -= a[i].se; remain--; string c = to_string(a[i].fi); ans += c; break; } } } cout << ans << endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; 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; } const ll INF = 1e18; int main() { ll n, m; ll d[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; cin >> n >> m; vector<pll> a(m); rep(i, m) { cin >> a[i].fi; a[i].se = d[a[i].fi - 1]; } sort(a.rbegin(), a.rend()); vector<ll> dp(n + 1, -1); dp[0] = 0; rep(i, n + 1) { if (dp[i] != -1) { rep(j, m) { if (i + a[j].se <= n) { dp[i + a[j].se] = max(dp[i + a[j].se], dp[i] + 1); } } } } ll match = n, remain = dp[n]; string ans = ""; while (match > 0) { rep(i, m) { if (match >= a[i].se && dp[match - a[i].se] == remain - 1) { match -= a[i].se; remain--; string c = to_string(a[i].fi); ans += c; break; } } } cout << ans << endl; return 0; }
replace
48
49
48
49
0
p03128
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, x, n) for (int i = x; i < n; i++) int main() { int num[10]; num[1] = 2, num[2] = 5, num[3] = 5, num[4] = 4, num[5] = 5; num[6] = 6, num[7] = 3, num[8] = 7, num[9] = 6; int N, M; cin >> N >> M; int A[M]; rep(i, M) { cin >> A[i]; } long long dp[N + 1]; dp[0] = 0; rep2(i, 1, N + 1) { long long ans = -10000000000; rep(j, M) { int k = i - num[A[j]]; if (k >= 0) { ans = max(ans, dp[k] + 1); } } dp[i] = ans; } sort(A, A + M, greater<int>()); long long n = dp[N - 1]; long long x = N; int res[n]; while (n > 0) { rep(i, M) { if (dp[x - num[A[i]]] == n - 1) { x -= num[A[i]]; n--; res[n] = A[i]; break; } } } for (int i = dp[N] - 1; i >= 0; i--) { cout << res[i]; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, x, n) for (int i = x; i < n; i++) int main() { int num[10]; num[1] = 2, num[2] = 5, num[3] = 5, num[4] = 4, num[5] = 5; num[6] = 6, num[7] = 3, num[8] = 7, num[9] = 6; int N, M; cin >> N >> M; int A[M]; rep(i, M) { cin >> A[i]; } long long dp[N + 1]; dp[0] = 0; rep2(i, 1, N + 1) { long long ans = -10000000000; rep(j, M) { int k = i - num[A[j]]; if (k >= 0) { ans = max(ans, dp[k] + 1); } } dp[i] = ans; } sort(A, A + M, greater<int>()); long long n = dp[N]; long long x = N; int res[n]; while (n > 0) { rep(i, M) { if (dp[x - num[A[i]]] == n - 1) { x -= num[A[i]]; n--; res[n] = A[i]; break; } } } for (int i = dp[N] - 1; i >= 0; i--) { cout << res[i]; } }
replace
26
27
26
27
0
p03128
C++
Time Limit Exceeded
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { int n, m; cin >> n >> m; vector<int> a(m); for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a.rbegin(), a.rend()); vector<int> num = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vector<int> digit(5010, -1000000); digit[0] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < m; j++) { int from = i - num[a[j]]; if (from < 0) continue; digit[i] = max(digit[i], digit[from] + 1); } } while (n > 0) { for (int i = 0; i < m; i++) { if (n - num[a[i]] < 0) continue; if (digit[n - num[a[i]]] == (digit[n] - 1)) { cout << a[i]; n -= num[a[i]]; break; } } } cout << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { int n, m; cin >> n >> m; vector<int> a(m); for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a.rbegin(), a.rend()); vector<int> num = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vector<int> digit(n + 1, -1000000); digit[0] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < m; j++) { int from = i - num[a[j]]; if (from < 0) continue; digit[i] = max(digit[i], digit[from] + 1); } } while (n > 0) { for (int i = 0; i < m; i++) { if (n - num[a[i]] < 0) continue; if (digit[n - num[a[i]]] == (digit[n] - 1)) { cout << a[i]; n -= num[a[i]]; break; } } } cout << endl; return 0; }
replace
95
96
95
96
TLE
p03128
C++
Time Limit Exceeded
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { int n, m; cin >> n >> m; vector<int> a(m); for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a.rbegin(), a.rend()); vector<int> num = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vector<int> digit(5001, -1000000); digit[0] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < m; j++) { int from = i - num[a[j]]; if (from < 0) continue; digit[i] = max(digit[i], digit[from] + 1); } } while (n > 0) { for (int i = 0; i < m; i++) { if (n - num[a[i]] < 0) continue; if (digit[n - num[a[i]]] == (digit[n] - 1)) { cout << a[i]; n -= num[a[i]]; break; } } } cout << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { int n, m; cin >> n >> m; vector<int> a(m); for (int i = 0; i < m; i++) { cin >> a[i]; } sort(a.rbegin(), a.rend()); vector<int> num = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vector<LL> digit(10000, -1000000); digit[0] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < m; j++) { int from = i - num[a[j]]; if (from < 0) continue; digit[i] = max(digit[i], digit[from] + 1); } } while (n > 0) { for (int i = 0; i < m; i++) { if (n - num[a[i]] < 0) continue; if (digit[n - num[a[i]]] == (digit[n] - 1)) { cout << a[i]; n -= num[a[i]]; break; } } } cout << endl; return 0; }
replace
95
96
95
96
TLE
p03128
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #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, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v, n) reverse(v, v + n); #define VREVERSE(v) reverse(v.begin(), v.end()); #define ll long long #define pb(a) push_back(a) #define INF 9999999999 #define m0(x) memset(x, 0, sizeof(x)) #define fill(x, y) memset(x, y, sizeof(x)) #define print(x) cout << x << endl; #define pe(x) cout << x << " "; #define lb(v, n) lower_bound(v.begin(), v.end(), n); // #define int long long using namespace std; 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; } int dy[4] = {0, 0, 1, -1}; int dx[4] = {1, -1, 0, 0}; int dxx[9] = {0, 0, 0, 1, 1, 1, -1, -1, -1}; int dyy[9] = {0, 1, -1, 0, 1, -1, 0, 1, -1}; ll gcd(ll x, ll y) { ll m = max(x, y), n = min(x, y); if (m % n == 0) return n; else return gcd(m % n, n); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } long long power_mod(long long x, long long n, long long m) { if (n == 0) return 1; if (n % 2 == 0) return power_mod(x * x % m, n / 2, m); else return x * power_mod(x, n - 1, m) % m; } long long power(long long a, long long n) { // aのn乗を計算します。 long long x = 1; while (n > 0) { // 全てのbitが捨てられるまで。 if (n & 1) { // 1番右のbitが1のとき。 x = x * a; } a = a * a; n >>= 1; // bit全体を右に1つシフトして一番右を捨てる。 } return x; } long long nCr(long long n, long long r) { if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r) long long ans = 1; long long i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } const int MAX = 510000; const int MOD = 1000000007; 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; } bool arr[100000100]; vector<ll> sosuu; void Eratosthenes() { ll N = 10000010; int c = 0; for (int i = 0; i < N; i++) { arr[i] = 1; } for (ll i = 2; i < sqrt(N); i++) { if (arr[i]) { for (ll j = 0; i * (j + 2) < N; j++) { arr[i * (j + 2)] = 0; } } } for (ll i = 2; i < N; i++) { if (arr[i]) { sosuu.pb(i); // cout << sosuu[c] << " "; c++; } } // cout << endl; // cout << c << endl; } ll stoL(string s) { ll n = s.length(); ll ans = 0; for (int i = 0; i < n; i++) { ans += power(10, n - i - 1) * (ll)(s[i] - '0'); } return ans; } bool comp(string x, string y) { if (x.length() > y.length()) return true; else if (x.length() < y.length()) return false; else return x > y; } int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int A[10]; string dp[10010]; int main() { int N, M; cin >> N >> M; REP(i, M) cin >> A[i]; REP(i, 10010) dp[i] = "0"; dp[0] = ""; FOR(i, 1, N + 1) { REP(j, M) { if (i - num[A[j]] < 0) continue; if (dp[i - num[A[j]]] != "0") { if (comp(dp[i - num[A[j]]] + to_string(A[j]), dp[i])) dp[i] = dp[i - A[j]] + to_string(A[j]); } } } // REP(i, N + 1)print(dp[i]); print(dp[N]); }
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #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, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v, n) reverse(v, v + n); #define VREVERSE(v) reverse(v.begin(), v.end()); #define ll long long #define pb(a) push_back(a) #define INF 9999999999 #define m0(x) memset(x, 0, sizeof(x)) #define fill(x, y) memset(x, y, sizeof(x)) #define print(x) cout << x << endl; #define pe(x) cout << x << " "; #define lb(v, n) lower_bound(v.begin(), v.end(), n); // #define int long long using namespace std; 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; } int dy[4] = {0, 0, 1, -1}; int dx[4] = {1, -1, 0, 0}; int dxx[9] = {0, 0, 0, 1, 1, 1, -1, -1, -1}; int dyy[9] = {0, 1, -1, 0, 1, -1, 0, 1, -1}; ll gcd(ll x, ll y) { ll m = max(x, y), n = min(x, y); if (m % n == 0) return n; else return gcd(m % n, n); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } long long power_mod(long long x, long long n, long long m) { if (n == 0) return 1; if (n % 2 == 0) return power_mod(x * x % m, n / 2, m); else return x * power_mod(x, n - 1, m) % m; } long long power(long long a, long long n) { // aのn乗を計算します。 long long x = 1; while (n > 0) { // 全てのbitが捨てられるまで。 if (n & 1) { // 1番右のbitが1のとき。 x = x * a; } a = a * a; n >>= 1; // bit全体を右に1つシフトして一番右を捨てる。 } return x; } long long nCr(long long n, long long r) { if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r) long long ans = 1; long long i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } const int MAX = 510000; const int MOD = 1000000007; 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; } bool arr[100000100]; vector<ll> sosuu; void Eratosthenes() { ll N = 10000010; int c = 0; for (int i = 0; i < N; i++) { arr[i] = 1; } for (ll i = 2; i < sqrt(N); i++) { if (arr[i]) { for (ll j = 0; i * (j + 2) < N; j++) { arr[i * (j + 2)] = 0; } } } for (ll i = 2; i < N; i++) { if (arr[i]) { sosuu.pb(i); // cout << sosuu[c] << " "; c++; } } // cout << endl; // cout << c << endl; } ll stoL(string s) { ll n = s.length(); ll ans = 0; for (int i = 0; i < n; i++) { ans += power(10, n - i - 1) * (ll)(s[i] - '0'); } return ans; } bool comp(string x, string y) { if (x.length() > y.length()) return true; else if (x.length() < y.length()) return false; else return x > y; } int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int A[10]; string dp[10010]; int main() { int N, M; cin >> N >> M; REP(i, M) cin >> A[i]; REP(i, 10010) dp[i] = "0"; dp[0] = ""; FOR(i, 1, N + 1) { REP(j, M) { if (i - num[A[j]] < 0) continue; if (dp[i - num[A[j]]] != "0") { if (comp(dp[i - num[A[j]]] + to_string(A[j]), dp[i])) dp[i] = dp[i - num[A[j]]] + to_string(A[j]); } } } // REP(i, N + 1)print(dp[i]); print(dp[N]); }
replace
184
185
184
185
-11
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 - 1; i >= 0; i--) #define rep2(i, s, n) for (int i = s; i < n; ++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; 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 int inf = 1001001001; const ll linf = 1001001001001001001; bool dp[5100][10100]; int main() { int n, m; cin >> n >> m; vector<int> ex(8, 0); rep(i, m) { int a; cin >> a; int b; if (a == 1) b = 2; else if (a == 7) b = 3; else if (a == 4) b = 4; else if (a == 2 || a == 3 || a == 5) b = 5; else if (a == 6 || a == 9) b = 6; else b = 7; chmax(ex[b], a); } rep(i, 5100) rep(j, 10100) dp[i][j] = false; dp[0][0] = true; rep(i, 5099) { rep(j, n + 1) { if (!dp[i][j]) continue; rep2(k, 2, 7) if (ex[k] > 0) { dp[i + 1][j + k] = true; } } } int mx; rrep(i, 5100) { if (dp[i][n]) { mx = i + 1; break; } } int now = n; for (int i = mx - 1; i > 0; i--) { int can = 0; int use; rep2(j, 2, min(8, now + 1)) { if (ex[j] > can && dp[i - 1][now - j]) { can = ex[j]; use = j; } } now -= use; cout << can; } cout << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rep2(i, s, n) for (int i = s; i < n; ++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; 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 int inf = 1001001001; const ll linf = 1001001001001001001; bool dp[5100][10100]; int main() { int n, m; cin >> n >> m; vector<int> ex(8, 0); rep(i, m) { int a; cin >> a; int b; if (a == 1) b = 2; else if (a == 7) b = 3; else if (a == 4) b = 4; else if (a == 2 || a == 3 || a == 5) b = 5; else if (a == 6 || a == 9) b = 6; else b = 7; chmax(ex[b], a); } rep(i, 5100) rep(j, 10100) dp[i][j] = false; dp[0][0] = true; rep(i, 5099) { rep(j, n + 1) { if (!dp[i][j]) continue; rep2(k, 2, 8) if (ex[k] > 0) { dp[i + 1][j + k] = true; } } } int mx; rrep(i, 5100) { if (dp[i][n]) { mx = i + 1; break; } } int now = n; for (int i = mx - 1; i > 0; i--) { int can = 0; int use; rep2(j, 2, min(8, now + 1)) { if (ex[j] > can && dp[i - 1][now - j]) { can = ex[j]; use = j; } } now -= use; cout << can; } cout << endl; }
replace
60
61
60
61
0
p03128
C++
Runtime Error
#include <algorithm> #include <bitset> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; typedef complex<double> C; #define cx real() #define cy imag() const ll INF = 1LL << 60; const double DINF = 1e30; const ll mod = 1000000007; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const C I = C(0, 1); const double EPS = 1e-10; const ll NCK_MAX = 510000; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_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; } } ll nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } template <typename T> class Zip { vector<T> d; bool flag; public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { // T need to have operator < !! if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return (ll)d.size(); } }; /**** Union Find ****/ class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: void init(ll n) { par.resize(n, 1); rank.resize(n, 0); } ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; template <typename T> class SegmentTree { ll n; vector<T> node; function<T(T, T)> fun, fun2; bool customChange; T outValue, initValue; public: void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) { // changeFunction: (input, beforevalue) => newvalue fun = resultFunction; fun2 = changeFunction; customChange = changeFunction != NULL; n = 1; while (n < num) n *= 2; node.resize(2 * n - 1, init); outValue = out; initValue = init; } void valueChange(ll num, T value) { num += n - 1; if (customChange) node[num] = fun2(value, node[num]); else node[num] = value; while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]); } T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b) if (r == -1) r = n; if (a <= l && r <= b) return node[k]; if (b <= l || r <= a) return outValue; ll mid = (l + r) / 2; return fun(rangeQuery(a, b, l, mid, 2 * k + 1), rangeQuery(a, b, mid, r, 2 * k + 2)); } }; ll n, m, a[10], d[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; string dp[1010]; bool cmp(const string &a, const string &b) { if (a.length() == b.length()) return a < b; return a.length() < b.length(); } int main() { scanf("%lld%lld", &n, &m); for (ll i = 0; i < m; i++) scanf("%lld", &a[i]); for (ll i = 0; i <= n; i++) dp[i] = ""; for (ll i = 0; i < n; i++) { if (i != 0 && dp[i] == "") continue; for (ll j = 0; j < m; j++) dp[i + d[a[j]]] = max(dp[i + d[a[j]]], dp[i] + to_string(a[j]), cmp); } cout << dp[n] << endl; }
#include <algorithm> #include <bitset> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; typedef complex<double> C; #define cx real() #define cy imag() const ll INF = 1LL << 60; const double DINF = 1e30; const ll mod = 1000000007; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const C I = C(0, 1); const double EPS = 1e-10; const ll NCK_MAX = 510000; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_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; } } ll nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } template <typename T> class Zip { vector<T> d; bool flag; public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { // T need to have operator < !! if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return (ll)d.size(); } }; /**** Union Find ****/ class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: void init(ll n) { par.resize(n, 1); rank.resize(n, 0); } ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; template <typename T> class SegmentTree { ll n; vector<T> node; function<T(T, T)> fun, fun2; bool customChange; T outValue, initValue; public: void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) { // changeFunction: (input, beforevalue) => newvalue fun = resultFunction; fun2 = changeFunction; customChange = changeFunction != NULL; n = 1; while (n < num) n *= 2; node.resize(2 * n - 1, init); outValue = out; initValue = init; } void valueChange(ll num, T value) { num += n - 1; if (customChange) node[num] = fun2(value, node[num]); else node[num] = value; while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]); } T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b) if (r == -1) r = n; if (a <= l && r <= b) return node[k]; if (b <= l || r <= a) return outValue; ll mid = (l + r) / 2; return fun(rangeQuery(a, b, l, mid, 2 * k + 1), rangeQuery(a, b, mid, r, 2 * k + 2)); } }; ll n, m, a[10], d[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; string dp[10010]; bool cmp(const string &a, const string &b) { if (a.length() == b.length()) return a < b; return a.length() < b.length(); } int main() { scanf("%lld%lld", &n, &m); for (ll i = 0; i < m; i++) scanf("%lld", &a[i]); for (ll i = 0; i <= n; i++) dp[i] = ""; for (ll i = 0; i < n; i++) { if (i != 0 && dp[i] == "") continue; for (ll j = 0; j < m; j++) dp[i + d[a[j]]] = max(dp[i + d[a[j]]], dp[i] + to_string(a[j]), cmp); } cout << dp[n] << endl; }
replace
190
191
190
191
0
p03128
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; /* macro */ #define rep(i, a, b) for (int i = a; i < b; i++) #define revrep(i, a, b) for (int i = a; i > b; i--) #define int long long #define exist(s, e) ((s).find(e) != (s).end()) #define all(v) (v).begin(), (v).end() #define each(s, itr) for (auto(itr) = s.begin(); (itr) != s.end(); (itr)++) #define sum(v) accumulate(all(v), (0LL)) #define isin(a, b, c) (b <= a && a <= c) #define println cout << "\n"; #define sz(v) (int)v.size() /* alias */ template <class T> using vec = vector<T>; typedef vector<int> vi; typedef pair<int, int> pi; typedef tuple<int, int, int> ti; typedef map<int, int> mi; typedef set<int> si; /* constant */ const int inf = 1LL << 62; const int mod = 1e9 + 7; const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1}; const int dy[8] = {0, 1, 0, -1, -1, -1, 1, 1}; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; /* io_method */ int input() { int tmp; cin >> tmp; return tmp; } string raw_input() { string tmp; cin >> tmp; return tmp; } template <class T> void printx(T n) { cout << n; } template <class T, class U> void printx(pair<T, U> p) { cout << "(" << p.first << "," << p.second << ")"; } template <class T, class U, class V> void printx(tuple<T, U, V> t) { cout << "{" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << "}" << endl; } template <class T> void printx(vector<T> v) { cout << "{"; rep(i, 0, v.size()) { printx(v[i]); if (i != v.size() - 1) printx(","); } cout << "}"; } template <class T> void print(T n) { printx(n); cout << endl; } template <class T> void print(set<T> s) { cout << "{"; each(s, e) { if (e != s.begin()) printx(","); printx(*e); } cout << "}" << endl; } template <class T, class U> void print(map<T, U> mp) { cout << "{"; each(mp, e) { cout << "(" << e->first << "," << e->second << ")"; } cout << "}" << endl; } template <class T> void printans(vec<T> v) { rep(i, 0, sz(v)) { cout << v[i] << (i == sz(v) - 1 ? "" : " "); } cout << endl; } /* general_method */ 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 <class T> T cut(T &a, int l, int r) { return T(a.begin() + l, a.begin() + r); } /* main */ int n, m; si arr; int need[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; void in() { cin >> n >> m; rep(i, 0, m) arr.insert(input()); } bool isbig(string a, string b) { if (sz(a) < sz(b)) return true; else if (sz(a) == sz(b)) { rep(i, 0, sz(a)) { if (a[i] > b[i]) return false; if (a[i] < b[i]) return true; } return false; } else { return false; } } string dp[10010]; string dfs(int rest) { if (rest == 0) return "&"; if (rest < 0) return "$"; if (dp[rest] != "-1") return dp[rest]; string ans = ""; rep(i, 1, 10) { if (exist(arr, i)) { string tmp = dfs(rest - need[i]); if (tmp.back() == '$') continue; if (isbig(ans, to_string(i) + tmp)) { ans = to_string(i) + tmp; } } } return dp[rest] = ans; } void solve() { rep(i, 0, 1010) dp[i] = "-1"; string ans = dfs(n); print(cut(ans, 0, sz(ans) - 1)); } signed main() { cin.tie(0); ios::sync_with_stdio(false); in(); solve(); }
#include "bits/stdc++.h" using namespace std; /* macro */ #define rep(i, a, b) for (int i = a; i < b; i++) #define revrep(i, a, b) for (int i = a; i > b; i--) #define int long long #define exist(s, e) ((s).find(e) != (s).end()) #define all(v) (v).begin(), (v).end() #define each(s, itr) for (auto(itr) = s.begin(); (itr) != s.end(); (itr)++) #define sum(v) accumulate(all(v), (0LL)) #define isin(a, b, c) (b <= a && a <= c) #define println cout << "\n"; #define sz(v) (int)v.size() /* alias */ template <class T> using vec = vector<T>; typedef vector<int> vi; typedef pair<int, int> pi; typedef tuple<int, int, int> ti; typedef map<int, int> mi; typedef set<int> si; /* constant */ const int inf = 1LL << 62; const int mod = 1e9 + 7; const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1}; const int dy[8] = {0, 1, 0, -1, -1, -1, 1, 1}; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; /* io_method */ int input() { int tmp; cin >> tmp; return tmp; } string raw_input() { string tmp; cin >> tmp; return tmp; } template <class T> void printx(T n) { cout << n; } template <class T, class U> void printx(pair<T, U> p) { cout << "(" << p.first << "," << p.second << ")"; } template <class T, class U, class V> void printx(tuple<T, U, V> t) { cout << "{" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << "}" << endl; } template <class T> void printx(vector<T> v) { cout << "{"; rep(i, 0, v.size()) { printx(v[i]); if (i != v.size() - 1) printx(","); } cout << "}"; } template <class T> void print(T n) { printx(n); cout << endl; } template <class T> void print(set<T> s) { cout << "{"; each(s, e) { if (e != s.begin()) printx(","); printx(*e); } cout << "}" << endl; } template <class T, class U> void print(map<T, U> mp) { cout << "{"; each(mp, e) { cout << "(" << e->first << "," << e->second << ")"; } cout << "}" << endl; } template <class T> void printans(vec<T> v) { rep(i, 0, sz(v)) { cout << v[i] << (i == sz(v) - 1 ? "" : " "); } cout << endl; } /* general_method */ 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 <class T> T cut(T &a, int l, int r) { return T(a.begin() + l, a.begin() + r); } /* main */ int n, m; si arr; int need[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6}; void in() { cin >> n >> m; rep(i, 0, m) arr.insert(input()); } bool isbig(string a, string b) { if (sz(a) < sz(b)) return true; else if (sz(a) == sz(b)) { rep(i, 0, sz(a)) { if (a[i] > b[i]) return false; if (a[i] < b[i]) return true; } return false; } else { return false; } } string dp[10010]; string dfs(int rest) { if (rest == 0) return "&"; if (rest < 0) return "$"; if (dp[rest] != "-1") return dp[rest]; string ans = ""; rep(i, 1, 10) { if (exist(arr, i)) { string tmp = dfs(rest - need[i]); if (tmp.back() == '$') continue; if (isbig(ans, to_string(i) + tmp)) { ans = to_string(i) + tmp; } } } return dp[rest] = ans; } void solve() { rep(i, 0, 10010) dp[i] = "-1"; string ans = dfs(n); print(cut(ans, 0, sz(ans) - 1)); } signed main() { cin.tie(0); ios::sync_with_stdio(false); in(); solve(); }
replace
154
155
154
155
0
p03128
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const ll mod = 1000000007; const int INF = 10000; int num[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; // num[i] : iを作るのに必要なマッチの本数 int main() { int n, m; cin >> n >> m; vector<int> a(m); rep(i, m) { cin >> a[i]; a[i]--; // a[i]を0-indexにする } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); // aを降順ソート vector<int> dp( n + 1, -INF); // dp[i] : // i本(iは1-index)のマッチを使って条件を満たすように整数を作るときの桁数の最大値 dp[0] = 0; for (int i = 1; i <= n; i++) { rep(j, 9) { if (i >= num[a[j]]) { dp[i] = max(dp[i], dp[i - num[a[j]]] + 1); } } } int nokori = n; // 残っているマッチの本数 rep(i, dp[n]) { // dp[n]桁作る rep(j, m) { // a[j]が作れるか調べる if (nokori >= num[a[j]] && dp[nokori - num[a[j]]] == dp[nokori] - 1) { // a[j]が作れる場合 cout << a[j] + 1; // 1-indexにしたa[j]を出力して nokori -= num[a[j]]; // 残り本数をnum[a[j]]本減らして break; // 次の桁に行く } } } cout << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const ll mod = 1000000007; const int INF = 10000; int num[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; // num[i] : iを作るのに必要なマッチの本数 int main() { int n, m; cin >> n >> m; vector<int> a(m); rep(i, m) { cin >> a[i]; a[i]--; // a[i]を0-indexにする } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); // aを降順ソート vector<int> dp( n + 1, -INF); // dp[i] : // i本(iは1-index)のマッチを使って条件を満たすように整数を作るときの桁数の最大値 dp[0] = 0; for (int i = 1; i <= n; i++) { rep(j, m) { if (i >= num[a[j]]) { dp[i] = max(dp[i], dp[i - num[a[j]]] + 1); } } } int nokori = n; // 残っているマッチの本数 rep(i, dp[n]) { // dp[n]桁作る rep(j, m) { // a[j]が作れるか調べる if (nokori >= num[a[j]] && dp[nokori - num[a[j]]] == dp[nokori] - 1) { // a[j]が作れる場合 cout << a[j] + 1; // 1-indexにしたa[j]を出力して nokori -= num[a[j]]; // 残り本数をnum[a[j]]本減らして break; // 次の桁に行く } } } cout << endl; return 0; }
replace
38
39
38
39
0
p03128
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define fw(p) for (int w = 0; w < (p); w++) #define fx(p) for (int x = 0; x < (p); x++) #define fy(p) for (int y = 0; y < (p); y++) #define fz(p) for (int z = 0; z < (p); z++) #define fyg(p, g) for (int y = (g); y < (p); y++) #define fzg(p, g) for (int z = (g); z < (p); z++) #define ce(d) cout << d << endl; #define vecp(p) \ int aa; \ cin >> aa; \ (p).push_back(aa); #define vecpl(p) \ long long aa; \ cin >> aa; \ (p).push_back(aa); #define vecps(p) \ string aa; \ cin >> aa; \ (p).push_back(aa); #define vecp2(p) \ cin >> aa; \ (p).push_back(aa); #define vecpl2(p) \ long long a b; \ cin >> ab; \ (p).push_back(ab); #define vecps2(p) \ string ab; \ cin >> ab; \ (p).push_back(ab); #define set0(k, n) \ for (int nn = 0; nn < (n); nn++) { \ (k).push_back(0); \ } #define sorts(c) sort((c).begin(), (c).end()); #define reverses(c) reverse((c).begin(), (c).end()); #define vec(b) vector<int>(b); #define vecl(b) vector<long long>(b); #define vecs(b) vector<string>(b); #define vecsize(b, size) vector<int>(b)((size)); #define pb(b, a) (b).push_back((a)); #define doublece(a, b) cout << (a) << ' ' << (b) << endl; #define pairs(s) vector<pair<int, int>>(s); #define pairsl(s) vector<pair<ll, ll>>(s); #define pairss(s) vector<pair<string, string>>(s); #define pairsp(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define pairspl(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define pairsps(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define pairsREV(s) (s).push_back(make_pair(bb, aa)); #define pairslREV(s) (s).push_back(make_pair(bb, aa)); #define pairssREV(s) (s).push_back(make_pair(bb, aa)); #define MOD 1000000007 int N, M; map<int, bool> S; int A[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vecs(ANS) int main() { cin >> N >> M; vec(C) fx(M){vecp(C)} sorts(C) vector<int> dp[2000]; fy(N + 1) { fx(M) { if (y - A[C.at(x)] < 0) { continue; } if (dp[y - A[C.at(x)]].size() == 0 && y - A[C.at(x)] != 0) { continue; } if (dp[y - A[C.at(x)]].size() + 1 > dp[y].size()) { dp[y].clear(); pb(dp[y], C.at(x)) fz(dp[y - A[C.at(x)]].size()) { pb(dp[y], dp[y - A[C.at(x)]].at(z)) } } else if (dp[y - A[C.at(x)]].size() + 1 == dp[y].size()) { sorts(dp[y]) vector<int> TEMP; TEMP.clear(); pb(TEMP, C.at(x)) fz(dp[y - A[C.at(x)]].size()){ pb(TEMP, dp[y - A[C.at(x)]].at(z))} sorts(TEMP); bool flag = true; for (int i = TEMP.size() - 1; i >= 0; i--) { if (dp[y].at(i) < TEMP.at(i)) { flag = false; break; } } if (!flag) { dp[y].clear(); for (int i = 0; i < TEMP.size(); i++) { // doublece(y,TEMP.at(i)) pb(dp[y], TEMP.at(i)) } } } } } sorts(dp[N]) reverses(dp[N]) fx(dp[N].size()) { // doublece(N,dp[N].at(x)) cout << dp[N].at(x); } cout << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fw(p) for (int w = 0; w < (p); w++) #define fx(p) for (int x = 0; x < (p); x++) #define fy(p) for (int y = 0; y < (p); y++) #define fz(p) for (int z = 0; z < (p); z++) #define fyg(p, g) for (int y = (g); y < (p); y++) #define fzg(p, g) for (int z = (g); z < (p); z++) #define ce(d) cout << d << endl; #define vecp(p) \ int aa; \ cin >> aa; \ (p).push_back(aa); #define vecpl(p) \ long long aa; \ cin >> aa; \ (p).push_back(aa); #define vecps(p) \ string aa; \ cin >> aa; \ (p).push_back(aa); #define vecp2(p) \ cin >> aa; \ (p).push_back(aa); #define vecpl2(p) \ long long a b; \ cin >> ab; \ (p).push_back(ab); #define vecps2(p) \ string ab; \ cin >> ab; \ (p).push_back(ab); #define set0(k, n) \ for (int nn = 0; nn < (n); nn++) { \ (k).push_back(0); \ } #define sorts(c) sort((c).begin(), (c).end()); #define reverses(c) reverse((c).begin(), (c).end()); #define vec(b) vector<int>(b); #define vecl(b) vector<long long>(b); #define vecs(b) vector<string>(b); #define vecsize(b, size) vector<int>(b)((size)); #define pb(b, a) (b).push_back((a)); #define doublece(a, b) cout << (a) << ' ' << (b) << endl; #define pairs(s) vector<pair<int, int>>(s); #define pairsl(s) vector<pair<ll, ll>>(s); #define pairss(s) vector<pair<string, string>>(s); #define pairsp(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define pairspl(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define pairsps(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define pairsREV(s) (s).push_back(make_pair(bb, aa)); #define pairslREV(s) (s).push_back(make_pair(bb, aa)); #define pairssREV(s) (s).push_back(make_pair(bb, aa)); #define MOD 1000000007 int N, M; map<int, bool> S; int A[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vecs(ANS) int main() { cin >> N >> M; vec(C) fx(M){vecp(C)} sorts(C) vector<int> dp[20000]; fy(N + 1) { fx(M) { if (y - A[C.at(x)] < 0) { continue; } if (dp[y - A[C.at(x)]].size() == 0 && y - A[C.at(x)] != 0) { continue; } if (dp[y - A[C.at(x)]].size() + 1 > dp[y].size()) { dp[y].clear(); pb(dp[y], C.at(x)) fz(dp[y - A[C.at(x)]].size()) { pb(dp[y], dp[y - A[C.at(x)]].at(z)) } } else if (dp[y - A[C.at(x)]].size() + 1 == dp[y].size()) { sorts(dp[y]) vector<int> TEMP; TEMP.clear(); pb(TEMP, C.at(x)) fz(dp[y - A[C.at(x)]].size()){ pb(TEMP, dp[y - A[C.at(x)]].at(z))} sorts(TEMP); bool flag = true; for (int i = TEMP.size() - 1; i >= 0; i--) { if (dp[y].at(i) < TEMP.at(i)) { flag = false; break; } } if (!flag) { dp[y].clear(); for (int i = 0; i < TEMP.size(); i++) { // doublece(y,TEMP.at(i)) pb(dp[y], TEMP.at(i)) } } } } } sorts(dp[N]) reverses(dp[N]) fx(dp[N].size()) { // doublece(N,dp[N].at(x)) cout << dp[N].at(x); } cout << endl; }
replace
71
72
71
72
0
p03128
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define loop(i, x, n) for (int i = (x); i < (n); i++) #define all(v) (v).begin(), (v).end() #define int long long using namespace std; const int MOD = 1e9 + 7; const int INF = 1e18; // template<typename T> void cmax(T &a, T b) { a = max(a, b); } // template<typename T> void cmin(T &a, T b) { a = min(a, b); } void cmax(string &a, string b) { if (a == "-" || a.size() < b.size()) a = b; else if (a.size() == b.size()) { if (a < b) a = b; } return; } int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; signed main() { int n, m; cin >> n >> m; vector<int> a(m); rep(i, m) cin >> a[i]; vector<string> dp(10004, "-"); dp[0] = ""; rep(i, n + 1) { if (dp[i] == "-") continue; for (auto x : a) cmax(dp[i + num[x]], dp[i] + (char)(x + '0')); } cout << dp[n] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define loop(i, x, n) for (int i = (x); i < (n); i++) #define all(v) (v).begin(), (v).end() #define int long long using namespace std; const int MOD = 1e9 + 7; const int INF = 1e18; // template<typename T> void cmax(T &a, T b) { a = max(a, b); } // template<typename T> void cmin(T &a, T b) { a = min(a, b); } void cmax(string &a, string b) { if (a == "-" || a.size() < b.size()) a = b; else if (a.size() == b.size()) { if (a < b) a = b; } return; } int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; signed main() { int n, m; cin >> n >> m; vector<int> a(m); rep(i, m) cin >> a[i]; vector<string> dp(20004, "-"); dp[0] = ""; rep(i, n + 1) { if (dp[i] == "-") continue; for (auto x : a) cmax(dp[i + num[x]], dp[i] + (char)(x + '0')); } cout << dp[n] << endl; return 0; }
replace
43
44
43
44
0
p03128
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <assert.h> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <vector> #define int long long // #define ll long long #define double long double #define mod 1000000007 #define MAXN (int)1e+5 * 2 + 1 #define LL_MAX 9223372036854775807 // ない環境用 #define LL_HALFMAX 9223372036854775807 / 2 // ない環境用 #define MIN -(9223372036854775807 / 2) #define INF 9223372036854775807 / 2 #define REP(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define mp make_pair template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } using namespace std; std::mt19937 mt((int)time(0)); int dx[4] = {0, 1, 0, -1}; // x軸方向への変位 int dy[4] = {1, 0, -1, 0}; // y軸方向への変位 using Weight = int; using Flow = int; struct Edge { int src, dst; Weight weight; Flow cap; Edge() : src(0), dst(0), weight(0) {} Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {} }; using Edges = std::vector<Edge>; using Graph = std::vector<Edges>; using Array = std::vector<Weight>; using Matrix = std::vector<Array>; void add_edge(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); g[b].emplace_back(b, a, w); } void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); } struct uf_tree { std::vector<int> parent; int __size; uf_tree(int size_) : parent(size_, -1), __size(size_) {} void unite(int x, int y) { if ((x = find(x)) != (y = find(y))) { if (parent[y] < parent[x]) std::swap(x, y); parent[x] += parent[y]; parent[y] = x; __size--; } } bool is_same(int x, int y) { return find(x) == find(y); } int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } int size() { return __size; } }; //!!!問題をちゃんと読む!!! //!!!問題をちゃんと読め!!! //!!!問題は読みましたか?!!! template <signed M, unsigned T> struct mod_int { constexpr static signed MODULO = M; constexpr static unsigned TABLE_SIZE = T; signed x; mod_int() : x(0) {} mod_int(long long y) : x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {} mod_int(signed y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {} mod_int &operator+=(const mod_int &rhs) { if ((x += rhs.x) >= MODULO) x -= MODULO; return *this; } mod_int &operator-=(const mod_int &rhs) { if ((x += MODULO - rhs.x) >= MODULO) x -= MODULO; return *this; } mod_int &operator*=(const mod_int &rhs) { x = static_cast<signed>(1LL * x * rhs.x % MODULO); return *this; } mod_int &operator/=(const mod_int &rhs) { x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO); return *this; } mod_int operator-() const { return mod_int(-x); } mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; } mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; } mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; } mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; } bool operator<(const mod_int &rhs) const { return x < rhs.x; } mod_int inv() const { assert(x != 0); if (x <= static_cast<signed>(TABLE_SIZE)) { if (_inv[1].x == 0) prepare(); return _inv[x]; } else { signed a = x, b = MODULO, u = 1, v = 0, t; while (b) { t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return mod_int(u); } } mod_int pow(long long t) const { assert(!(x == 0 && t == 0)); mod_int e = *this, res = mod_int(1); for (; t; e *= e, t >>= 1) if (t & 1) res *= e; return res; } mod_int fact() { if (_fact[0].x == 0) prepare(); return _fact[x]; } mod_int inv_fact() { if (_fact[0].x == 0) prepare(); return _inv_fact[x]; } mod_int choose(mod_int y) { assert(y.x <= x); return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact(); } static mod_int _inv[TABLE_SIZE + 1]; static mod_int _fact[TABLE_SIZE + 1]; static mod_int _inv_fact[TABLE_SIZE + 1]; static void prepare() { _inv[1] = 1; for (int i = 2; i <= (int)TABLE_SIZE; ++i) { _inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO; } _fact[0] = 1; for (unsigned i = 1; i <= TABLE_SIZE; ++i) { _fact[i] = _fact[i - 1] * signed(i); } _inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv(); for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) { _inv_fact[i] = _inv_fact[i + 1] * (i + 1); } } }; template <signed M, unsigned F> std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) { return os << rhs.x; } template <signed M, unsigned F> std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) { long long s; is >> s; rhs = mod_int<M, F>(s); return is; } template <signed M, unsigned F> mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1]; template <signed M, unsigned F> mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1]; template <signed M, unsigned F> mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1]; template <signed M, unsigned F> bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) { return lhs.x == rhs.x; } template <int M, unsigned F> bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) { return !(lhs == rhs); } const signed MF = 1000010; const signed MOD = 1000000007; using mint = mod_int<MOD, MF>; mint binom(int n, int r) { return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r); } mint fact(int n) { return mint(n).fact(); } mint inv_fact(int n) { return mint(n).inv_fact(); } // 出典 http://beet-aizu.hatenablog.com/entry/2017/12/01/225955 /* コンストラクタ引数説明 int n_ 要素数。 f 2つの要素Tをマージするための関数。 区間MAX区間更新の時: max 区間Sum区間Addの時: + g 1つの要素Tに作用素Eを適用するための関数。 区間MAX区間更新の時: = 区間Sum区間Addの時: + h 2つの作用素Eをマージするための関数。 区間MAX区間更新の時: = 区間Sum区間Addの時: + T d1 演算fの単位元。 区間MAX区間更新の時: -INF  区間Sum区間Addの時: 0 E d0, g, hの単位元。 区間MAX区間更新の時: 定義域外のどこか 区間Sum区間Addの時: 0 vector<T> v = vector<T>() セグ木を構成するときのvector P p = [](E a, int b) {return a; } 区間の長さbを引数に取り、区間の長さによって変化する作用素E'を返す関数。 例えば、区間MAX区間Addの時なんかは区間長によって足すべき数が変化するので必要 区間Sum区間Addの時: * //具体例 //区間chmin, 区間min auto myMin = [](int a, int b) {return min(a, b); }; SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX); //区間update、区間min SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX); */ template <typename T, typename E> struct SegmentTree { typedef function<T(T, T)> F; typedef function<T(T, E)> G; typedef function<E(E, E)> H; typedef function<E(E, int)> P; int n; F f; G g; H h; P p; T d1; E d0; vector<T> dat; vector<E> laz; SegmentTree( int n_, F f, G g, H h, T d1, E d0, vector<T> v = vector<T>(), P p = [](E a, int b) { return a; }) : f(f), g(g), h(h), d1(d1), d0(d0), p(p) { init(n_); if (n_ == (int)v.size()) build(n_, v); } // 初期化。要素配列と遅延配列を2*n-1個にする void init(int n_) { n = 1; while (n < n_) n *= 2; dat.clear(); dat.resize(2 * n - 1, d1); laz.clear(); laz.resize(2 * n - 1, d0); } // 既存のvectorからセグ木を構築 void build(int n_, vector<T> v) { for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]); } // ノードを評価する。 inline void eval(int len, int k) { // 遅延配列に単位元が入ってたら評価済みなのでおしまい if (laz[k] == d0) return; // 葉ノードでないなら遅延伝播する if (k * 2 + 1 < n * 2 - 1) { // h: 2つの作用素を引数に取り合成した作用素を返す関数 laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]); laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]); } // p: // このノードに対応する区間長と作用素を引数に取り、区間長に対応する作用素を返す関数 // dat[k] にlaz に溜めていた作用素を適用(g: // 要素型と作用素型を引数に取り、要素に作用素を作用させた結果を返す関数、ここでの作用素とは区間Sum区間Addなら // (+ 3) とか) dat[k] = g(dat[k], p(laz[k], len)); // 適用し終わったので遅延配列をクリア laz[k] = d0; } //[l,r)の区間を再帰的に見ながら0-indexedの[a, b)を更新する T update(int a, int b, E x, int k, int l, int r) { // 先に評価 eval(r - l, k); // 範囲外ならなにもしないでそのノードが持つ値を返す if (r <= a || b <= l) return dat[k]; // 完全被覆なら既に遅延配列に入っている作用素と追加したい作用素をマージした後にそれを要素に作用させた結果を返す、pは区間長に対応する作用素を得るための(ry if (a <= l && r <= b) { laz[k] = h(laz[k], x); return g(dat[k], p(laz[k], r - l)); } // 完全被覆でも範囲外でもないなら(中途半端にかぶっているなら)完全被覆と範囲外の境界が見えるまで木を潜って変化後の値を得る return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2), update(a, b, x, k * 2 + 2, (l + r) / 2, r)); } T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); } // a だけ更新(点更新) T update(int a, E x) { return update(a, a + 1, x, 0, 0, n); } T query(int a, int b, int k, int l, int r) { eval(r - l, k); // 範囲外なら単位元を返す if (r <= a || b <= l) return d1; // 完全被覆ならそのまま返す if (a <= l && r <= b) return dat[k]; // 一部被覆なら完全被覆と範囲外に分かれるまで木を潜る T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return f(vl, vr); } // 0-indexedで[a, b)の区間*を求める T query(int a, int b) { return query(a, b, 0, 0, n); } // 点取得 T query(int a) { return query(a, a + 1, 0, 0, n); } }; // 座標圧縮 class compress { public: static const int MAP = 10000000; map<int, int> zip; int unzip[MAP]; compress(vector<int> &x) { sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); for (int i = 0; i < x.size(); i++) { zip[x[i]] = i; unzip[i] = x[i]; } } }; unsigned euclidean_gcd(unsigned a, unsigned b) { while (1) { if (a < b) swap(a, b); if (!b) break; a %= b; } return a; } // https://ei1333.github.io/luzhiled/snippets/dp/cumulative-sum-2d.html template <class T> struct CumulativeSum2D { vector<vector<T>> data; CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {} void add(int x, int y, T z) { ++x, ++y; if (x >= data.size() || y >= data[0].size()) return; data[x][y] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } T query(int sx, int sy, int gx, int gy) { return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]); } }; // lib int nC2(int n) { return n * (n - 1) / 2; } class node { public: int depth; int num; node(int d, int n) { depth = d; num = n; } }; CumulativeSum2D<int> sumB(4001, 4001); template <class T> struct CumulativeSum { vector<T> data; CumulativeSum(int sz) : data(sz, 0){}; void add(int k, T x) { data[k] += x; } void build() { for (int i = 1; i < data.size(); i++) { data[i] += data[i - 1]; } } T query(int k) { if (k < 0) return (0); return (data[min(k, (int)data.size() - 1)]); } //[left, right]の和 T query(int left, int right) { return query(right) - query(left - 1); } }; std::vector<bool> IsPrime; void sieve(size_t max) { if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } IsPrime[0] = false; // 0は素数ではない IsPrime[1] = false; // 1は素数ではない for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる if (IsPrime[i]) // iが素数ならば for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は IsPrime[i * j] = false; // 素数ではない } vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; for (int64_t i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } class ExDijkstraNode { public: int nowDist; int parity; int nowNode; ExDijkstraNode(int d, int p, int n) { nowDist = d; parity = p; nowNode = n; } bool operator<(const ExDijkstraNode &r) const { return nowDist < r.nowDist; } bool operator>(const ExDijkstraNode &r) const { return nowDist > r.nowDist; } }; // 型T の値Nについて、繰り返し二乗法でN^Pを計算する関数テンプレート // http://satanic0258.hatenablog.com/entry/2016/04/29/004730 template <typename T> T RepeatSquaring(T N, int P, function<T(T, T)> mul, T id) { if (P == 0) return id; if (P % 2 == 0) { T t = RepeatSquaring(N, P / 2, mul, id); return mul(t, t); } return mul(N, RepeatSquaring(N, P - 1, mul, id)); } // 行列積 a.b vector<vector<mint>> dot(vector<vector<mint>> a, vector<vector<mint>> b) { vector<vector<mint>> ret; rep(i, a.size()) { vector<mint> v(b[0].size(), mint(0)); ret.push_back(v); } rep(i, a.size()) { rep(j, b[0].size()) { rep(k, a.size()) { ret[i][j] += a[i][k] * b[k][j]; } } } return ret; } std::pair<std::vector<int>, std::vector<int>> prime_factor_decomp(int n) { std::vector<int> p, e; int m = n; for (int i = 2; i * i <= n; i++) { if (m % i != 0) continue; int c = 0; while (m % i == 0) c++, m /= i; p.push_back(i); e.push_back(c); } if (m > 1) { p.push_back(m); e.push_back(1); } return std::make_pair(p, e); } vector<pair<int, int>> pdecomped; /* dp[i] := i本で作れる整数の最大値 更新: dp[i] = max(dp[i-本数(1)]...dp[i-本数(9)]) */ string dp[10001]; bool visited[10001]; const int matchNum[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int N, M; vector<int> A; // 最大5000桁->10^3オーダー auto strMax = [](string s, string t) -> string { if (s == t) { return t; } if (s.length() > t.length()) { return s; } if (s.length() < t.length()) { return t; } // ここに来るのはs とt の桁数が同じで違う数になっているとき -> // 違う数が必ず存在 rep(i, s.length()) { if (s[i] < t[i]) { return t; } if (s[i] > t[i]) { return s; } } }; string rec(int n) { if (n < 0) { return "NG"; } // ぴったり使い切る必要があるので n == 0 に到達できる時のみOK if (n == 0) { return ""; } if (visited[n]) { return dp[n]; } // 各遷移元に作れる数を付け足してみる string result = ""; for (int i : A) { string cand = rec(n - matchNum[i]); if (cand == "NG") { continue; } cand += to_string(i); sort(cand.begin(), cand.end(), greater<char>()); result = strMax(result, cand); } visited[n] = true; if (result == "") { return dp[n] = "NG"; } else { return dp[n] = result; } } signed main() { cin >> N >> M; rep(i, 10001) { dp[i] = ""; } rep(i, M) { int t; cin >> t; A.push_back(t); } // 意味なし(デバッガビリティ向上目的) sort(A.begin(), A.end(), greater<int>()); cout << rec(N) << "\n"; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <assert.h> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <vector> #define int long long // #define ll long long #define double long double #define mod 1000000007 #define MAXN (int)1e+5 * 2 + 1 #define LL_MAX 9223372036854775807 // ない環境用 #define LL_HALFMAX 9223372036854775807 / 2 // ない環境用 #define MIN -(9223372036854775807 / 2) #define INF 9223372036854775807 / 2 #define REP(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define mp make_pair template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } using namespace std; std::mt19937 mt((int)time(0)); int dx[4] = {0, 1, 0, -1}; // x軸方向への変位 int dy[4] = {1, 0, -1, 0}; // y軸方向への変位 using Weight = int; using Flow = int; struct Edge { int src, dst; Weight weight; Flow cap; Edge() : src(0), dst(0), weight(0) {} Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {} }; using Edges = std::vector<Edge>; using Graph = std::vector<Edges>; using Array = std::vector<Weight>; using Matrix = std::vector<Array>; void add_edge(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); g[b].emplace_back(b, a, w); } void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); } struct uf_tree { std::vector<int> parent; int __size; uf_tree(int size_) : parent(size_, -1), __size(size_) {} void unite(int x, int y) { if ((x = find(x)) != (y = find(y))) { if (parent[y] < parent[x]) std::swap(x, y); parent[x] += parent[y]; parent[y] = x; __size--; } } bool is_same(int x, int y) { return find(x) == find(y); } int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } int size() { return __size; } }; //!!!問題をちゃんと読む!!! //!!!問題をちゃんと読め!!! //!!!問題は読みましたか?!!! template <signed M, unsigned T> struct mod_int { constexpr static signed MODULO = M; constexpr static unsigned TABLE_SIZE = T; signed x; mod_int() : x(0) {} mod_int(long long y) : x(static_cast<signed>(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO)) {} mod_int(signed y) : x(y >= 0 ? y % MODULO : MODULO - (-y) % MODULO) {} mod_int &operator+=(const mod_int &rhs) { if ((x += rhs.x) >= MODULO) x -= MODULO; return *this; } mod_int &operator-=(const mod_int &rhs) { if ((x += MODULO - rhs.x) >= MODULO) x -= MODULO; return *this; } mod_int &operator*=(const mod_int &rhs) { x = static_cast<signed>(1LL * x * rhs.x % MODULO); return *this; } mod_int &operator/=(const mod_int &rhs) { x = static_cast<signed>((1LL * x * rhs.inv().x) % MODULO); return *this; } mod_int operator-() const { return mod_int(-x); } mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; } mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; } mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; } mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; } bool operator<(const mod_int &rhs) const { return x < rhs.x; } mod_int inv() const { assert(x != 0); if (x <= static_cast<signed>(TABLE_SIZE)) { if (_inv[1].x == 0) prepare(); return _inv[x]; } else { signed a = x, b = MODULO, u = 1, v = 0, t; while (b) { t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return mod_int(u); } } mod_int pow(long long t) const { assert(!(x == 0 && t == 0)); mod_int e = *this, res = mod_int(1); for (; t; e *= e, t >>= 1) if (t & 1) res *= e; return res; } mod_int fact() { if (_fact[0].x == 0) prepare(); return _fact[x]; } mod_int inv_fact() { if (_fact[0].x == 0) prepare(); return _inv_fact[x]; } mod_int choose(mod_int y) { assert(y.x <= x); return this->fact() * y.inv_fact() * mod_int(x - y.x).inv_fact(); } static mod_int _inv[TABLE_SIZE + 1]; static mod_int _fact[TABLE_SIZE + 1]; static mod_int _inv_fact[TABLE_SIZE + 1]; static void prepare() { _inv[1] = 1; for (int i = 2; i <= (int)TABLE_SIZE; ++i) { _inv[i] = 1LL * _inv[MODULO % i].x * (MODULO - MODULO / i) % MODULO; } _fact[0] = 1; for (unsigned i = 1; i <= TABLE_SIZE; ++i) { _fact[i] = _fact[i - 1] * signed(i); } _inv_fact[TABLE_SIZE] = _fact[TABLE_SIZE].inv(); for (int i = (int)TABLE_SIZE - 1; i >= 0; --i) { _inv_fact[i] = _inv_fact[i + 1] * (i + 1); } } }; template <signed M, unsigned F> std::ostream &operator<<(std::ostream &os, const mod_int<M, F> &rhs) { return os << rhs.x; } template <signed M, unsigned F> std::istream &operator>>(std::istream &is, mod_int<M, F> &rhs) { long long s; is >> s; rhs = mod_int<M, F>(s); return is; } template <signed M, unsigned F> mod_int<M, F> mod_int<M, F>::_inv[TABLE_SIZE + 1]; template <signed M, unsigned F> mod_int<M, F> mod_int<M, F>::_fact[TABLE_SIZE + 1]; template <signed M, unsigned F> mod_int<M, F> mod_int<M, F>::_inv_fact[TABLE_SIZE + 1]; template <signed M, unsigned F> bool operator==(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) { return lhs.x == rhs.x; } template <int M, unsigned F> bool operator!=(const mod_int<M, F> &lhs, const mod_int<M, F> &rhs) { return !(lhs == rhs); } const signed MF = 1000010; const signed MOD = 1000000007; using mint = mod_int<MOD, MF>; mint binom(int n, int r) { return (r < 0 || r > n || n < 0) ? 0 : mint(n).choose(r); } mint fact(int n) { return mint(n).fact(); } mint inv_fact(int n) { return mint(n).inv_fact(); } // 出典 http://beet-aizu.hatenablog.com/entry/2017/12/01/225955 /* コンストラクタ引数説明 int n_ 要素数。 f 2つの要素Tをマージするための関数。 区間MAX区間更新の時: max 区間Sum区間Addの時: + g 1つの要素Tに作用素Eを適用するための関数。 区間MAX区間更新の時: = 区間Sum区間Addの時: + h 2つの作用素Eをマージするための関数。 区間MAX区間更新の時: = 区間Sum区間Addの時: + T d1 演算fの単位元。 区間MAX区間更新の時: -INF  区間Sum区間Addの時: 0 E d0, g, hの単位元。 区間MAX区間更新の時: 定義域外のどこか 区間Sum区間Addの時: 0 vector<T> v = vector<T>() セグ木を構成するときのvector P p = [](E a, int b) {return a; } 区間の長さbを引数に取り、区間の長さによって変化する作用素E'を返す関数。 例えば、区間MAX区間Addの時なんかは区間長によって足すべき数が変化するので必要 区間Sum区間Addの時: * //具体例 //区間chmin, 区間min auto myMin = [](int a, int b) {return min(a, b); }; SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX); //区間update、区間min SegmentTree<int, int> seg(n, myMin, myMin, myMin, LL_HALFMAX, LL_HALFMAX); */ template <typename T, typename E> struct SegmentTree { typedef function<T(T, T)> F; typedef function<T(T, E)> G; typedef function<E(E, E)> H; typedef function<E(E, int)> P; int n; F f; G g; H h; P p; T d1; E d0; vector<T> dat; vector<E> laz; SegmentTree( int n_, F f, G g, H h, T d1, E d0, vector<T> v = vector<T>(), P p = [](E a, int b) { return a; }) : f(f), g(g), h(h), d1(d1), d0(d0), p(p) { init(n_); if (n_ == (int)v.size()) build(n_, v); } // 初期化。要素配列と遅延配列を2*n-1個にする void init(int n_) { n = 1; while (n < n_) n *= 2; dat.clear(); dat.resize(2 * n - 1, d1); laz.clear(); laz.resize(2 * n - 1, d0); } // 既存のvectorからセグ木を構築 void build(int n_, vector<T> v) { for (int i = 0; i < n_; i++) dat[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[i * 2 + 1], dat[i * 2 + 2]); } // ノードを評価する。 inline void eval(int len, int k) { // 遅延配列に単位元が入ってたら評価済みなのでおしまい if (laz[k] == d0) return; // 葉ノードでないなら遅延伝播する if (k * 2 + 1 < n * 2 - 1) { // h: 2つの作用素を引数に取り合成した作用素を返す関数 laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]); laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]); } // p: // このノードに対応する区間長と作用素を引数に取り、区間長に対応する作用素を返す関数 // dat[k] にlaz に溜めていた作用素を適用(g: // 要素型と作用素型を引数に取り、要素に作用素を作用させた結果を返す関数、ここでの作用素とは区間Sum区間Addなら // (+ 3) とか) dat[k] = g(dat[k], p(laz[k], len)); // 適用し終わったので遅延配列をクリア laz[k] = d0; } //[l,r)の区間を再帰的に見ながら0-indexedの[a, b)を更新する T update(int a, int b, E x, int k, int l, int r) { // 先に評価 eval(r - l, k); // 範囲外ならなにもしないでそのノードが持つ値を返す if (r <= a || b <= l) return dat[k]; // 完全被覆なら既に遅延配列に入っている作用素と追加したい作用素をマージした後にそれを要素に作用させた結果を返す、pは区間長に対応する作用素を得るための(ry if (a <= l && r <= b) { laz[k] = h(laz[k], x); return g(dat[k], p(laz[k], r - l)); } // 完全被覆でも範囲外でもないなら(中途半端にかぶっているなら)完全被覆と範囲外の境界が見えるまで木を潜って変化後の値を得る return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2), update(a, b, x, k * 2 + 2, (l + r) / 2, r)); } T update(int a, int b, E x) { return update(a, b, x, 0, 0, n); } // a だけ更新(点更新) T update(int a, E x) { return update(a, a + 1, x, 0, 0, n); } T query(int a, int b, int k, int l, int r) { eval(r - l, k); // 範囲外なら単位元を返す if (r <= a || b <= l) return d1; // 完全被覆ならそのまま返す if (a <= l && r <= b) return dat[k]; // 一部被覆なら完全被覆と範囲外に分かれるまで木を潜る T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return f(vl, vr); } // 0-indexedで[a, b)の区間*を求める T query(int a, int b) { return query(a, b, 0, 0, n); } // 点取得 T query(int a) { return query(a, a + 1, 0, 0, n); } }; // 座標圧縮 class compress { public: static const int MAP = 10000000; map<int, int> zip; int unzip[MAP]; compress(vector<int> &x) { sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); for (int i = 0; i < x.size(); i++) { zip[x[i]] = i; unzip[i] = x[i]; } } }; unsigned euclidean_gcd(unsigned a, unsigned b) { while (1) { if (a < b) swap(a, b); if (!b) break; a %= b; } return a; } // https://ei1333.github.io/luzhiled/snippets/dp/cumulative-sum-2d.html template <class T> struct CumulativeSum2D { vector<vector<T>> data; CumulativeSum2D(int W, int H) : data(W + 1, vector<int>(H + 1, 0)) {} void add(int x, int y, T z) { ++x, ++y; if (x >= data.size() || y >= data[0].size()) return; data[x][y] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } T query(int sx, int sy, int gx, int gy) { return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]); } }; // lib int nC2(int n) { return n * (n - 1) / 2; } class node { public: int depth; int num; node(int d, int n) { depth = d; num = n; } }; CumulativeSum2D<int> sumB(4001, 4001); template <class T> struct CumulativeSum { vector<T> data; CumulativeSum(int sz) : data(sz, 0){}; void add(int k, T x) { data[k] += x; } void build() { for (int i = 1; i < data.size(); i++) { data[i] += data[i - 1]; } } T query(int k) { if (k < 0) return (0); return (data[min(k, (int)data.size() - 1)]); } //[left, right]の和 T query(int left, int right) { return query(right) - query(left - 1); } }; std::vector<bool> IsPrime; void sieve(size_t max) { if (max + 1 > IsPrime.size()) { // resizeで要素数が減らないように IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保 } IsPrime[0] = false; // 0は素数ではない IsPrime[1] = false; // 1は素数ではない for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる if (IsPrime[i]) // iが素数ならば for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は IsPrime[i * j] = false; // 素数ではない } vector<int64_t> divisor(int64_t n) { vector<int64_t> ret; for (int64_t i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } class ExDijkstraNode { public: int nowDist; int parity; int nowNode; ExDijkstraNode(int d, int p, int n) { nowDist = d; parity = p; nowNode = n; } bool operator<(const ExDijkstraNode &r) const { return nowDist < r.nowDist; } bool operator>(const ExDijkstraNode &r) const { return nowDist > r.nowDist; } }; // 型T の値Nについて、繰り返し二乗法でN^Pを計算する関数テンプレート // http://satanic0258.hatenablog.com/entry/2016/04/29/004730 template <typename T> T RepeatSquaring(T N, int P, function<T(T, T)> mul, T id) { if (P == 0) return id; if (P % 2 == 0) { T t = RepeatSquaring(N, P / 2, mul, id); return mul(t, t); } return mul(N, RepeatSquaring(N, P - 1, mul, id)); } // 行列積 a.b vector<vector<mint>> dot(vector<vector<mint>> a, vector<vector<mint>> b) { vector<vector<mint>> ret; rep(i, a.size()) { vector<mint> v(b[0].size(), mint(0)); ret.push_back(v); } rep(i, a.size()) { rep(j, b[0].size()) { rep(k, a.size()) { ret[i][j] += a[i][k] * b[k][j]; } } } return ret; } std::pair<std::vector<int>, std::vector<int>> prime_factor_decomp(int n) { std::vector<int> p, e; int m = n; for (int i = 2; i * i <= n; i++) { if (m % i != 0) continue; int c = 0; while (m % i == 0) c++, m /= i; p.push_back(i); e.push_back(c); } if (m > 1) { p.push_back(m); e.push_back(1); } return std::make_pair(p, e); } vector<pair<int, int>> pdecomped; /* dp[i] := i本で作れる整数の最大値 更新: dp[i] = max(dp[i-本数(1)]...dp[i-本数(9)]) */ string dp[10001]; bool visited[10001]; const int matchNum[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int N, M; vector<int> A; // 最大5000桁->10^3オーダー auto strMax = [](string s, string t) -> string { if (s == t) { return t; } if (s.length() > t.length()) { return s; } if (s.length() < t.length()) { return t; } // ここに来るのはs とt の桁数が同じで違う数になっているとき -> // 違う数が必ず存在 rep(i, s.length()) { if (s[i] < t[i]) { return t; } if (s[i] > t[i]) { return s; } } }; string rec(int n) { if (n < 0) { return "NG"; } // ぴったり使い切る必要があるので n == 0 に到達できる時のみOK if (n == 0) { return ""; } if (visited[n]) { return dp[n]; } // 各遷移元に作れる数を付け足してみる string result = ""; for (int i : A) { string cand = rec(n - matchNum[i]); if (cand == "NG") { continue; } int ind = 0; while (ind < cand.length() && (cand[ind] - '0') > i) { ind++; } cand.insert(ind, to_string(i)); // sort(cand.begin(), cand.end(), greater<char>()); result = strMax(result, cand); } visited[n] = true; if (result == "") { return dp[n] = "NG"; } else { return dp[n] = result; } } signed main() { cin >> N >> M; rep(i, 10001) { dp[i] = ""; } rep(i, M) { int t; cin >> t; A.push_back(t); } // 意味なし(デバッガビリティ向上目的) sort(A.begin(), A.end(), greater<int>()); cout << rec(N) << "\n"; return 0; }
replace
636
639
636
642
TLE
p03128
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long ll f[2001][2001]; int main() { ll n, m; cin >> n >> m; ll c[10]; c[1] = 2; c[2] = 5; c[3] = 5; c[4] = 4; c[5] = 5; c[6] = 6; c[7] = 3; c[8] = 7; c[9] = 6; ll a[m + 1]; for (ll i = 1; i <= m; i++) { cin >> a[i]; f[c[a[i]]][a[i]] = 1; } sort(a + 1, a + m + 1); a[0] = 0; for (ll i = 2; i < n; i++) { for (ll j = 1; j <= m; j++) { if (f[i][a[j]]) { for (ll k = 1; k <= m; k++) { f[i + c[a[k]]][a[k]] = max(f[i + c[a[k]]][a[k]], f[i][a[j]] + 1); } } } } ll k; for (ll i = n; i > 0; i -= c[a[k]]) { k = 0; for (ll j = 1; j <= m; j++) { if (f[i][a[j]] && f[i][a[j]] >= f[i][a[k]]) { k = j; } } cout << (char)('0' + a[k]); } }
#include <bits/stdc++.h> using namespace std; #define ll long long ll f[20001][20]; int main() { ll n, m; cin >> n >> m; ll c[10]; c[1] = 2; c[2] = 5; c[3] = 5; c[4] = 4; c[5] = 5; c[6] = 6; c[7] = 3; c[8] = 7; c[9] = 6; ll a[m + 1]; for (ll i = 1; i <= m; i++) { cin >> a[i]; f[c[a[i]]][a[i]] = 1; } sort(a + 1, a + m + 1); a[0] = 0; for (ll i = 2; i < n; i++) { for (ll j = 1; j <= m; j++) { if (f[i][a[j]]) { for (ll k = 1; k <= m; k++) { f[i + c[a[k]]][a[k]] = max(f[i + c[a[k]]][a[k]], f[i][a[j]] + 1); } } } } ll k; for (ll i = n; i > 0; i -= c[a[k]]) { k = 0; for (ll j = 1; j <= m; j++) { if (f[i][a[j]] && f[i][a[j]] >= f[i][a[k]]) { k = j; } } cout << (char)('0' + a[k]); } }
replace
3
4
3
4
0
p03128
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl template <typename T> void trace(T *a, int s, int n) { for (int i = s; i < n; i++) { cout << a[i] << " "; } cout << endl; } typedef long long ll; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; const int inf = 1e9; int n, m; vector<int> digits; int maxlen[maxn]; // max length when using i sticks void relax(int &x, int y) { x = max(x, y); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; cin >> n >> m; for (int i = 0; i < m; i++) { int d; cin >> d; digits.push_back(d); } for (int i = 0; i <= n; i++) { maxlen[i] = -inf; } maxlen[0] = 0; for (int i = 0; i <= n; i++) { for (int d : digits) { if (d + i > n) continue; relax(maxlen[i + cost[d]], maxlen[i] + 1); } } int have = n; string res = ""; while (have > 0) { int x = 0; for (int d : digits) { if (cost[d] > have) continue; if (maxlen[have - cost[d]] + 1 == maxlen[have]) { x = max(x, d); } } have -= cost[x]; res += char('0' + x); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl template <typename T> void trace(T *a, int s, int n) { for (int i = s; i < n; i++) { cout << a[i] << " "; } cout << endl; } typedef long long ll; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; const int inf = 1e9; int n, m; vector<int> digits; int maxlen[maxn]; // max length when using i sticks void relax(int &x, int y) { x = max(x, y); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; cin >> n >> m; for (int i = 0; i < m; i++) { int d; cin >> d; digits.push_back(d); } for (int i = 0; i <= n; i++) { maxlen[i] = -inf; } maxlen[0] = 0; for (int i = 0; i <= n; i++) { for (int d : digits) { if (cost[d] + i > n) continue; relax(maxlen[i + cost[d]], maxlen[i] + 1); } } int have = n; string res = ""; while (have > 0) { int x = 0; for (int d : digits) { if (cost[d] > have) continue; if (maxlen[have - cost[d]] + 1 == maxlen[have]) { x = max(x, d); } } have -= cost[x]; res += char('0' + x); } cout << res << endl; return 0; }
replace
48
49
48
49
TLE
p03128
C++
Runtime Error
// 繝・Φ繝励Ξ #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define ALL(v) (v).begin(), (v).end() #define PAIR pair<int, int> using namespace std; // constexpr int MOD = 10e9+7; // constexpr int INF = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } // UP = 0;RIGHT = 1; DOWN = 2; LEFT =3; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; int gcd(int a, int b) { if (a < b) gcd(b, a); int r; while ((r = a % b)) { a = b; b = r; } return b; } // int req[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int dp[10010]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, M; cin >> N >> M; int A[M]; REP(i, M) cin >> A[i]; fill(dp, dp + N, (int)-1e9); dp[0] = 0; REP(i, N) { REP(j, M) { if (i + 1 - req[A[j]] >= 0) { chmax(dp[i + 1], dp[i + 1 - req[A[j]]] + 1); } } } sort(A, A + M, greater<int>()); string ans{""}; int n = N; REP(i, dp[N]) { REP(j, M) { if (n >= A[j] && dp[n] == dp[n - req[A[j]]] + 1) { ans.push_back(A[j] + '0'); n -= req[A[j]]; break; } } } assert(n == 0); cout << ans << endl; } // 驛ィ蛻・・譛€蟆丞€、 // 譖エ譁ー縺励↑縺・エ蜷遺・邏ッ遨阪o // 莠梧ャ。蜈・↓縺励◆縺・・縺・b縺呎ウ・ // 荳€邂・園繧剃ス募屓繧よ峩譁ー縺励◆縺・・Segment // Tree(縺溘□縺怜叙蠕涌(logN)) 遽・峇繧剃ス募屓繧よ峩譁ー縺励◆縺・・Lazy Segment // Tree
// 繝・Φ繝励Ξ #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define ALL(v) (v).begin(), (v).end() #define PAIR pair<int, int> using namespace std; // constexpr int MOD = 10e9+7; // constexpr int INF = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } // UP = 0;RIGHT = 1; DOWN = 2; LEFT =3; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; int gcd(int a, int b) { if (a < b) gcd(b, a); int r; while ((r = a % b)) { a = b; b = r; } return b; } // int req[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; int dp[10010]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, M; cin >> N >> M; int A[M]; REP(i, M) cin >> A[i]; fill(dp, dp + N, (int)-1e9); dp[0] = 0; REP(i, N) { REP(j, M) { if (i + 1 - req[A[j]] >= 0) { chmax(dp[i + 1], dp[i + 1 - req[A[j]]] + 1); } } } sort(A, A + M, greater<int>()); string ans{""}; int n = N; REP(i, dp[N]) { REP(j, M) { if (n >= req[A[j]] && dp[n] == dp[n - req[A[j]]] + 1) { ans.push_back(A[j] + '0'); n -= req[A[j]]; break; } } } assert(n == 0); cout << ans << endl; } // 驛ィ蛻・・譛€蟆丞€、 // 譖エ譁ー縺励↑縺・エ蜷遺・邏ッ遨阪o // 莠梧ャ。蜈・↓縺励◆縺・・縺・b縺呎ウ・ // 荳€邂・園繧剃ス募屓繧よ峩譁ー縺励◆縺・・Segment // Tree(縺溘□縺怜叙蠕涌(logN)) 遽・峇繧剃ス募屓繧よ峩譁ー縺励◆縺・・Lazy Segment // Tree
replace
64
65
64
65
0
p03128
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define mkp(a, b) make_pair(a, b) #define pb(t) push_back(t) #define ft first #define sc second #define pt(num) cout << num << "\n" #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) #define chmax(a, b) (a < b ? a = b : 0) #define chmin(a, b) (a > b ? a = b : 0) #define INF 1000000000000000000 #define MOD 1000000007LL #define MAX 101010 using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef map<ll, ll> Map; int main(void) { ll N, M; cin >> N >> M; ll use[10] = {}; ll cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; ll i, j; for (i = 1; i <= M; i++) { ll a; cin >> a; use[a] = 1; } string dp[1111]; for (i = 0; i <= N; i++) dp[i] = ""; for (i = 1; i < 10; i++) if (use[i]) dp[cost[i]] = (char)(i + '0'); for (i = 0; i <= N; i++) { if (dp[i] == "") continue; for (j = 1; j < 10; j++) { if (use[j] == 0) continue; if (i + cost[j] > N) continue; string s = dp[i] + (char)(j + '0'); if (dp[i + cost[j]].size() < dp[i].size() + 1) dp[i + cost[j]] = s; else if (dp[i + cost[j]] < s) dp[i + cost[j]] = s; } } pt(dp[N]); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define mkp(a, b) make_pair(a, b) #define pb(t) push_back(t) #define ft first #define sc second #define pt(num) cout << num << "\n" #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) #define chmax(a, b) (a < b ? a = b : 0) #define chmin(a, b) (a > b ? a = b : 0) #define INF 1000000000000000000 #define MOD 1000000007LL #define MAX 101010 using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef map<ll, ll> Map; int main(void) { ll N, M; cin >> N >> M; ll use[10] = {}; ll cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; ll i, j; for (i = 1; i <= M; i++) { ll a; cin >> a; use[a] = 1; } string dp[11111]; for (i = 0; i <= N; i++) dp[i] = ""; for (i = 1; i < 10; i++) if (use[i]) dp[cost[i]] = (char)(i + '0'); for (i = 0; i <= N; i++) { if (dp[i] == "") continue; for (j = 1; j < 10; j++) { if (use[j] == 0) continue; if (i + cost[j] > N) continue; string s = dp[i] + (char)(j + '0'); if (dp[i + cost[j]].size() < dp[i].size() + 1) dp[i + cost[j]] = s; else if (dp[i + cost[j]] < s) dp[i + cost[j]] = s; } } pt(dp[N]); }
replace
44
45
44
45
0
p03128
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define dbg(x) cerr << #x << ": " << x << endl const int INF = 1000000; const int MAXK = 6000; int main() { int n, m; cin >> n >> m; vector<int> A(m); rep(i, m) cin >> A[i]; sort(all(A)); vector<int> K = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vector<int> dp(MAXK, -INF); dp[0] = 0; for (int j = 0; j <= n; j++) rep(i, m) dp[j + K[A[i]]] = max(dp[j + K[A[i]]], dp[j] + 1); int rem = dp[n]; string s; int j = n; while (j > 0) { for (int i = m - 1; i >= 0; i--) { if (j - K[A[i]] < 0) continue; if (dp[j - K[A[i]]] == rem - 1) { char c = '0' + A[i]; s = s + c; j -= K[A[i]]; rem--; break; } } } cout << s << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define dbg(x) cerr << #x << ": " << x << endl const int INF = 1000000; const int MAXK = 1000005; int main() { int n, m; cin >> n >> m; vector<int> A(m); rep(i, m) cin >> A[i]; sort(all(A)); vector<int> K = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; vector<int> dp(MAXK, -INF); dp[0] = 0; for (int j = 0; j <= n; j++) rep(i, m) dp[j + K[A[i]]] = max(dp[j + K[A[i]]], dp[j] + 1); int rem = dp[n]; string s; int j = n; while (j > 0) { for (int i = m - 1; i >= 0; i--) { if (j - K[A[i]] < 0) continue; if (dp[j - K[A[i]]] == rem - 1) { char c = '0' + A[i]; s = s + c; j -= K[A[i]]; rem--; break; } } } cout << s << endl; return 0; }
replace
11
12
11
12
0
p03128
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (long long i = 0; i < (n); i++) #define FOR(i, a, b) for (long long i = (a); i < (b); i++) #define dump(x) cerr << #x << " => " << (x) << endl #define MIN(vec) *min_element(vec.begin(), vec.end()) #define MAX(vec) *max_element(vec.begin(), vec.end()) #define UNIQ(vec) \ vec.erase(unique(vec.begin(), vec.end()), vec.end()) // ソートの必要あり #define IN(n, m) (!(m.find(n) == m.end())) #define FINDL(vec, x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin()) #define FINDU(vec, x) (upper_bound(vec.begin(), vec.end(), x) - vec.begin()) #define EQ(a, b) (abs(a - b) < 1e-10) using namespace std; typedef long long LL; constexpr int dx[4] = {0, 1, 0, -1}; constexpr int dy[4] = {1, 0, -1, 0}; constexpr long double pi = M_PI; constexpr double eps = 1e-10; constexpr long mod = 1000000007; // LONG_MAX,LLONG_MAX template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template <class Key, class Value> ostream &operator<<(ostream &s, map<Key, Value> M) { for (auto itr = begin(M); itr != end(M); ++itr) { s << itr->first << ":" << itr->second; } return s; } constexpr int n[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> A(M); REP(i, M) cin >> A[i]; vector<string> dp(N + 1, ""); REP(i, M) { FOR(j, i + 1, M) { if (n[A[i] - 1] == n[A[j] - 1]) { int m = max(A[i], A[j]); A[i] = m; A[j] = m; } } } UNIQ(A); for (int num : A) { dp[n[num - 1]] = max(dp[n[num - 1]], to_string(num)); } FOR(i, 1, N + 1) { for (int num : A) { if (i >= n[num - 1]) { string a; if (dp[i - n[num - 1]] != "") a = max(dp[i - n[num - 1]] + to_string(num), to_string(num) + dp[i - n[num - 1]]); else a = ""; dp[i] = max(dp[i], a, [](string l, string r) { return (l.size() < r.size() || (l.size() == r.size() && l < r)); }); } } } cout << dp[N] << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (long long i = 0; i < (n); i++) #define FOR(i, a, b) for (long long i = (a); i < (b); i++) #define dump(x) cerr << #x << " => " << (x) << endl #define MIN(vec) *min_element(vec.begin(), vec.end()) #define MAX(vec) *max_element(vec.begin(), vec.end()) #define UNIQ(vec) \ vec.erase(unique(vec.begin(), vec.end()), vec.end()) // ソートの必要あり #define IN(n, m) (!(m.find(n) == m.end())) #define FINDL(vec, x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin()) #define FINDU(vec, x) (upper_bound(vec.begin(), vec.end(), x) - vec.begin()) #define EQ(a, b) (abs(a - b) < 1e-10) using namespace std; typedef long long LL; constexpr int dx[4] = {0, 1, 0, -1}; constexpr int dy[4] = {1, 0, -1, 0}; constexpr long double pi = M_PI; constexpr double eps = 1e-10; constexpr long mod = 1000000007; // LONG_MAX,LLONG_MAX template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template <class Key, class Value> ostream &operator<<(ostream &s, map<Key, Value> M) { for (auto itr = begin(M); itr != end(M); ++itr) { s << itr->first << ":" << itr->second; } return s; } constexpr int n[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector<int> A(M); REP(i, M) cin >> A[i]; vector<string> dp(N + 1, ""); REP(i, M) { FOR(j, i + 1, M) { if (n[A[i] - 1] == n[A[j] - 1]) { int m = max(A[i], A[j]); A[i] = m; A[j] = m; } } } UNIQ(A); for (int num : A) { if (n[num - 1] <= N) dp[n[num - 1]] = max(dp[n[num - 1]], to_string(num)); } FOR(i, 1, N + 1) { for (int num : A) { if (i >= n[num - 1]) { string a; if (dp[i - n[num - 1]] != "") a = max(dp[i - n[num - 1]] + to_string(num), to_string(num) + dp[i - n[num - 1]]); else a = ""; dp[i] = max(dp[i], a, [](string l, string r) { return (l.size() < r.size() || (l.size() == r.size() && l < r)); }); } } } cout << dp[N] << endl; }
replace
67
68
67
69
0
p03128
Python
Runtime Error
inf = float("inf") N, M = map(int, input().split()) A = map(int, input().split()) C = [2, 5, 5, 4, 5, 6, 3, 7, 6] costs = {m: C[m - 1] for m in A} dp = [0] for i in range(1, N + 1): dp.append(max([dp[i - c] if i - c >= 0 else -inf for c in costs.values()]) + 1) digits = list(costs.keys()) digits = sorted(digits, reverse=True) num = N result = [] for _ in range(dp[N]): for digit in digits: if dp[num - costs[digit]] != -inf and dp[num - costs[digit]] == dp[num] - 1: result.append(str(digit)) num -= costs[digit] break print("".join(result))
inf = float("inf") N, M = map(int, input().split()) A = map(int, input().split()) C = [2, 5, 5, 4, 5, 6, 3, 7, 6] costs = {m: C[m - 1] for m in A} dp = [0] for i in range(1, N + 1): dp.append(max([dp[i - c] if i - c >= 0 else -inf for c in costs.values()]) + 1) digits = list(costs.keys()) digits = sorted(digits, reverse=True) num = N result = [] for _ in range(dp[N]): for digit in digits: if ( num >= costs[digit] and dp[num - costs[digit]] != -inf and dp[num - costs[digit]] == dp[num] - 1 ): result.append(str(digit)) num -= costs[digit] break print("".join(result))
replace
15
16
15
20
0
p03128
C++
Runtime Error
#include <bits/stdc++.h> #define rt "\n" #define sp " " #define test(n) cout << "test" << n << endl; #define fixsp(n) fixed << setprecision(n) #define defsp(n) defaultfloat << setprecision(n) #define kyopro \ ios::sync_with_stdio(false); \ cin.tie(NULL) #define MOD 1000000007 #define iikae auto & #define vector3D(K, N, M, DP) \ vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M))); #define vector4D(K, N, M, O, DP) \ vector<vector<vector<vector<ll>>>> DP( \ K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O)))); #define zenbu(a) a.begin(), a.end() #define rzenbu(a) a.rbegin(), a.rend() #define rep(i, s, N) for (ll i{s}; i < N; i++) #define rem(i, N, s) for (ll i{N}; i > s; i--) using namespace std; using ll = long long int; using ld = long double; using P = pair<ll, ll>; /* 最大公約数 */ template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } /* UnionFind */ template <typename T> struct UnionFind { vector<T> par; UnionFind(T n) : par(n, -1) {} void init(T n) { par.assign(n, -1); } T root(T x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(T x, T y) { return root(x) == root(y); } bool merge(T x, T y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; /* コンビネーション */ template <typename T> ll combpm(T N_, T C_) { const int NUM_ = 400001; static ll fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1]; if (fact[0] == 0) { inv[1] = fact[0] = factr[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i % MOD, factr[i] = factr[i - 1] * inv[i] % MOD; } if (C_ < 0 || C_ > N_) return 0; return factr[C_] * fact[N_] % MOD * factr[N_ - C_] % MOD; } /* ここからコード開始 */ int main() { kyopro; ll N, M; cin >> N >> M; vector<P> digit; vector<ll> num = {2, 5, 5, 4, 5, 6, 3, 7, 6}; rep(i, 0, M) { ll tmp; cin >> tmp; rep(i, 0, 9) { if (tmp == i + 1) digit.push_back(P(i + 1, num[i])); } } sort(zenbu(digit)); vector<string> ans(N + 1, "X"); for (auto &&j : digit) { ans[j.second] = to_string(j.first); } // test(1); // rep(i, 1, N+1){ // cout << i << sp << ans[i] << rt; // } // test(2); rep(i, 1, N + 1) { for (auto &&j : digit) { auto &figure = j.first; auto &amount = j.second; string append = ans[i] + to_string(figure); if (i + amount < N + 1 ? append.size() > ans[i + amount].size() || (append.size() == ans[i + amount].size() && append >= ans[i + amount]) : 0) { if (ans[i] != "X") ans[i + amount] = append; } } // cout << i << ": " << ans[i] << endl; } // test(3); cout << ans[N] << endl; }
#include <bits/stdc++.h> #define rt "\n" #define sp " " #define test(n) cout << "test" << n << endl; #define fixsp(n) fixed << setprecision(n) #define defsp(n) defaultfloat << setprecision(n) #define kyopro \ ios::sync_with_stdio(false); \ cin.tie(NULL) #define MOD 1000000007 #define iikae auto & #define vector3D(K, N, M, DP) \ vector<vector<vector<ll>>> DP(K, vector<vector<ll>>(N, vector<ll>(M))); #define vector4D(K, N, M, O, DP) \ vector<vector<vector<vector<ll>>>> DP( \ K, vector<vector<vector<ll>>>(N, vector<vector<ll>>(M, vector<ll>(O)))); #define zenbu(a) a.begin(), a.end() #define rzenbu(a) a.rbegin(), a.rend() #define rep(i, s, N) for (ll i{s}; i < N; i++) #define rem(i, N, s) for (ll i{N}; i > s; i--) using namespace std; using ll = long long int; using ld = long double; using P = pair<ll, ll>; /* 最大公約数 */ template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; } /* UnionFind */ template <typename T> struct UnionFind { vector<T> par; UnionFind(T n) : par(n, -1) {} void init(T n) { par.assign(n, -1); } T root(T x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(T x, T y) { return root(x) == root(y); } bool merge(T x, T y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; /* コンビネーション */ template <typename T> ll combpm(T N_, T C_) { const int NUM_ = 400001; static ll fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1]; if (fact[0] == 0) { inv[1] = fact[0] = factr[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i % MOD, factr[i] = factr[i - 1] * inv[i] % MOD; } if (C_ < 0 || C_ > N_) return 0; return factr[C_] * fact[N_] % MOD * factr[N_ - C_] % MOD; } /* ここからコード開始 */ int main() { kyopro; ll N, M; cin >> N >> M; vector<P> digit; vector<ll> num = {2, 5, 5, 4, 5, 6, 3, 7, 6}; rep(i, 0, M) { ll tmp; cin >> tmp; rep(i, 0, 9) { if (tmp == i + 1) digit.push_back(P(i + 1, num[i])); } } sort(zenbu(digit)); vector<string> ans(N + 1, "X"); for (auto &&j : digit) { if (j.second < N + 1) ans[j.second] = to_string(j.first); } // test(1); // rep(i, 1, N+1){ // cout << i << sp << ans[i] << rt; // } // test(2); rep(i, 1, N + 1) { for (auto &&j : digit) { auto &figure = j.first; auto &amount = j.second; string append = ans[i] + to_string(figure); if (i + amount < N + 1 ? append.size() > ans[i + amount].size() || (append.size() == ans[i + amount].size() && append >= ans[i + amount]) : 0) { if (ans[i] != "X") ans[i + amount] = append; } } // cout << i << ": " << ans[i] << endl; } // test(3); cout << ans[N] << endl; }
replace
84
85
84
86
0
p03128
C++
Runtime Error
/*#include <iostream> #include <algorithm> #include <array> #include <cmath> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> */ #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; const ll INF = LLONG_MAX - 100; const ll mod = 1e9 + 7; const int MAX_N = 5e5 + 5; int dx[] = {-1LL, 0, 1LL, 0}, dy[] = {0, 1LL, 0, -1LL}; vector<ll> prime; ll inv[MAX_N], fac[MAX_N]; template <class T = ll> T in() { T x; cin >> x; return (x); } inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); } inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c % mod; } a = a * a % mod; b >>= 1LL; } return c; } inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i % mod; } for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } } inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod) * inv[n - r] % mod; } inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } typedef pair<int, pair<int, int>> edge; class UnionFind { private: vector<int> par; public: UnionFind(int N) { par = vector<int>(N, -1LL); } int find(int x); ll size(int x); void unite(int x, int y); bool same(int x, int y); }; class Kruskal { private: UnionFind *uf; vector<edge> e; public: vector<edge> mst; Kruskal(int N) { uf = new UnionFind(N); } void add(int x, int y, ll z); void run(); }; //----UnionFind------------------------------- int UnionFind::find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } ll UnionFind::size(int x) { return -par[find(x)]; } void UnionFind::unite(int x, int y) { x = find(x); y = find(y); // 大きい方に小さい方をくっ付ける if (size(x) < size(y)) swap(x, y); par[x] += par[y]; par[y] = x; } bool UnionFind::same(int x, int y) { x = find(x); y = find(y); return x == y; } //----Kruskal------------------------------- void Kruskal::add(int x, int y, ll z) { // x < y if (x > y) swap(x, y); e.push_back({z, {x, y}}); } void Kruskal::run() { sort(e.begin(), e.end()); e.erase(unique(e.begin(), e.end()), e.end()); for (auto x : e) { if (uf->same(x.second.first, x.second.second)) { continue; } else { mst.push_back(x); uf->unite(x.second.first, x.second.second); } } } string chmax(string A, string B) { if (A.size() < B.size()) swap(A, B); if (A.size() == B.size()) return max(A, B); else return A; } string dp[1005]; signed main() { int n, m; cin >> n >> m; int a[m]; int koho[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; REP(i, m) cin >> a[i]; REP(i, n + 1) { REP(j, m) { int syohi = koho[a[j] - 1]; if (i + syohi <= n && (dp[i] != "" || i == 0)) { string next = max(dp[i] + to_string(a[j]), to_string(a[j]) + dp[i]); dp[i + syohi] = chmax(dp[i + syohi], next); } } } cout << dp[n] << endl; }
/*#include <iostream> #include <algorithm> #include <array> #include <cmath> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> */ #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define F first #define S second #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; const ll INF = LLONG_MAX - 100; const ll mod = 1e9 + 7; const int MAX_N = 5e5 + 5; int dx[] = {-1LL, 0, 1LL, 0}, dy[] = {0, 1LL, 0, -1LL}; vector<ll> prime; ll inv[MAX_N], fac[MAX_N]; template <class T = ll> T in() { T x; cin >> x; return (x); } inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; } return a; } inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); } inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c % mod; } a = a * a % mod; b >>= 1LL; } return c; } inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i % mod; } for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } } inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod) * inv[n - r] % mod; } inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; } for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } } typedef pair<int, pair<int, int>> edge; class UnionFind { private: vector<int> par; public: UnionFind(int N) { par = vector<int>(N, -1LL); } int find(int x); ll size(int x); void unite(int x, int y); bool same(int x, int y); }; class Kruskal { private: UnionFind *uf; vector<edge> e; public: vector<edge> mst; Kruskal(int N) { uf = new UnionFind(N); } void add(int x, int y, ll z); void run(); }; //----UnionFind------------------------------- int UnionFind::find(int x) { if (par[x] < 0) return x; else return par[x] = find(par[x]); } ll UnionFind::size(int x) { return -par[find(x)]; } void UnionFind::unite(int x, int y) { x = find(x); y = find(y); // 大きい方に小さい方をくっ付ける if (size(x) < size(y)) swap(x, y); par[x] += par[y]; par[y] = x; } bool UnionFind::same(int x, int y) { x = find(x); y = find(y); return x == y; } //----Kruskal------------------------------- void Kruskal::add(int x, int y, ll z) { // x < y if (x > y) swap(x, y); e.push_back({z, {x, y}}); } void Kruskal::run() { sort(e.begin(), e.end()); e.erase(unique(e.begin(), e.end()), e.end()); for (auto x : e) { if (uf->same(x.second.first, x.second.second)) { continue; } else { mst.push_back(x); uf->unite(x.second.first, x.second.second); } } } string chmax(string A, string B) { if (A.size() < B.size()) swap(A, B); if (A.size() == B.size()) return max(A, B); else return A; } string dp[10020]; signed main() { int n, m; cin >> n >> m; int a[m]; int koho[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6}; REP(i, m) cin >> a[i]; REP(i, n + 1) { REP(j, m) { int syohi = koho[a[j] - 1]; if (i + syohi <= n && (dp[i] != "" || i == 0)) { string next = max(dp[i] + to_string(a[j]), to_string(a[j]) + dp[i]); dp[i + syohi] = chmax(dp[i + syohi], next); } } } cout << dp[n] << endl; }
replace
174
175
174
175
0
p03128
Python
Runtime Error
""" Match Matching 提出 #4299735 を参考に作成 """ def solve(): # 初期値の設定 num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] N, M = map(int, input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) # 丁度n本で作成できる最大桁数を格納する. # 初期値は -inf (丁度使い切ることは不可能) としておく dp = [-1 * float("inf")] * (N + 1) # 動的計画法で丁度n本のマッチを使うときに作れる最大桁数を計算する for n in range(1, N + 1): for a in A: if n - num[a] >= 0: # マッチがnum[a]本あるときにaが作れるなら, # n - num[a]本の時よりも1桁多く作れるはず. # これをすべてのAに対して行い、その中で最大となった桁数を求める. dp[n] = max(dp[n], dp[n - num[a]] + 1) # print('各本数丁度で作れる最大桁数') # print(dp) # 回答となる数値を算出 ans = "" for i in range(dp[N]): # dp[N]桁の数を上位の桁から決定していく for a in A: # num[a]本使って数を作ったとき, # N - num[a] 本で作れる桁数よりも N 本で作れる桁数のほうが1多い場合, # numを作っても最終的に作れる数の桁数は変わらない. # そのため dp[N] - 1 == dp[N - num[a]] を満たすような最大のAを作り, # 作成する数の上位桁に使用すればよい. # 同じ本数のマッチを使用する場合はより大きい数を採用する. # そのためAはあらかじめ降順にソートしておく. # 最初の条件で配列外アクセスを防ぐ if N - num[a] > -1 and dp[N] - 1 == dp[N - num[a]]: ans += str(a) N -= num[a] break # print('現在の残本数', N, '採用された数', a) print(ans) if __name__ == "__main__": solve()
""" Match Matching 提出 #4299735 を参考に作成 """ def solve(): # 初期値の設定 num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] N, M = map(int, input().split()) A = [int(i) for i in input().split()] A.sort(reverse=True) # 丁度n本で作成できる最大桁数を格納する. # 初期値は -inf (丁度使い切ることは不可能) としておく dp = [-1 * float("inf")] * (N + 1) # 動的計画法で丁度n本のマッチを使うときに作れる最大桁数を計算する dp[0] = 0 for n in range(1, N + 1): for a in A: if n - num[a] >= 0: # マッチがnum[a]本あるときにaが作れるなら, # n - num[a]本の時よりも1桁多く作れるはず. # これをすべてのAに対して行い、その中で最大となった桁数を求める. dp[n] = max(dp[n], dp[n - num[a]] + 1) # print('各本数丁度で作れる最大桁数') # print(dp) # 回答となる数値を算出 ans = "" for i in range(dp[N]): # dp[N]桁の数を上位の桁から決定していく for a in A: # num[a]本使って数を作ったとき, # N - num[a] 本で作れる桁数よりも N 本で作れる桁数のほうが1多い場合, # numを作っても最終的に作れる数の桁数は変わらない. # そのため dp[N] - 1 == dp[N - num[a]] を満たすような最大のAを作り, # 作成する数の上位桁に使用すればよい. # 同じ本数のマッチを使用する場合はより大きい数を採用する. # そのためAはあらかじめ降順にソートしておく. # 最初の条件で配列外アクセスを防ぐ if N - num[a] > -1 and dp[N] - 1 == dp[N - num[a]]: ans += str(a) N -= num[a] break # print('現在の残本数', N, '採用された数', a) print(ans) if __name__ == "__main__": solve()
insert
17
17
17
18
TypeError: 'float' object cannot be interpreted as an integer
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03128/Python/s934603439.py", line 50, in <module> solve() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03128/Python/s934603439.py", line 30, in solve for i in range(dp[N]): # dp[N]桁の数を上位の桁から決定していく TypeError: 'float' object cannot be interpreted as an integer
p03128
Python
Runtime Error
#!/usr/bin/env python3 N, M = map(int, input().split()) A = sorted(map(int, input().split()), reverse=True) inf = float("inf") num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] dp = [0] + [-inf] * N for i in range(N + 1)[1::]: for x in A: if i >= num[x]: dp[i] = max(dp[i], dp[i - num[x]] + 1) ans = "" while N > 0: for x in A: if dp[N - num[x]] == dp[N] - 1: ans += str(x) N -= num[x] break print(ans)
#!/usr/bin/env python3 N, M = map(int, input().split()) A = sorted(map(int, input().split()), reverse=True) inf = float("inf") num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] dp = [0] + [-inf] * N for i in range(N + 1)[1::]: for x in A: if i >= num[x]: dp[i] = max(dp[i], dp[i - num[x]] + 1) ans = "" while N > 0: for x in A: if N >= num[x] and dp[N - num[x]] == dp[N] - 1: ans += str(x) N -= num[x] break print(ans)
replace
15
16
15
16
0
p03128
Python
Runtime Error
num_A = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() A.reverse() INF = 10**6 dp = [-INF for i in range(N + 1)] # get the max digit size using i matches dp[0] = 0 for i in range(1, N + 1): next_num = [Ai for Ai in A if num_A[Ai] <= i] if next_num != []: dpi_candidate = [dp[i - num_A[next_numi]] + 1 for next_numi in next_num] dp[i] = max(dpi_candidate) remain_match = N ans = "0" while remain_match > 0: for Ai in A: if dp[remain_match - num_A[Ai]] == dp[remain_match] - 1: ans += str(Ai) remain_match -= num_A[Ai] break print(int(ans[1:]))
num_A = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort() A.reverse() INF = 10**6 dp = [-INF for i in range(N + 1)] # get the max digit size using i matches dp[0] = 0 for i in range(1, N + 1): next_num = [Ai for Ai in A if num_A[Ai] <= i] if next_num != []: dpi_candidate = [dp[i - num_A[next_numi]] + 1 for next_numi in next_num] dp[i] = max(dpi_candidate) remain_match = N ans = "0" while remain_match > 0: for Ai in A: if ( remain_match >= num_A[Ai] and dp[remain_match - num_A[Ai]] == dp[remain_match] - 1 ): ans += str(Ai) remain_match -= num_A[Ai] break print(int(ans[1:]))
replace
19
20
19
23
0
p03128
Python
Runtime Error
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, m = map(int, readline().split()) a = list(map(int, readline().split())) memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] dp = [""] * (n + 1) for aa in a: if aa <= n: if dp[memo[aa]] < str(aa): dp[memo[aa]] = str(aa) for i in range(n): if dp[i] == "": continue for aa in a: if i + memo[aa] <= n: v = str(aa) + dp[i] if len(dp[i + memo[aa]]) < len(v): dp[i + memo[aa]] = v else: dp[i + memo[aa]] = max(dp[i + memo[aa]], v) print(dp[-1])
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, m = map(int, readline().split()) a = list(map(int, readline().split())) memo = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] dp = [""] * (n + 1) for aa in a: if memo[aa] <= n: dp[memo[aa]] = max(dp[memo[aa]], str(aa)) for i in range(n): if dp[i] == "": continue for aa in a: if i + memo[aa] <= n: v = str(aa) + dp[i] if len(dp[i + memo[aa]]) < len(v): dp[i + memo[aa]] = v else: dp[i + memo[aa]] = max(dp[i + memo[aa]], v) print(dp[-1])
replace
12
15
12
14
0
p03128
Python
Runtime Error
f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] n, m = map(int, input().split()) a = list(map(int, input().split())) memo = ["-1"] * 10100 def MAX(x, y): if y[0] != "#" and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)): return y else: return x def dp(i): # i本のマッチを使って作れる最大の整数 if i < 0: return "#" if memo[i] != "-1": return memo[i] if i == 0: return "" ret = "#" for x in a: ret = MAX(ret, dp(i - f[x]) + str(x)) memo[i] = ret return ret print(dp(n))
import resource import sys sys.setrecursionlimit(20000) f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] n, m = map(int, input().split()) a = list(map(int, input().split())) memo = ["-1"] * 10100 def MAX(x, y): if y[0] != "#" and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)): return y else: return x def dp(i): # i本のマッチを使って作れる最大の整数 if i < 0: return "#" if memo[i] != "-1": return memo[i] if i == 0: return "" ret = "#" for x in a: ret = MAX(ret, dp(i - f[x]) + str(x)) memo[i] = ret return ret print(dp(n))
insert
0
0
0
4
0
p03128
Python
Runtime Error
n, m = map(int, input().split()) a = list(map(int, input().split())) dp = dict.fromkeys(range(n + 1)) # dp[n]: n本使うときの桁数 dp[0] = 0 num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} anum = sorted( dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True ) # 後の計算用にsortしておく for i in range(n): dp[i + 1] = dp[i] for e in anum: if i + 1 - e[1] >= 0: dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1) ans = "" while dp[n] > 1: for e in anum: # anum は降順sortされているので, 大きい順に確認 if n - e[1] >= 0: if dp[n - e[1]] == dp[n] - 1: ans += str(e[0]) n -= e[1] break # 末尾桁は n =0(ちょうど使い切るように決定) ans += str(list(filter(lambda e: e[1] == n, anum))[0][0]) print(ans)
n, m = map(int, input().split()) a = list(map(int, input().split())) dp = dict.fromkeys(range(n + 1)) # dp[n]: n本使うときの桁数 dp[0] = 0 num = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} anum = sorted( dict(filter(lambda e: e[0] in a, num.items())).items(), reverse=True ) # 後の計算用にsortしておく for i in range(n): dp[i + 1] = -float("inf") for e in anum: if i + 1 - e[1] >= 0: dp[i + 1] = max(dp[i + 1], dp[i + 1 - e[1]] + 1) ans = "" while dp[n] > 1: for e in anum: # anum は降順sortされているので, 大きい順に確認 if n - e[1] >= 0: if dp[n - e[1]] == dp[n] - 1: ans += str(e[0]) n -= e[1] break # 末尾桁は n =0(ちょうど使い切るように決定) ans += str(list(filter(lambda e: e[1] == n, anum))[0][0]) print(ans)
replace
12
13
12
13
0
p03128
Python
Runtime Error
N, M = map(int, input().split()) A = [int(x) for x in input().split()] f = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} A = sorted(A, reverse=True) dp = [float("-inf")] * (N + 1) dp[0] = 0 for i in range(N + 1): for a in A: if i - f[a] >= 0: dp[i] = max(dp[i], dp[i - f[a]] + 1) ans = "" num, digit = N, dp[N] while num > 0: for a in A: if dp[num - f[a]] == digit - 1: ans += str(a) num -= f[a] digit -= 1 break print(ans)
N, M = map(int, input().split()) A = [int(x) for x in input().split()] f = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6} A = sorted(A, reverse=True) dp = [float("-inf")] * (N + 1) dp[0] = 0 for i in range(N + 1): for a in A: if i - f[a] >= 0: dp[i] = max(dp[i], dp[i - f[a]] + 1) ans = "" num, digit = N, dp[N] while num > 0: for a in A: i = num - f[a] if i >= 0 and dp[i] == digit - 1: ans += str(a) num -= f[a] digit -= 1 break print(ans)
replace
17
18
17
19
0
p03128
Python
Runtime Error
# -*- coding: utf-8 -*- N, M = map(int, input().split()) A = list(map(int, input().split())) cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] cd = [(a, cost[a]) for a in A] cd.sort(key=lambda x: x[0], reverse=True) dp = [0] + [-1] * N for i in range(1, N + 1): for a, c in cd: if i - c >= 0 and 0 <= dp[i - c]: dp[i] = max(dp[i], dp[i - c] + 1) ans, i = [], N for _ in range(dp[-1]): for a, c in cd: if dp[i - c] == dp[i] - 1: ans.append(a) i = i - c break print("".join(map(str, ans)))
# -*- coding: utf-8 -*- N, M = map(int, input().split()) A = list(map(int, input().split())) cost = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] cd = [(a, cost[a]) for a in A] cd.sort(key=lambda x: x[0], reverse=True) dp = [0] + [-1] * N for i in range(1, N + 1): for a, c in cd: if i - c >= 0 and 0 <= dp[i - c]: dp[i] = max(dp[i], dp[i - c] + 1) ans, i = [], N for _ in range(dp[-1]): for a, c in cd: if i - c >= 0 and dp[i - c] == dp[i] - 1: ans.append(a) i = i - c break print("".join(map(str, ans)))
replace
18
19
18
19
0
p03128
C++
Runtime Error
#if 1 #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <cmath> #include <cstdint> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> auto &in = std::cin; auto &out = std::cout; #define all_range(C) std::begin(C), std::end(C) const double PI = 3.141592653589793238462643383279502884197169399375105820974944; bool able[10]; const int use[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; std::pair<int32_t, std::string> dp[10000]; const std::pair<int32_t, std::string> &func(int i) { if (i == 0) { dp[i].first = 0; return dp[i]; } if (dp[i].first != -1) { return dp[i]; } char add = '0'; for (size_t n = 1; n < 10; n++) { if (able[n] && i >= use[n]) { const auto &next = func(i - use[n]); if (next.first < 0) { continue; } if (dp[i].first <= next.first) { dp[i] = next; add = '0' + n; } } } if (add != '0') { dp[i].first += 1; dp[i].second = add + dp[i].second; } return dp[i]; } template <typename T, typename U> std::enable_if_t<std::rank<T>::value == 0> fill_all(T &arr, const U &v) { arr = v; } template <typename ARR, typename U> std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR &arr, const U &v) { for (auto &i : arr) { fill_all(i, v); } } int main() { fill_all(dp, std::pair<int32_t, std::string>{-1, ""}); using std::endl; in.sync_with_stdio(false); out.sync_with_stdio(false); in.tie(nullptr); out.tie(nullptr); int32_t N, M; in >> N >> M; for (size_t i = 0; i < M; i++) { int v; in >> v; able[v] = true; } out << func(N).second << endl; return 0; } #endif
#if 1 #include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <cmath> #include <cstdint> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> auto &in = std::cin; auto &out = std::cout; #define all_range(C) std::begin(C), std::end(C) const double PI = 3.141592653589793238462643383279502884197169399375105820974944; bool able[10]; const int use[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6}; std::pair<int32_t, std::string> dp[11000]; const std::pair<int32_t, std::string> &func(int i) { if (i == 0) { dp[i].first = 0; return dp[i]; } if (dp[i].first != -1) { return dp[i]; } char add = '0'; for (size_t n = 1; n < 10; n++) { if (able[n] && i >= use[n]) { const auto &next = func(i - use[n]); if (next.first < 0) { continue; } if (dp[i].first <= next.first) { dp[i] = next; add = '0' + n; } } } if (add != '0') { dp[i].first += 1; dp[i].second = add + dp[i].second; } return dp[i]; } template <typename T, typename U> std::enable_if_t<std::rank<T>::value == 0> fill_all(T &arr, const U &v) { arr = v; } template <typename ARR, typename U> std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR &arr, const U &v) { for (auto &i : arr) { fill_all(i, v); } } int main() { fill_all(dp, std::pair<int32_t, std::string>{-1, ""}); using std::endl; in.sync_with_stdio(false); out.sync_with_stdio(false); in.tie(nullptr); out.tie(nullptr); int32_t N, M; in >> N >> M; for (size_t i = 0; i < M; i++) { int v; in >> v; able[v] = true; } out << func(N).second << endl; return 0; } #endif
replace
33
34
33
34
0
p03128
Python
Runtime Error
import sys mp = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] if __name__ == "__main__": n, m = map(int, input().split()) a = sorted(input().split(), reverse=True) dp = [-10007] * (n + 1) dp[0] = 0 for i in a: step = mp[int(i)] for j in range(step, n + 1): dp[j] = max(dp[j - step] + 1, dp[j]) i = n while i > 0: for x in a: step = mp[int(x)] if dp[i - step] == dp[i] - 1: sys.stdout.write(x) i -= step break print()
import sys mp = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6] if __name__ == "__main__": n, m = map(int, input().split()) a = sorted(input().split(), reverse=True) dp = [-10007] * (n + 1) dp[0] = 0 for i in a: step = mp[int(i)] for j in range(step, n + 1): dp[j] = max(dp[j - step] + 1, dp[j]) i = n while i > 0: for x in a: step = mp[int(x)] if i >= step and dp[i - step] == dp[i] - 1: sys.stdout.write(x) i -= step break print()
replace
19
20
19
20
0