답안 #558914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558914 2022-05-09T00:16:30 Z Olympia Brunhilda’s Birthday (BOI13_brunhilda) C++17
100 / 100
935 ms 80120 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 = 10000001;
    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 151 ms 78464 KB Output is correct
2 Correct 513 ms 78572 KB Output is correct
3 Correct 411 ms 78520 KB Output is correct
4 Correct 92 ms 78560 KB Output is correct
5 Correct 201 ms 78548 KB Output is correct
6 Correct 147 ms 78588 KB Output is correct
7 Correct 411 ms 78564 KB Output is correct
8 Correct 572 ms 78452 KB Output is correct
9 Correct 730 ms 78584 KB Output is correct
10 Correct 734 ms 78568 KB Output is correct
11 Correct 486 ms 78576 KB Output is correct
12 Correct 99 ms 78572 KB Output is correct
13 Correct 889 ms 78680 KB Output is correct
14 Correct 899 ms 78652 KB Output is correct
15 Correct 475 ms 78572 KB Output is correct
16 Correct 508 ms 78572 KB Output is correct
17 Correct 198 ms 78548 KB Output is correct
18 Correct 90 ms 78564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 78720 KB Output is correct
2 Correct 128 ms 79952 KB Output is correct
3 Correct 875 ms 79876 KB Output is correct
4 Correct 202 ms 78600 KB Output is correct
5 Correct 512 ms 79328 KB Output is correct
6 Correct 327 ms 78656 KB Output is correct
7 Correct 107 ms 78776 KB Output is correct
8 Correct 187 ms 78584 KB Output is correct
9 Correct 549 ms 79768 KB Output is correct
10 Correct 904 ms 79696 KB Output is correct
11 Correct 881 ms 79192 KB Output is correct
12 Correct 519 ms 78692 KB Output is correct
13 Correct 116 ms 78724 KB Output is correct
14 Correct 199 ms 78636 KB Output is correct
15 Correct 781 ms 79188 KB Output is correct
16 Correct 127 ms 79952 KB Output is correct
17 Correct 832 ms 78520 KB Output is correct
18 Correct 573 ms 79924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 837 ms 79432 KB Output is correct
2 Correct 890 ms 79432 KB Output is correct
3 Correct 910 ms 79432 KB Output is correct
4 Correct 575 ms 78792 KB Output is correct
5 Correct 154 ms 80012 KB Output is correct
6 Correct 771 ms 78956 KB Output is correct
7 Correct 358 ms 79908 KB Output is correct
8 Correct 821 ms 79388 KB Output is correct
9 Correct 822 ms 79304 KB Output is correct
10 Correct 436 ms 78680 KB Output is correct
11 Correct 330 ms 78668 KB Output is correct
12 Correct 715 ms 78684 KB Output is correct
13 Correct 793 ms 79328 KB Output is correct
14 Correct 825 ms 79084 KB Output is correct
15 Correct 847 ms 78716 KB Output is correct
16 Correct 883 ms 78728 KB Output is correct
17 Correct 523 ms 79312 KB Output is correct
18 Correct 888 ms 79340 KB Output is correct
19 Correct 202 ms 78668 KB Output is correct
20 Correct 900 ms 79436 KB Output is correct
21 Correct 829 ms 79188 KB Output is correct
22 Correct 886 ms 80072 KB Output is correct
23 Correct 164 ms 79180 KB Output is correct
24 Correct 133 ms 78764 KB Output is correct
25 Correct 535 ms 78884 KB Output is correct
26 Correct 582 ms 78952 KB Output is correct
27 Correct 935 ms 79952 KB Output is correct
28 Correct 183 ms 78792 KB Output is correct
29 Correct 512 ms 80016 KB Output is correct
30 Correct 444 ms 79696 KB Output is correct
31 Correct 201 ms 78828 KB Output is correct
32 Correct 255 ms 78796 KB Output is correct
33 Correct 109 ms 78924 KB Output is correct
34 Correct 359 ms 80120 KB Output is correct
35 Correct 193 ms 78872 KB Output is correct
36 Correct 888 ms 79876 KB Output is correct
37 Correct 159 ms 80008 KB Output is correct
38 Correct 750 ms 78856 KB Output is correct
39 Correct 159 ms 78848 KB Output is correct
40 Correct 635 ms 78996 KB Output is correct
41 Correct 504 ms 79952 KB Output is correct
42 Correct 888 ms 79072 KB Output is correct