답안 #152528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152528 2019-09-08T09:19:01 Z dolphingarlic Brunhilda’s Birthday (BOI13_brunhilda) C++14
0 / 100
974 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 + 10], p[100001], max_divide[MAXN + 10], to[MAXN + 10];

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]);
        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")
# 결과 실행 시간 메모리 Grader output
1 Runtime error 261 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 320 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 293 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 248 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 289 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 255 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 286 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 312 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 414 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 435 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 407 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 236 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 747 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 722 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 347 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 327 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 309 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 244 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 288 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 316 ms 262144 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 377 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 599 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 307 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 293 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 354 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 684 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 908 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 894 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 488 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 270 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 357 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 709 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 329 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 806 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 743 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 805 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 893 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 912 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 548 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 345 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 702 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 626 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 715 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 738 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 592 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 496 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 690 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 865 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 464 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 725 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 800 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 679 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 929 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 281 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 920 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 546 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 870 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 356 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 273 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 555 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 501 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 974 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 304 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 873 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Runtime error 729 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
31 Runtime error 356 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Runtime error 384 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Runtime error 245 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 610 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 318 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 930 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 350 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 729 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 298 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Runtime error 592 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 523 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 825 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)