# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644486 | 2022-09-24T17:54:07 Z | GusterGoose27 | Strongbox (POI11_sej) | C++11 | 180 ms | 43244 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll MAXN = 1e14; const int MAXK = 25e4; const int MAXF = 1e5; ll n; int k; ll elems[MAXK]; ll gcd(ll a, ll b) { if (a > b) return gcd(b, a); if (a == 0) return b; return gcd(b%a, a); } vector<ll> primes; vector<ll> nprimes; bitset<(int) sqrt(MAXN)+1> is_prime; vector<pii> factorizations[MAXK]; int state[MAXF]; // 0 unvisited, 2 descended from k, 1 blocked ll val[MAXF]; int hshs[MAXK]; int coeffs[MAXK]; int mxh = 0; ll ans = 0; void make_primes(ll mx) { is_prime.set(); for (int i = 2; i <= mx; i++) { if (!is_prime[i]) continue; primes.push_back(i); for (int j = 2*i; j <= mx; j+= i) is_prime[j] = 0; } } void factorize(ll target, vector<pii> &factored) { // prime for (int i = 0; i < primes.size() && target > 1; i++) { int c = 0; while (target % primes[i] == 0) { target /= primes[i]; c++; } if (c) { factored.push_back(pii(primes[i], c)); nprimes.push_back(primes[i]); } } if (target != 1) { nprimes.push_back(target); factored.push_back(pii(target, 1)); } } void factorize2(ll target, vector<pii> &factored) { // prime for (int i = 0; i < nprimes.size(); i++) { int c = 0; while (target % nprimes[i] == 0) { target /= nprimes[i]; c++; } factored.push_back(pii(nprimes[i], c)); } } void make_coeffs() { int mult = 1; for (int i = 0; i < nprimes.size(); i++) { coeffs[i] = mult; mult *= (factorizations[k-1][i].second+1); } } int hsh(vector<pii> &factored) { int r = 0; for (int i = 0; i < nprimes.size(); i++) { r += factored[i].second*coeffs[i]; } mxh = max(mxh, r); return r; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for (int i = 0; i < k; i++) { cin >> elems[i]; } elems[k-1] = gcd(elems[k-1], n); for (int i = 0; i < k-1; i++) elems[i] = gcd(elems[i], elems[k-1]); for (int i = 0; i < k; i++) { if (elems[i] == 0) elems[i] = n; } make_primes((int) sqrt(n)); factorize(elems[k-1], factorizations[k-1]); make_coeffs(); hshs[k-1] = hsh(factorizations[k-1]); state[hshs[k-1]] = 2; val[hshs[k-1]] = elems[k-1]; for (int i = 0; i < k-1; i++) { factorize2(elems[i], factorizations[i]); hshs[i] = hsh(factorizations[i]); state[hshs[i]] = 1; val[hshs[i]] = elems[i]; } for (int i = mxh; i >= 0; i--) { if (state[i] == 0) continue; if (state[i] == 2) ans = max(ans, n/val[i]); for (int p = 0; p < nprimes.size(); p++) { int v = i/coeffs[p]; if (v % (factorizations[k-1][p].second+1) == 0) continue; int nxt = i-coeffs[p]; if (state[nxt] == 1 || (state[nxt] == 2 && state[i] == 2)) continue; val[nxt] = val[i]/nprimes[p]; state[nxt] = state[i]; } } assert(ans > 0); cout << ans << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 7380 KB | Output is correct |
2 | Correct | 4 ms | 7380 KB | Output is correct |
3 | Correct | 5 ms | 7380 KB | Output is correct |
4 | Correct | 4 ms | 7380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 3 ms | 7380 KB | Output is correct |
3 | Correct | 4 ms | 7380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 3 ms | 7380 KB | Output is correct |
3 | Correct | 4 ms | 7380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7636 KB | Output is correct |
2 | Correct | 4 ms | 7636 KB | Output is correct |
3 | Correct | 4 ms | 7508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8532 KB | Output is correct |
2 | Correct | 9 ms | 8532 KB | Output is correct |
3 | Correct | 9 ms | 8580 KB | Output is correct |
4 | Correct | 10 ms | 8532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 11660 KB | Output is correct |
2 | Correct | 43 ms | 11652 KB | Output is correct |
3 | Correct | 55 ms | 15680 KB | Output is correct |
4 | Correct | 43 ms | 11628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 9608 KB | Output is correct |
2 | Correct | 46 ms | 15736 KB | Output is correct |
3 | Correct | 62 ms | 15680 KB | Output is correct |
4 | Correct | 38 ms | 11648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 11588 KB | Output is correct |
2 | Correct | 53 ms | 15680 KB | Output is correct |
3 | Correct | 62 ms | 15744 KB | Output is correct |
4 | Correct | 45 ms | 11712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 15784 KB | Output is correct |
2 | Correct | 54 ms | 15756 KB | Output is correct |
3 | Correct | 59 ms | 15780 KB | Output is correct |
4 | Correct | 57 ms | 15740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 11636 KB | Output is correct |
2 | Correct | 59 ms | 15744 KB | Output is correct |
3 | Correct | 63 ms | 15680 KB | Output is correct |
4 | Correct | 61 ms | 15732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 83 ms | 16448 KB | Output is correct |
2 | Correct | 102 ms | 21536 KB | Output is correct |
3 | Correct | 102 ms | 27880 KB | Output is correct |
4 | Runtime error | 124 ms | 37128 KB | Memory limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 106 ms | 22140 KB | Output is correct |
2 | Correct | 155 ms | 30684 KB | Output is correct |
3 | Runtime error | 127 ms | 43244 KB | Memory limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 100 ms | 20412 KB | Output is correct |
2 | Runtime error | 180 ms | 35068 KB | Memory limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 141 ms | 26936 KB | Output is correct |
2 | Runtime error | 177 ms | 38652 KB | Memory limit exceeded |
3 | Halted | 0 ms | 0 KB | - |