Submission #558908

# Submission time Handle Problem Language Result Execution time Memory
558908 2022-05-09T00:07:24 Z Olympia Brunhilda’s Birthday (BOI13_brunhilda) C++17
17.7778 / 100
24 ms 4716 KB
#include <bits/stdc++.h>
using namespace std;
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 = 100000;
    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:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int j = 0; j < p.size(); j++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1108 KB Output isn't correct
2 Correct 5 ms 980 KB Output is correct
3 Correct 4 ms 980 KB Output is correct
4 Correct 3 ms 1108 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Incorrect 3 ms 980 KB Output isn't correct
7 Correct 5 ms 980 KB Output is correct
8 Correct 6 ms 1092 KB Output is correct
9 Correct 8 ms 980 KB Output is correct
10 Correct 8 ms 980 KB Output is correct
11 Correct 6 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 8 ms 1108 KB Output is correct
14 Correct 10 ms 1108 KB Output is correct
15 Correct 4 ms 980 KB Output is correct
16 Correct 6 ms 1108 KB Output is correct
17 Correct 4 ms 1108 KB Output is correct
18 Correct 3 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 2388 KB Execution killed with signal 11
2 Runtime error 13 ms 4404 KB Execution killed with signal 11
3 Runtime error 18 ms 3924 KB Execution killed with signal 11
4 Runtime error 4 ms 2132 KB Execution killed with signal 11
5 Runtime error 14 ms 3484 KB Execution killed with signal 11
6 Runtime error 5 ms 2004 KB Execution killed with signal 11
7 Runtime error 4 ms 2388 KB Execution killed with signal 11
8 Runtime error 3 ms 2004 KB Execution killed with signal 11
9 Runtime error 14 ms 3940 KB Execution killed with signal 11
10 Runtime error 17 ms 3924 KB Execution killed with signal 11
11 Runtime error 13 ms 3248 KB Execution killed with signal 11
12 Runtime error 6 ms 2004 KB Execution killed with signal 11
13 Runtime error 3 ms 2132 KB Execution killed with signal 11
14 Runtime error 3 ms 2132 KB Execution killed with signal 11
15 Runtime error 12 ms 3244 KB Execution killed with signal 11
16 Runtime error 13 ms 4520 KB Execution killed with signal 11
17 Runtime error 10 ms 2056 KB Execution killed with signal 11
18 Runtime error 22 ms 4600 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 3416 KB Execution killed with signal 11
2 Runtime error 18 ms 3484 KB Execution killed with signal 11
3 Runtime error 14 ms 3416 KB Execution killed with signal 11
4 Runtime error 7 ms 2132 KB Execution killed with signal 11
5 Runtime error 13 ms 4564 KB Execution killed with signal 11
6 Runtime error 8 ms 2248 KB Execution killed with signal 11
7 Runtime error 14 ms 4692 KB Execution killed with signal 11
8 Runtime error 13 ms 3416 KB Execution killed with signal 11
9 Runtime error 13 ms 3492 KB Execution killed with signal 11
10 Runtime error 6 ms 2132 KB Execution killed with signal 11
11 Runtime error 5 ms 2132 KB Execution killed with signal 11
12 Runtime error 9 ms 2228 KB Execution killed with signal 11
13 Runtime error 14 ms 3000 KB Execution killed with signal 11
14 Runtime error 10 ms 2004 KB Execution killed with signal 11
15 Runtime error 10 ms 2244 KB Execution killed with signal 11
16 Runtime error 11 ms 2280 KB Execution killed with signal 11
17 Runtime error 11 ms 3324 KB Execution killed with signal 11
18 Runtime error 14 ms 3460 KB Execution killed with signal 11
19 Runtime error 4 ms 2132 KB Execution killed with signal 11
20 Runtime error 13 ms 3496 KB Execution killed with signal 11
21 Runtime error 8 ms 2004 KB Execution killed with signal 11
22 Runtime error 18 ms 4692 KB Execution killed with signal 11
23 Runtime error 6 ms 3028 KB Execution killed with signal 11
24 Runtime error 3 ms 2004 KB Execution killed with signal 11
25 Runtime error 6 ms 2132 KB Execution killed with signal 11
26 Runtime error 7 ms 2132 KB Execution killed with signal 11
27 Runtime error 22 ms 4556 KB Execution killed with signal 11
28 Runtime error 3 ms 2024 KB Execution killed with signal 11
29 Runtime error 16 ms 4716 KB Execution killed with signal 11
30 Runtime error 24 ms 3984 KB Execution killed with signal 11
31 Runtime error 4 ms 2160 KB Execution killed with signal 11
32 Runtime error 4 ms 2132 KB Execution killed with signal 11
33 Runtime error 3 ms 2004 KB Execution killed with signal 11
34 Runtime error 14 ms 4700 KB Execution killed with signal 11
35 Runtime error 3 ms 2004 KB Execution killed with signal 11
36 Runtime error 17 ms 4444 KB Execution killed with signal 11
37 Runtime error 13 ms 4620 KB Execution killed with signal 11
38 Runtime error 9 ms 2252 KB Execution killed with signal 11
39 Runtime error 3 ms 2132 KB Execution killed with signal 11
40 Runtime error 8 ms 2388 KB Execution killed with signal 11
41 Runtime error 16 ms 4692 KB Execution killed with signal 11
42 Runtime error 10 ms 2132 KB Execution killed with signal 11