# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1069167 | ortsac | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 12 ms | 4160 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define fr first
#define se second
int inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1e4;
int dp[MAXN + 10];
priority_queue<pii> pq;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
pq.push({0, a});
}
for (int i = 1; i <= MAXN; i++) {
dp[i] = inf;
while ((pq.top().se - pq.top().fr) <= i) {
auto u = pq.top();
pq.pop();
pq.push({u.fr - u.se, u.se});
}
dp[i] = min(dp[i], dp[-pq.top().fr] + 1);
}
while (q--) {
int x;
cin >> x;
if (dp[x] == inf) cout << "oo\n";
else cout << dp[x] << "\n";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |