This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MAXN 10000001
typedef long long ll;
using namespace std;
ll dp[MAXN];
int main() {
iostream::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
deque<pair<int, int>> dq;
FOR(i, 0, n) {
int k;
cin >> k;
dq.push_back({k, k});
}
dp[0] = 0;
FOR(i, 1, MAXN) {
dp[i] = INT_MAX;
for (int j = 0; j < n && i == dq.front().first; j++) {
int c, k;
tie(c, k) = dq.front();
dq.pop_front();
while (c < dq.back().first) c += k;
dq.push_back({c, k});
}
dp[i] = dp[i - (i % dq.front().second)] + 1;
}
FOR(i, 0, q) {
int x;
cin >> x;
if (dp[x] >= INT_MAX) cout << "oo\n";
else cout << dp[x] << '\n';
}
return 0;
}
Compilation message (stderr)
brunhilda.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
#pragma GCC Optimize("O3")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |