Submission #385520

# Submission time Handle Problem Language Result Execution time Memory
385520 2021-04-04T14:19:33 Z b00n0rp Brunhilda’s Birthday (BOI13_brunhilda) C++17
100 / 100
631 ms 116592 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 10000000;

int n,q;
int a[100005];
int lp[MAXN+5];
int dp[MAXN+5];

signed main(){
    cin >> n >> q;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
    }
    sort(a,a+n);
    for(int i = n-1; i >= 0; i --){
        if(lp[a[i]]) continue;
        for(int j = 0; j <= 10000000; j += a[i]){
            if(!lp[j]) lp[j] = a[i];
        }
    }
    int ptr = 0;
    dp[0] = 0;
    deque<int> dq;
    dq.push_back(0);
    // cout << "gg\n";
    for(int i = 1; i <= MAXN; i ++){
        while(ptr+lp[ptr] <= i) ptr++;
        // cout << i << " " << ptr << endl;
        while((!dq.empty()) and dq.front() < ptr) dq.pop_front();
        if(dq.empty()) dp[i] = MAXN*100;
        else dp[i] = 1+dp[dq.front()];
        
        while((!dq.empty()) and dp[dq.back()] > dp[i]){
            dq.pop_back();
            // cout << i << " ";
        }
        dq.push_back(i);
    }
    for(int i = 0; i < q; i ++){
        int x; cin >> x;
        if(dp[x] <= MAXN) cout << dp[x] << "\n";
        else cout << "oo\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 165 ms 78572 KB Output is correct
2 Correct 175 ms 78572 KB Output is correct
3 Correct 167 ms 78572 KB Output is correct
4 Correct 160 ms 78700 KB Output is correct
5 Correct 163 ms 78744 KB Output is correct
6 Correct 168 ms 78572 KB Output is correct
7 Correct 164 ms 78572 KB Output is correct
8 Correct 170 ms 78700 KB Output is correct
9 Correct 202 ms 78572 KB Output is correct
10 Correct 223 ms 78572 KB Output is correct
11 Correct 206 ms 78572 KB Output is correct
12 Correct 132 ms 78572 KB Output is correct
13 Correct 306 ms 78828 KB Output is correct
14 Correct 332 ms 78700 KB Output is correct
15 Correct 189 ms 78572 KB Output is correct
16 Correct 172 ms 78572 KB Output is correct
17 Correct 189 ms 78700 KB Output is correct
18 Correct 161 ms 78700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 82540 KB Output is correct
2 Correct 205 ms 116592 KB Output is correct
3 Correct 352 ms 89596 KB Output is correct
4 Correct 181 ms 79212 KB Output is correct
5 Correct 285 ms 84500 KB Output is correct
6 Correct 165 ms 78956 KB Output is correct
7 Correct 159 ms 82516 KB Output is correct
8 Correct 175 ms 78828 KB Output is correct
9 Correct 322 ms 84744 KB Output is correct
10 Correct 353 ms 89572 KB Output is correct
11 Correct 366 ms 82932 KB Output is correct
12 Correct 234 ms 78828 KB Output is correct
13 Correct 150 ms 80748 KB Output is correct
14 Correct 183 ms 79084 KB Output is correct
15 Correct 314 ms 82540 KB Output is correct
16 Correct 201 ms 116592 KB Output is correct
17 Correct 314 ms 78956 KB Output is correct
18 Correct 321 ms 100256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 83736 KB Output is correct
2 Correct 435 ms 82540 KB Output is correct
3 Correct 500 ms 84012 KB Output is correct
4 Correct 545 ms 79980 KB Output is correct
5 Correct 471 ms 99104 KB Output is correct
6 Correct 547 ms 80236 KB Output is correct
7 Correct 436 ms 92028 KB Output is correct
8 Correct 417 ms 83684 KB Output is correct
9 Correct 419 ms 83820 KB Output is correct
10 Correct 282 ms 79232 KB Output is correct
11 Correct 281 ms 79340 KB Output is correct
12 Correct 348 ms 79468 KB Output is correct
13 Correct 569 ms 83308 KB Output is correct
14 Correct 487 ms 80060 KB Output is correct
15 Correct 364 ms 79340 KB Output is correct
16 Correct 374 ms 79340 KB Output is correct
17 Correct 334 ms 82668 KB Output is correct
18 Correct 421 ms 82412 KB Output is correct
19 Correct 221 ms 81920 KB Output is correct
20 Correct 521 ms 83812 KB Output is correct
21 Correct 522 ms 80108 KB Output is correct
22 Correct 631 ms 87036 KB Output is correct
23 Correct 452 ms 84204 KB Output is correct
24 Correct 411 ms 80148 KB Output is correct
25 Correct 512 ms 79980 KB Output is correct
26 Correct 482 ms 79980 KB Output is correct
27 Correct 526 ms 87280 KB Output is correct
28 Correct 416 ms 80756 KB Output is correct
29 Correct 623 ms 87292 KB Output is correct
30 Correct 588 ms 84460 KB Output is correct
31 Correct 404 ms 80928 KB Output is correct
32 Correct 438 ms 80032 KB Output is correct
33 Correct 384 ms 80620 KB Output is correct
34 Correct 433 ms 92156 KB Output is correct
35 Correct 427 ms 80488 KB Output is correct
36 Correct 625 ms 87164 KB Output is correct
37 Correct 478 ms 99232 KB Output is correct
38 Correct 548 ms 80236 KB Output is correct
39 Correct 429 ms 80236 KB Output is correct
40 Correct 510 ms 80492 KB Output is correct
41 Correct 435 ms 110704 KB Output is correct
42 Correct 581 ms 80108 KB Output is correct