Submission #522430

#TimeUsernameProblemLanguageResultExecution timeMemory
522430Hamed5001Brunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
238 ms79172 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 1e7+1; int dp[mxN], dp2[mxN]; void solve() { int M, Q; cin >> M >> Q; vector<int> primes(M); for (auto &a : primes) cin >> a; for (auto p : primes) { for (int i = p; i <= mxN; i += p) { dp2[i - 1] = max(dp2[i - 1], p - 1); } dp2[mxN - 1] = max(dp2[mxN - 1], (mxN - 1) % p); } for (int i = mxN - 2; i >= 0; --i) { dp2[i] = max(dp2[i], dp2[i + 1] - 1); } dp[0] = 0; for (int i = 1; i < mxN; ++i) { dp[i] = 1e9; dp[i] = dp[i - dp2[i]] + 1; } while(Q--) { int n; cin >> n; int ans = dp[n]; if (ans >= 1e9) cout << "oo\n"; else cout << ans << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...