Submission #447944

#TimeUsernameProblemLanguageResultExecution timeMemory
447944prvocisloBrunhilda’s Birthday (BOI13_brunhilda)C++17
100 / 100
888 ms123724 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int maxn = 1e7 + 5, inf = 1e9 + 5; void chmin(int &a, const int &b) { a = min(a, b); } void chmax(int &a, const int &b) { a = max(a, b); } int main() { ios::sync_with_stdio(false); cin.tie(0); vector<int> lp(maxn, -1), pr; for (int i = 2; i < maxn; i++) { if (lp[i] == -1) pr.push_back(i), lp[i] = i; for (int j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < maxn; j++) lp[i*pr[j]] = pr[j]; } int m, q; cin >> m >> q; vector<int> p(m); vector<bool> b(maxn, false); int mul = 1; for (int i = 0; i < m; i++) { cin >> p[i]; if (mul * 1ll * p[i] < (ll)maxn) mul *= p[i]; else mul = maxn; b[p[i]] = true; } vector<int> dp(maxn, inf), hr(maxn+1, 0); for (int i = 0; i < mul; i++) { if (!i) dp[i] = 0; else { if (i <= hr[dp[i-1]]) dp[i] = dp[i-1]; else dp[i] = dp[i-1]+1; } int big = 1; if (!i) big = p.back(); for (int j = i; j > 1; j /= lp[j]) if (b[lp[j]]) chmax(big, lp[j]); if (big != 1) { chmax(hr[dp[i]+1], i+big-1); } } while (q--) { int n; cin >> n; if (dp[n] == inf) cout << "oo\n"; else cout << dp[n] << "\n"; } return 0; }

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:16:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         for (int j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] < maxn; j++)
      |                         ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...