Submission #152526

# Submission time Handle Problem Language Result Execution time Memory
152526 2019-09-08T09:18:20 Z dolphingarlic Brunhilda’s Birthday (BOI13_brunhilda) C++14
0 / 100
1000 ms 262148 KB
#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MAXN 20000001
typedef long long ll;
using namespace std;

ll dp[MAXN], p[100001], max_divide[MAXN], to[MAXN];

int main() {
    iostream::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    FOR(i, 0, n) cin >> p[i];
    FOR(i, 0, n) for (int j = p[i]; j <= MAXN; j += p[i]) max_divide[j] = p[i];

    ll mn = MAXN - 1;
    for (int i = MAXN - 1; i > 0; i--) {
        mn = min(mn, i + 1 - max_divide[i + 1]);
        if (i < 100) cout << i << ' ' << mn << '\n';
        to[i] = mn;
    }

    FOR(i, 1, MAXN) if (to[i] == i) dp[i] = INT_MAX;
    else dp[i] = dp[to[i]] + 1;

    FOR(i, 0, q) {
        int x;
        cin >> x;
        if (dp[x] >= INT_MAX)
            cout << "oo\n";
        else
            cout << dp[x] << '\n';
    }
    return 0;
}

Compilation message

brunhilda.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
 #pragma GCC Optimize("O3")
# Verdict Execution time Memory Grader output
1 Runtime error 249 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 307 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 276 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 246 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 273 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 267 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 306 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 338 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 373 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 427 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 381 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 237 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 710 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 710 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 340 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 310 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 319 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 261 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 280 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 312 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 905 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 357 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 592 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 314 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 298 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 356 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 676 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 893 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 914 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 485 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 266 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 360 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 741 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 327 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 738 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 723 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 813 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 905 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 906 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 499 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 339 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 687 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 597 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 701 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 708 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 569 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 467 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 829 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 837 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 447 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 735 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 850 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 668 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 935 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 266 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 900 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 615 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 928 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 348 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 271 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 541 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 488 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 1020 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 292 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 774 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Runtime error 701 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
31 Runtime error 347 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Runtime error 400 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Runtime error 242 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 621 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 329 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 869 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 343 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 715 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 303 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Runtime error 608 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 543 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 812 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)