Submission #493731

# Submission time Handle Problem Language Result Execution time Memory
493731 2021-12-12T17:54:49 Z _Monkey_ Brunhilda’s Birthday (BOI13_brunhilda) C++17
100 / 100
452 ms 158960 KB
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define el '\n'
#define ld long double
const int maxn=1e5+1,nn=2e7+1;
void amax(int &x,int y){if(y>x)x=y;}
int a[maxn],f[nn],ut[nn];
int m,n,q,oo=1e9,p;
bool ok;
int take(int z){
    if(f[z]>=0) return f[z];
    if(ut[z]==0){
        f[z]=oo;
    } else {
        f[z]=min(oo,take(z-ut[z])+1);
    }
    return f[z];
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> m >> q;
    for(int i=0;i<m;++i) cin >> a[i];
    sort(a+0,a+m);
    for(int i=0;i<m;++i)
        for(int j=a[i]-1;j<nn;j+=a[i]) ut[j]=a[i]-1;
    for(int i=nn-2;i>0;--i) amax(ut[i],ut[i+1]-1);
    memset(f,-1,sizeof f);
    f[0]=0;
    while(q--){
        cin >> n;
        p=take(n);
        if(p==oo){
            cout << "oo" << el;
        } else {
            cout << p << el;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 137 ms 156916 KB Output is correct
2 Correct 165 ms 156788 KB Output is correct
3 Correct 149 ms 156788 KB Output is correct
4 Correct 123 ms 156828 KB Output is correct
5 Correct 145 ms 156788 KB Output is correct
6 Correct 136 ms 156792 KB Output is correct
7 Correct 148 ms 156792 KB Output is correct
8 Correct 167 ms 156848 KB Output is correct
9 Correct 176 ms 156784 KB Output is correct
10 Correct 212 ms 156760 KB Output is correct
11 Correct 199 ms 156788 KB Output is correct
12 Correct 131 ms 156904 KB Output is correct
13 Correct 313 ms 156792 KB Output is correct
14 Correct 376 ms 156796 KB Output is correct
15 Correct 162 ms 156748 KB Output is correct
16 Correct 155 ms 156760 KB Output is correct
17 Correct 187 ms 156796 KB Output is correct
18 Correct 144 ms 156824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 156848 KB Output is correct
2 Correct 161 ms 157152 KB Output is correct
3 Correct 406 ms 157064 KB Output is correct
4 Correct 180 ms 156856 KB Output is correct
5 Correct 281 ms 156952 KB Output is correct
6 Correct 148 ms 156804 KB Output is correct
7 Correct 147 ms 156840 KB Output is correct
8 Correct 172 ms 156796 KB Output is correct
9 Correct 300 ms 157140 KB Output is correct
10 Correct 368 ms 157124 KB Output is correct
11 Correct 429 ms 156952 KB Output is correct
12 Correct 228 ms 156832 KB Output is correct
13 Correct 129 ms 156804 KB Output is correct
14 Correct 172 ms 156800 KB Output is correct
15 Correct 330 ms 156960 KB Output is correct
16 Correct 155 ms 157160 KB Output is correct
17 Correct 339 ms 156868 KB Output is correct
18 Correct 313 ms 157180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 157036 KB Output is correct
2 Correct 398 ms 157004 KB Output is correct
3 Correct 440 ms 157120 KB Output is correct
4 Correct 282 ms 157064 KB Output is correct
5 Correct 192 ms 157320 KB Output is correct
6 Correct 352 ms 157204 KB Output is correct
7 Correct 317 ms 157304 KB Output is correct
8 Correct 387 ms 157112 KB Output is correct
9 Correct 333 ms 157112 KB Output is correct
10 Correct 266 ms 156812 KB Output is correct
11 Correct 234 ms 156940 KB Output is correct
12 Correct 303 ms 156816 KB Output is correct
13 Correct 387 ms 157264 KB Output is correct
14 Correct 252 ms 158960 KB Output is correct
15 Correct 337 ms 157032 KB Output is correct
16 Correct 387 ms 156952 KB Output is correct
17 Correct 310 ms 157096 KB Output is correct
18 Correct 395 ms 156996 KB Output is correct
19 Correct 151 ms 156884 KB Output is correct
20 Correct 379 ms 157332 KB Output is correct
21 Correct 298 ms 157772 KB Output is correct
22 Correct 441 ms 157524 KB Output is correct
23 Correct 224 ms 157164 KB Output is correct
24 Correct 166 ms 157132 KB Output is correct
25 Correct 292 ms 157248 KB Output is correct
26 Correct 264 ms 157076 KB Output is correct
27 Correct 452 ms 157240 KB Output is correct
28 Correct 170 ms 157120 KB Output is correct
29 Correct 385 ms 157352 KB Output is correct
30 Correct 376 ms 157320 KB Output is correct
31 Correct 200 ms 157052 KB Output is correct
32 Correct 217 ms 157124 KB Output is correct
33 Correct 155 ms 157064 KB Output is correct
34 Correct 287 ms 157232 KB Output is correct
35 Correct 166 ms 157144 KB Output is correct
36 Correct 439 ms 157400 KB Output is correct
37 Correct 191 ms 157432 KB Output is correct
38 Correct 409 ms 157088 KB Output is correct
39 Correct 188 ms 157076 KB Output is correct
40 Correct 334 ms 157088 KB Output is correct
41 Correct 300 ms 157348 KB Output is correct
42 Correct 380 ms 157184 KB Output is correct