Submission #734618

# Submission time Handle Problem Language Result Execution time Memory
734618 2023-05-02T17:18:42 Z DAleksa Brunhilda’s Birthday (BOI13_brunhilda) C++17
0 / 100
829 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e7 + 10;
int n, q;
vector<int> p;
vector<int> v;
int cnt[N];
int prime[N];
int prv[N];
int dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    p.resize(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = p.size() - 1; i >= 0; i--) {
        for(int j = p[i]; j < N; j += p[i]) {
            if(prime[j] == 0) {
                cnt[j]++;
                prime[j] = p[i];
            }
        }
    }
    cnt[0]++;
    prime[0] = p.back();
    for(int i = 0; i < N; i++) for(int j = 0; j < cnt[i]; j++) v.push_back(i);
    int j = 0;
    for(int i = 1; i < N; i++) {
        while(v[j] + prime[v[j]] <= i) j++;
        prv[i] = v[j];
    }
    for(int i = 1; i < N; i++) {
        if(prv[i] == i) dp[i] = -1;
        else dp[i] = dp[prv[i]] + 1;
    }
    while(q--) {
        int x;
        cin >> x;
        if(x < p.back()) cout << "1\n";
        else if(dp[x] == -1) cout << "oo\n";
        else cout << dp[x] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 267 ms 262144 KB Execution killed with signal 9
2 Runtime error 384 ms 262144 KB Execution killed with signal 9
3 Runtime error 324 ms 262144 KB Execution killed with signal 9
4 Runtime error 256 ms 262144 KB Execution killed with signal 9
5 Runtime error 351 ms 262144 KB Execution killed with signal 9
6 Runtime error 270 ms 262144 KB Execution killed with signal 9
7 Runtime error 342 ms 262144 KB Execution killed with signal 9
8 Runtime error 356 ms 262144 KB Execution killed with signal 9
9 Runtime error 463 ms 262144 KB Execution killed with signal 9
10 Runtime error 502 ms 262144 KB Execution killed with signal 9
11 Runtime error 486 ms 262144 KB Execution killed with signal 9
12 Runtime error 231 ms 262144 KB Execution killed with signal 9
13 Runtime error 682 ms 262144 KB Execution killed with signal 9
14 Runtime error 691 ms 262144 KB Execution killed with signal 9
15 Runtime error 456 ms 262144 KB Execution killed with signal 9
16 Runtime error 388 ms 262144 KB Execution killed with signal 9
17 Runtime error 409 ms 262144 KB Execution killed with signal 9
18 Runtime error 205 ms 262144 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 301 ms 262144 KB Execution killed with signal 9
2 Runtime error 350 ms 262144 KB Execution killed with signal 9
3 Runtime error 765 ms 262144 KB Execution killed with signal 9
4 Runtime error 413 ms 262144 KB Execution killed with signal 9
5 Runtime error 620 ms 262144 KB Execution killed with signal 9
6 Runtime error 350 ms 262144 KB Execution killed with signal 9
7 Runtime error 274 ms 262144 KB Execution killed with signal 9
8 Runtime error 400 ms 262144 KB Execution killed with signal 9
9 Runtime error 641 ms 262144 KB Execution killed with signal 9
10 Runtime error 779 ms 262144 KB Execution killed with signal 9
11 Runtime error 702 ms 262144 KB Execution killed with signal 9
12 Runtime error 558 ms 262144 KB Execution killed with signal 9
13 Runtime error 262 ms 262144 KB Execution killed with signal 9
14 Runtime error 443 ms 262144 KB Execution killed with signal 9
15 Runtime error 693 ms 262144 KB Execution killed with signal 9
16 Runtime error 333 ms 262144 KB Execution killed with signal 9
17 Runtime error 746 ms 262144 KB Execution killed with signal 9
18 Runtime error 635 ms 262144 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 725 ms 262144 KB Execution killed with signal 9
2 Runtime error 730 ms 262144 KB Execution killed with signal 9
3 Runtime error 723 ms 262144 KB Execution killed with signal 9
4 Runtime error 530 ms 262144 KB Execution killed with signal 9
5 Runtime error 322 ms 262144 KB Execution killed with signal 9
6 Runtime error 647 ms 262144 KB Execution killed with signal 9
7 Runtime error 625 ms 262144 KB Execution killed with signal 9
8 Runtime error 615 ms 262144 KB Execution killed with signal 9
9 Runtime error 625 ms 262144 KB Execution killed with signal 9
10 Runtime error 610 ms 262144 KB Execution killed with signal 9
11 Runtime error 543 ms 262144 KB Execution killed with signal 9
12 Runtime error 631 ms 262144 KB Execution killed with signal 9
13 Runtime error 741 ms 262144 KB Execution killed with signal 9
14 Runtime error 519 ms 262144 KB Execution killed with signal 9
15 Runtime error 636 ms 262144 KB Execution killed with signal 9
16 Runtime error 717 ms 262144 KB Execution killed with signal 9
17 Runtime error 745 ms 262144 KB Execution killed with signal 9
18 Runtime error 816 ms 262144 KB Execution killed with signal 9
19 Runtime error 309 ms 262144 KB Execution killed with signal 9
20 Runtime error 826 ms 262144 KB Execution killed with signal 9
21 Runtime error 556 ms 262144 KB Execution killed with signal 9
22 Runtime error 785 ms 262144 KB Execution killed with signal 9
23 Runtime error 405 ms 262144 KB Execution killed with signal 9
24 Runtime error 291 ms 262144 KB Execution killed with signal 9
25 Runtime error 687 ms 262144 KB Execution killed with signal 9
26 Runtime error 592 ms 262144 KB Execution killed with signal 9
27 Runtime error 829 ms 262144 KB Execution killed with signal 9
28 Runtime error 370 ms 262144 KB Execution killed with signal 9
29 Runtime error 780 ms 262144 KB Execution killed with signal 9
30 Runtime error 723 ms 262144 KB Execution killed with signal 9
31 Runtime error 405 ms 262144 KB Execution killed with signal 9
32 Runtime error 464 ms 262144 KB Execution killed with signal 9
33 Runtime error 237 ms 262144 KB Execution killed with signal 9
34 Runtime error 707 ms 262144 KB Execution killed with signal 9
35 Runtime error 342 ms 262144 KB Execution killed with signal 9
36 Runtime error 805 ms 262144 KB Execution killed with signal 9
37 Runtime error 363 ms 262144 KB Execution killed with signal 9
38 Runtime error 740 ms 262144 KB Execution killed with signal 9
39 Runtime error 334 ms 262144 KB Execution killed with signal 9
40 Runtime error 615 ms 262144 KB Execution killed with signal 9
41 Runtime error 603 ms 262144 KB Execution killed with signal 9
42 Runtime error 733 ms 262144 KB Execution killed with signal 9