Submission #58741

# Submission time Handle Problem Language Result Execution time Memory
58741 2018-07-19T06:02:56 Z Batrr Brunhilda’s Birthday (BOI13_brunhilda) C++14
100 / 100
790 ms 117988 KB
#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long                   
#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 
#define IOS ios_base::sync_with_stdio(0);

using namespace std;                    

const ll maxn=2e5+123,inf=1e18,mod=1e9+7,N=1e7+12,LOG=20;
int n,q,a[maxn],ans[N],cur,pos,nxt,nxtval,mx[N];
int main(){
    #ifdef LOCAL
        freopen ("test.in", "r", stdin);
    #endif
    cin>>n>>q;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<N;j+=a[i])
            mx[j]=max(mx[j],a[i]);
    }
    for(int i=0;i<N;i++)
        ans[i]=-1;
    ans[0]=0;
    cur=mx[0];
    pos=1;
    nxt=nxtval=-1;
    while(true){
        while(pos<N && pos%cur!=0){
            ans[pos]=ans[pos/cur*cur]+1;
            if( pos+mx[pos]>nxt )
                nxtval=mx[pos],nxt=pos+mx[pos];
            pos++;
        }
        if(pos==N || nxtval==-1)
            break;
        cur=nxtval;
        nxt=nxtval=-1;
    }
    while(q--){
        int x;
        cin>>x;
        if(ans[x]==-1)            
            cout<<"oo"<<endl;
        else
            cout<<ans[x]<<endl;
    }

}
# Verdict Execution time Memory Grader output
1 Correct 89 ms 78584 KB Output is correct
2 Correct 172 ms 78584 KB Output is correct
3 Correct 104 ms 78792 KB Output is correct
4 Correct 168 ms 78868 KB Output is correct
5 Correct 191 ms 78984 KB Output is correct
6 Correct 109 ms 78984 KB Output is correct
7 Correct 130 ms 78984 KB Output is correct
8 Correct 140 ms 79136 KB Output is correct
9 Correct 266 ms 79152 KB Output is correct
10 Correct 294 ms 79152 KB Output is correct
11 Correct 250 ms 79192 KB Output is correct
12 Correct 169 ms 79220 KB Output is correct
13 Correct 469 ms 79220 KB Output is correct
14 Correct 413 ms 79236 KB Output is correct
15 Correct 239 ms 79236 KB Output is correct
16 Correct 190 ms 79288 KB Output is correct
17 Correct 222 ms 79288 KB Output is correct
18 Correct 178 ms 79288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 79344 KB Output is correct
2 Correct 222 ms 80432 KB Output is correct
3 Correct 536 ms 80944 KB Output is correct
4 Correct 223 ms 80944 KB Output is correct
5 Correct 344 ms 81052 KB Output is correct
6 Correct 181 ms 81052 KB Output is correct
7 Correct 166 ms 81052 KB Output is correct
8 Correct 236 ms 81052 KB Output is correct
9 Correct 454 ms 81744 KB Output is correct
10 Correct 487 ms 82404 KB Output is correct
11 Correct 507 ms 82620 KB Output is correct
12 Correct 302 ms 82620 KB Output is correct
13 Correct 187 ms 82620 KB Output is correct
14 Correct 209 ms 82620 KB Output is correct
15 Correct 356 ms 82992 KB Output is correct
16 Correct 254 ms 83744 KB Output is correct
17 Correct 452 ms 83744 KB Output is correct
18 Correct 481 ms 84436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 575 ms 84944 KB Output is correct
2 Correct 615 ms 85496 KB Output is correct
3 Correct 564 ms 86340 KB Output is correct
4 Correct 562 ms 87092 KB Output is correct
5 Correct 514 ms 88892 KB Output is correct
6 Correct 639 ms 89344 KB Output is correct
7 Correct 577 ms 90748 KB Output is correct
8 Correct 542 ms 91300 KB Output is correct
9 Correct 533 ms 91700 KB Output is correct
10 Correct 366 ms 91700 KB Output is correct
11 Correct 300 ms 91900 KB Output is correct
12 Correct 377 ms 92008 KB Output is correct
13 Correct 790 ms 93236 KB Output is correct
14 Correct 437 ms 94388 KB Output is correct
15 Correct 383 ms 94388 KB Output is correct
16 Correct 418 ms 94388 KB Output is correct
17 Correct 492 ms 94828 KB Output is correct
18 Correct 646 ms 95200 KB Output is correct
19 Correct 229 ms 95608 KB Output is correct
20 Correct 649 ms 96340 KB Output is correct
21 Correct 468 ms 97308 KB Output is correct
22 Correct 645 ms 98916 KB Output is correct
23 Correct 430 ms 99624 KB Output is correct
24 Correct 378 ms 100432 KB Output is correct
25 Correct 558 ms 101144 KB Output is correct
26 Correct 433 ms 101676 KB Output is correct
27 Correct 644 ms 103236 KB Output is correct
28 Correct 416 ms 103664 KB Output is correct
29 Correct 774 ms 105480 KB Output is correct
30 Correct 722 ms 106712 KB Output is correct
31 Correct 411 ms 107044 KB Output is correct
32 Correct 426 ms 107904 KB Output is correct
33 Correct 394 ms 108480 KB Output is correct
34 Correct 572 ms 109964 KB Output is correct
35 Correct 370 ms 110500 KB Output is correct
36 Correct 746 ms 112180 KB Output is correct
37 Correct 490 ms 113768 KB Output is correct
38 Correct 624 ms 114252 KB Output is correct
39 Correct 531 ms 115056 KB Output is correct
40 Correct 575 ms 115876 KB Output is correct
41 Correct 519 ms 117188 KB Output is correct
42 Correct 748 ms 117988 KB Output is correct