Submission #1109314

#TimeUsernameProblemLanguageResultExecution timeMemory
1109314Kirill22Brunhilda’s Birthday (BOI13_brunhilda)C++17
100 / 100
168 ms80796 KiB
#include "bits/stdc++.h" using namespace std; const int N = (int) 1e7 + 22, inf = (int) 1e9; int dp[N], mx[N]; void solve() { fill(dp, dp + N, inf); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; for (int j = a[i]; j < N; j += a[i]) { mx[j - 1] = max(mx[j - 1], a[i] - 1); } mx[N - 1] = max(mx[N - 1], (N - 1) % a[i]); } for (int i = N - 1; i > 0; i--) { mx[i] = max(mx[i], mx[i + 1] - 1); } dp[0] = 0; for (int i = 1; i < N; i++) { if (!mx[i]) { continue; } dp[i] = min(inf, dp[i - mx[i]] + 1); } while (q--) { int x; cin >> x; if (dp[x] == inf) { cout << "oo\n"; } else { cout << dp[x] << '\n'; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...