Submission #155750

#TimeUsernameProblemLanguageResultExecution timeMemory
155750souhhcongBrunhilda’s Birthday (BOI13_brunhilda)C++14
78.10 / 100
801 ms79504 KiB
#include <iostream> #include <string.h> using namespace std; const int N = 1e5+5, MAXN = 1e7+7, INF = 1e9+9; int n, q, x, p[N], dp[MAXN], mx[MAXN]; int main() { cin >> n >> q; for (int i = 0; i < n; i++) { cin >> p[i]; for (int j = p[i]-1; j < MAXN; j += p[i]) { mx[j] = max(mx[j], p[i]-1); } } for (int i = MAXN - 2; i >= 0; i--) mx[i] = max(mx[i], mx[i+1]-1); for (int i = 1; i < MAXN; i++) { if (mx[i] > 0) dp[i] = 1 + dp[i-mx[i]]; else dp[i] = INF; } while(q--) { cin >> x; if (dp[x] == INF) cout << "oo\n"; else cout << dp[x] << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...