답안 #558911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558911 2022-05-09T00:10:17 Z Olympia Brunhilda’s Birthday (BOI13_brunhilda) C++17
90.9524 / 100
907 ms 80084 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int M, Q; cin >> M >> Q;
    vector<int> p(M);
    for (int i = 0; i < M; i++) {
        cin >> p[i];
    }
    int mx = 10000000;
    int res[mx];
    int lpf[mx];
    for (int i = 0; i < mx; i++) {
        lpf[i] = -1;
    }
    for (int j = 0; j < p.size(); j++) {
        for (int i = p[j]; i < mx; i += p[j]) {
            lpf[i] = j;
        }
    }
    int dp[M];
    priority_queue<int, vector<int>, greater<int> > ms;
    for (int i = 0; i < M; i++) {
        dp[i] = 0;
        ms.push(dp[i]);
    }
    for (int i = 1; i < mx; i++) {
        int ans = 1e9;
        if (lpf[i] == -1) {
            ans = ms.top() + 1;
        } else {
            vector<int> invalid;
            int x = i;
            while (lpf[x] != -1) {
                if (dp[lpf[x]] == ms.top()) {
                    invalid.push_back(lpf[x]);
                    ms.pop();
                }
                int a = p[lpf[x]];
                while (x % a == 0) {
                    x /= a;
                }
            }
            if (!ms.empty()) {
                ans = ms.top() + 1;
            }
            for (int j: invalid) {
                dp[j] = ans;
                ms.push(dp[j]);
            }
        }
        res[i] = ans;
    }
    while (Q--) {
        int x;
        cin >> x;
        if (res[x] == (int)1e9) {
            cout << "oo\n";
        } else {
            cout << res[x] << '\n';
        }
    }
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int j = 0; j < p.size(); j++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 150 ms 78668 KB Output isn't correct
2 Correct 513 ms 78572 KB Output is correct
3 Correct 410 ms 78568 KB Output is correct
4 Correct 100 ms 78560 KB Output is correct
5 Correct 199 ms 78668 KB Output is correct
6 Incorrect 149 ms 78576 KB Output isn't correct
7 Correct 417 ms 78584 KB Output is correct
8 Correct 575 ms 78568 KB Output is correct
9 Correct 716 ms 78564 KB Output is correct
10 Correct 729 ms 78576 KB Output is correct
11 Correct 490 ms 78580 KB Output is correct
12 Correct 95 ms 78572 KB Output is correct
13 Correct 881 ms 78668 KB Output is correct
14 Correct 907 ms 78576 KB Output is correct
15 Correct 467 ms 78612 KB Output is correct
16 Correct 512 ms 78656 KB Output is correct
17 Correct 196 ms 78596 KB Output is correct
18 Correct 96 ms 78576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 78668 KB Output is correct
2 Correct 125 ms 79952 KB Output is correct
3 Correct 885 ms 79760 KB Output is correct
4 Correct 199 ms 78712 KB Output is correct
5 Correct 502 ms 79428 KB Output is correct
6 Correct 331 ms 78596 KB Output is correct
7 Correct 111 ms 78660 KB Output is correct
8 Correct 188 ms 78588 KB Output is correct
9 Correct 552 ms 79768 KB Output is correct
10 Correct 869 ms 79788 KB Output is correct
11 Correct 868 ms 79344 KB Output is correct
12 Correct 518 ms 78672 KB Output is correct
13 Correct 118 ms 78540 KB Output is correct
14 Correct 197 ms 78628 KB Output is correct
15 Correct 764 ms 79308 KB Output is correct
16 Correct 129 ms 79932 KB Output is correct
17 Correct 847 ms 78744 KB Output is correct
18 Incorrect 571 ms 80020 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 835 ms 79304 KB Output is correct
2 Correct 895 ms 79340 KB Output is correct
3 Correct 899 ms 79432 KB Output is correct
4 Correct 579 ms 78800 KB Output is correct
5 Correct 167 ms 80068 KB Output is correct
6 Correct 741 ms 78960 KB Output is correct
7 Correct 380 ms 79948 KB Output is correct
8 Correct 803 ms 79316 KB Output is correct
9 Correct 806 ms 79316 KB Output is correct
10 Correct 415 ms 78668 KB Output is correct
11 Correct 315 ms 78664 KB Output is correct
12 Correct 705 ms 78720 KB Output is correct
13 Correct 792 ms 79328 KB Output is correct
14 Correct 808 ms 79120 KB Output is correct
15 Correct 838 ms 78676 KB Output is correct
16 Correct 870 ms 78740 KB Output is correct
17 Correct 528 ms 79308 KB Output is correct
18 Correct 895 ms 79436 KB Output is correct
19 Correct 201 ms 78720 KB Output is correct
20 Correct 902 ms 79444 KB Output is correct
21 Incorrect 827 ms 79204 KB Output isn't correct
22 Correct 890 ms 80000 KB Output is correct
23 Correct 166 ms 79188 KB Output is correct
24 Correct 132 ms 78856 KB Output is correct
25 Correct 508 ms 78916 KB Output is correct
26 Correct 574 ms 78888 KB Output is correct
27 Correct 903 ms 80004 KB Output is correct
28 Incorrect 182 ms 78796 KB Output isn't correct
29 Correct 508 ms 80084 KB Output is correct
30 Correct 445 ms 79696 KB Output is correct
31 Correct 201 ms 78796 KB Output is correct
32 Correct 257 ms 78848 KB Output is correct
33 Correct 110 ms 78800 KB Output is correct
34 Correct 362 ms 79952 KB Output is correct
35 Incorrect 190 ms 78860 KB Output isn't correct
36 Correct 884 ms 79900 KB Output is correct
37 Correct 151 ms 80048 KB Output is correct
38 Correct 750 ms 78952 KB Output is correct
39 Correct 154 ms 78880 KB Output is correct
40 Correct 626 ms 78988 KB Output is correct
41 Correct 499 ms 80080 KB Output is correct
42 Incorrect 885 ms 79052 KB Output isn't correct