답안 #558913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558913 2022-05-09T00:15:07 Z Olympia Brunhilda’s Birthday (BOI13_brunhilda) C++17
93.1746 / 100
913 ms 80132 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 Correct 160 ms 78620 KB Output is correct
2 Correct 511 ms 78576 KB Output is correct
3 Correct 416 ms 78548 KB Output is correct
4 Correct 95 ms 78568 KB Output is correct
5 Correct 211 ms 78564 KB Output is correct
6 Correct 157 ms 78568 KB Output is correct
7 Correct 411 ms 78576 KB Output is correct
8 Correct 583 ms 78572 KB Output is correct
9 Correct 720 ms 78576 KB Output is correct
10 Correct 751 ms 78572 KB Output is correct
11 Correct 491 ms 78576 KB Output is correct
12 Correct 99 ms 78568 KB Output is correct
13 Correct 905 ms 78700 KB Output is correct
14 Correct 900 ms 78540 KB Output is correct
15 Correct 484 ms 78548 KB Output is correct
16 Correct 511 ms 78548 KB Output is correct
17 Correct 186 ms 78700 KB Output is correct
18 Correct 92 ms 78584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 78784 KB Output is correct
2 Correct 127 ms 79848 KB Output is correct
3 Correct 901 ms 79808 KB Output is correct
4 Correct 198 ms 78596 KB Output is correct
5 Correct 489 ms 79272 KB Output is correct
6 Correct 333 ms 78668 KB Output is correct
7 Correct 109 ms 78788 KB Output is correct
8 Correct 185 ms 78548 KB Output is correct
9 Correct 571 ms 79768 KB Output is correct
10 Correct 879 ms 79708 KB Output is correct
11 Correct 864 ms 79256 KB Output is correct
12 Correct 519 ms 78708 KB Output is correct
13 Correct 123 ms 78596 KB Output is correct
14 Correct 210 ms 78724 KB Output is correct
15 Correct 770 ms 79216 KB Output is correct
16 Correct 128 ms 79852 KB Output is correct
17 Correct 862 ms 78540 KB Output is correct
18 Incorrect 577 ms 79976 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 821 ms 79312 KB Output is correct
2 Correct 895 ms 79568 KB Output is correct
3 Correct 905 ms 79432 KB Output is correct
4 Correct 580 ms 78984 KB Output is correct
5 Correct 167 ms 80048 KB Output is correct
6 Correct 749 ms 78860 KB Output is correct
7 Correct 367 ms 79952 KB Output is correct
8 Correct 837 ms 79428 KB Output is correct
9 Correct 822 ms 79308 KB Output is correct
10 Correct 415 ms 78644 KB Output is correct
11 Correct 328 ms 78712 KB Output is correct
12 Correct 712 ms 78724 KB Output is correct
13 Correct 807 ms 79324 KB Output is correct
14 Correct 839 ms 79092 KB Output is correct
15 Correct 858 ms 78672 KB Output is correct
16 Correct 863 ms 78692 KB Output is correct
17 Correct 550 ms 79280 KB Output is correct
18 Correct 893 ms 79336 KB Output is correct
19 Correct 201 ms 78720 KB Output is correct
20 Correct 906 ms 79552 KB Output is correct
21 Incorrect 837 ms 79180 KB Output isn't correct
22 Correct 889 ms 80096 KB Output is correct
23 Correct 165 ms 79244 KB Output is correct
24 Correct 143 ms 78780 KB Output is correct
25 Correct 524 ms 79020 KB Output is correct
26 Correct 576 ms 78924 KB Output is correct
27 Correct 913 ms 80016 KB Output is correct
28 Incorrect 184 ms 78844 KB Output isn't correct
29 Correct 508 ms 80132 KB Output is correct
30 Correct 442 ms 79764 KB Output is correct
31 Correct 205 ms 78788 KB Output is correct
32 Correct 262 ms 78948 KB Output is correct
33 Correct 110 ms 78824 KB Output is correct
34 Correct 357 ms 79960 KB Output is correct
35 Incorrect 189 ms 78888 KB Output isn't correct
36 Correct 894 ms 79904 KB Output is correct
37 Correct 156 ms 80076 KB Output is correct
38 Correct 759 ms 78956 KB Output is correct
39 Correct 155 ms 78924 KB Output is correct
40 Correct 649 ms 78992 KB Output is correct
41 Correct 515 ms 79952 KB Output is correct
42 Incorrect 891 ms 79100 KB Output isn't correct