# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
209935 | dantoh000 | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 332 ms | 87800 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.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int MAXN = 11000000;
int a[MAXN];
int ans[MAXN];
int main(){
int n,q;
scanf("%d%d",&n,&q);
for (int i = 0; i < n; i++){
int k;
scanf("%d",&k);
for (int j = k-1; j < MAXN; j+=k){
a[j] = k-1;
}
}
for (int i = MAXN-2; i >= 0; i--){
a[i] = max(a[i],a[i+1]-1);
}
fill(ans,ans+MAXN,INF);
ans[1] = 1;
ans[0] = 0;
for (int i = 2; i < MAXN; i++){
if (a[i] == 0) ans[i] = INF;
else ans[i] = min(ans[i],ans[i-a[i]]+1);
}
for (int i = 0; i < q; i++){
int x;
scanf("%d",&x);
if (ans[x] == INF) printf("oo\n");
else printf("%d\n",ans[x]);
}
}
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... |