Submission #1005419

#TimeUsernameProblemLanguageResultExecution timeMemory
1005419tvladm2009Brunhilda’s Birthday (BOI13_brunhilda)C++17
100 / 100
121 ms80232 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int V = 1e7; int nxt[V + 7], dp[V + 7]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; for (int i = 1; i <= n; ++i) { int x; cin >> x; for (int j = x; j - 1 <= V; j += x) { nxt[j - 1] = x - 1; } nxt[V] = max(nxt[V], V % x); } for (int i = V; i >= 1; --i) { nxt[i] = max(nxt[i], nxt[i + 1] - 1); } for (int i = 1; i <= V; ++i) { if (nxt[i] == 0 || dp[i - nxt[i]] == -1) { dp[i] = -1; } else { dp[i] = dp[i - nxt[i]] + 1; } } while (q--) { ll x; cin >> x; if (dp[x] < 0) { cout << "oo\n"; } else { cout << dp[x] << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...