# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
644511 | 2022-09-24T18:32:30 Z | GusterGoose27 | Strongbox (POI11_sej) | C++11 | 171 ms | 26124 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, char> pii; const ll MAXN = 1e14; const int MAXK = 25e4; const int MAXF = 2e4; 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; bitset<(int) sqrt(MAXN)+1> is_prime; vector<pii> kfactored; vector<char> factorizations[MAXK-1]; int state[MAXF]; // 0 unvisited, 2 descended from k, 1 blocked ll val[MAXF]; int hshs[MAXK]; vector<int> coeffs; 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) { // 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) { kfactored.push_back(pii(primes[i], c)); } } if (target != 1) { kfactored.push_back(pii(target, 1)); } } void factorize(ll target, vector<char> &factored) { // prime for (int i = 0; i < kfactored.size(); i++) { int c = 0; while (target % kfactored[i].first == 0) { target /= kfactored[i].first; c++; } factored.push_back(c); } } void make_coeffs() { int mult = 1; for (int i = 0; i < kfactored.size(); i++) { coeffs.push_back(mult); mult *= (kfactored[i].second+1); } } int hsh(vector<char> &factored) { int r = 0; for (int i = 0; i < factored.size(); i++) { r += factored[i]*coeffs[i]; } mxh = max(mxh, r); return r; } int hsh(vector<pii> &factored) { int r = 0; for (int i = 0; i < factored.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]); if (elems[k-1] == 0) elems[k-1] = n; make_primes((int) sqrt(n)); factorize(elems[k-1]); make_coeffs(); hshs[k-1] = hsh(kfactored); state[hshs[k-1]] = 2; val[hshs[k-1]] = elems[k-1]; for (int i = 0; i < k-1; i++) { factorize(elems[i], factorizations[i]); hshs[i] = hsh(factorizations[i]); state[hshs[i]] = 1; val[hshs[i]] = elems[i]; } assert(mxh < MAXF); 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 < kfactored.size(); p++) { int v = i/coeffs[p]; if (v % (kfactored[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]/kfactored[p].first; state[nxt] = state[i]; } } assert(ans > 0); cout << ans << "\n"; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 4 ms | 7380 KB | Output is correct |
3 | Correct | 3 ms | 7380 KB | Output is correct |
4 | Correct | 4 ms | 7380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 4 ms | 7380 KB | Output is correct |
3 | Correct | 4 ms | 7380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7380 KB | Output is correct |
2 | Correct | 4 ms | 7380 KB | Output is correct |
3 | Correct | 4 ms | 7380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 7508 KB | Output is correct |
2 | Correct | 4 ms | 7636 KB | Output is correct |
3 | Correct | 5 ms | 7508 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 8488 KB | Output is correct |
2 | Correct | 9 ms | 8532 KB | Output is correct |
3 | Correct | 9 ms | 8572 KB | Output is correct |
4 | Correct | 12 ms | 8532 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 11596 KB | Output is correct |
2 | Correct | 41 ms | 11548 KB | Output is correct |
3 | Correct | 61 ms | 15680 KB | Output is correct |
4 | Correct | 45 ms | 11688 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 9564 KB | Output is correct |
2 | Correct | 46 ms | 15712 KB | Output is correct |
3 | Correct | 62 ms | 15772 KB | Output is correct |
4 | Correct | 35 ms | 11624 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 11644 KB | Output is correct |
2 | Correct | 54 ms | 15740 KB | Output is correct |
3 | Correct | 66 ms | 15724 KB | Output is correct |
4 | Correct | 43 ms | 11716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 15680 KB | Output is correct |
2 | Correct | 57 ms | 15772 KB | Output is correct |
3 | Correct | 62 ms | 15728 KB | Output is correct |
4 | Correct | 56 ms | 15736 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 11596 KB | Output is correct |
2 | Correct | 56 ms | 15744 KB | Output is correct |
3 | Correct | 62 ms | 15736 KB | Output is correct |
4 | Correct | 60 ms | 15740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 89 ms | 16564 KB | Output is correct |
2 | Correct | 96 ms | 16852 KB | Output is correct |
3 | Correct | 97 ms | 16996 KB | Output is correct |
4 | Correct | 121 ms | 19180 KB | Output is correct |
5 | Correct | 100 ms | 17004 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 108 ms | 19172 KB | Output is correct |
2 | Correct | 149 ms | 21096 KB | Output is correct |
3 | Correct | 114 ms | 19604 KB | Output is correct |
4 | Correct | 110 ms | 18576 KB | Output is correct |
5 | Correct | 139 ms | 21168 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 102 ms | 20284 KB | Output is correct |
2 | Correct | 168 ms | 23260 KB | Output is correct |
3 | Correct | 149 ms | 23084 KB | Output is correct |
4 | Correct | 154 ms | 25976 KB | Output is correct |
5 | Correct | 160 ms | 26088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 135 ms | 23048 KB | Output is correct |
2 | Correct | 171 ms | 23272 KB | Output is correct |
3 | Correct | 156 ms | 23316 KB | Output is correct |
4 | Correct | 154 ms | 26124 KB | Output is correct |
5 | Correct | 151 ms | 26056 KB | Output is correct |