Submission #734608

# Submission time Handle Problem Language Result Execution time Memory
734608 2023-05-02T17:09:50 Z DAleksa Brunhilda’s Birthday (BOI13_brunhilda) C++17
97.7778 / 100
507 ms 195040 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e7 + 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(dp[x] == -1) cout << "oo\n";
        else cout << dp[x] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 144 ms 163608 KB Output isn't correct
2 Correct 221 ms 185376 KB Output is correct
3 Correct 194 ms 181400 KB Output is correct
4 Correct 118 ms 159876 KB Output is correct
5 Correct 188 ms 167236 KB Output is correct
6 Incorrect 161 ms 163520 KB Output isn't correct
7 Correct 201 ms 181460 KB Output is correct
8 Correct 223 ms 186416 KB Output is correct
9 Correct 277 ms 189084 KB Output is correct
10 Correct 309 ms 189996 KB Output is correct
11 Correct 286 ms 184452 KB Output is correct
12 Correct 118 ms 159040 KB Output is correct
13 Correct 397 ms 193376 KB Output is correct
14 Correct 393 ms 193328 KB Output is correct
15 Correct 241 ms 184472 KB Output is correct
16 Correct 228 ms 185412 KB Output is correct
17 Correct 196 ms 167136 KB Output is correct
18 Correct 119 ms 159824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 163572 KB Output is correct
2 Correct 201 ms 166096 KB Output is correct
3 Correct 441 ms 194056 KB Output is correct
4 Correct 242 ms 172820 KB Output is correct
5 Correct 393 ms 188584 KB Output is correct
6 Correct 205 ms 180460 KB Output is correct
7 Correct 160 ms 163576 KB Output is correct
8 Correct 265 ms 171196 KB Output is correct
9 Correct 410 ms 190784 KB Output is correct
10 Correct 448 ms 194032 KB Output is correct
11 Correct 493 ms 193616 KB Output is correct
12 Correct 340 ms 186724 KB Output is correct
13 Correct 170 ms 166596 KB Output is correct
14 Correct 253 ms 172852 KB Output is correct
15 Correct 415 ms 192664 KB Output is correct
16 Correct 186 ms 166048 KB Output is correct
17 Correct 405 ms 192932 KB Output is correct
18 Correct 391 ms 191464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 404 ms 193488 KB Output is correct
2 Correct 460 ms 193960 KB Output is correct
3 Correct 488 ms 194304 KB Output is correct
4 Correct 333 ms 188884 KB Output is correct
5 Correct 237 ms 166784 KB Output is correct
6 Correct 434 ms 192276 KB Output is correct
7 Correct 387 ms 185280 KB Output is correct
8 Correct 449 ms 193520 KB Output is correct
9 Correct 424 ms 193540 KB Output is correct
10 Correct 394 ms 184268 KB Output is correct
11 Correct 325 ms 180136 KB Output is correct
12 Correct 398 ms 191620 KB Output is correct
13 Correct 435 ms 193368 KB Output is correct
14 Correct 349 ms 191996 KB Output is correct
15 Correct 431 ms 193152 KB Output is correct
16 Correct 421 ms 193460 KB Output is correct
17 Correct 367 ms 189220 KB Output is correct
18 Correct 454 ms 193936 KB Output is correct
19 Correct 180 ms 173552 KB Output is correct
20 Correct 466 ms 194392 KB Output is correct
21 Correct 371 ms 193516 KB Output is correct
22 Correct 507 ms 195040 KB Output is correct
23 Correct 227 ms 168072 KB Output is correct
24 Correct 202 ms 164484 KB Output is correct
25 Correct 362 ms 187680 KB Output is correct
26 Correct 331 ms 188884 KB Output is correct
27 Correct 480 ms 194664 KB Output is correct
28 Correct 195 ms 171084 KB Output is correct
29 Correct 431 ms 191768 KB Output is correct
30 Correct 403 ms 190072 KB Output is correct
31 Correct 238 ms 172108 KB Output is correct
32 Correct 286 ms 175932 KB Output is correct
33 Correct 148 ms 161400 KB Output is correct
34 Correct 364 ms 185196 KB Output is correct
35 Correct 204 ms 171928 KB Output is correct
36 Correct 453 ms 194776 KB Output is correct
37 Correct 199 ms 166924 KB Output is correct
38 Correct 401 ms 192252 KB Output is correct
39 Correct 202 ms 166456 KB Output is correct
40 Correct 403 ms 190668 KB Output is correct
41 Correct 327 ms 188592 KB Output is correct
42 Correct 435 ms 194508 KB Output is correct