Submission #522428

#TimeUsernameProblemLanguageResultExecution timeMemory
522428Hamed5001Brunhilda’s Birthday (BOI13_brunhilda)C++14
76.35 / 100
267 ms80688 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); } } 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 << dp[n] << '\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...