Submission #546536

# Submission time Handle Problem Language Result Execution time Memory
546536 2022-04-07T18:29:27 Z _martynas Brunhilda’s Birthday (BOI13_brunhilda) C++11
100 / 100
280 ms 127120 KB
#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define F first
#define S second

using pii = pair<int, int>;

const int MXN = 1e5+5;
const int MXM = 1e7+5;
const int INF = 1e8;

int m, q;
int P[MXN];
int dp[MXM];
int add[MXM];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> m >> q;

    for(int i = 0; i < m; i++) {
        cin >> P[i];
    }

    fill(dp, dp + MXM, INF);

    for(int i = 0; i < m; i++) {
        // prime can exceed maximum!
        // only the place which transition leads to needs to fit
        for(int p = P[i]; p - P[i] < MXM; p += P[i]) {
            add[p - P[i]] = P[i];
        }
    }

    dp[0] = 0;
    queue<pii> Q;
    for(int i = 0; i < MXM; i++) {
        while(!Q.empty() && Q.front().F + Q.front().S <= i) {
            Q.pop();
        }

        if(!Q.empty()) {
            dp[i] = min(INF, dp[Q.front().S]+1);
        }

        if(add[i]) {
            Q.push({add[i], i});
        }
    }

    for(int qq = 0; qq < q; qq++) {
        int n;
        cin >> n;
        if(dp[n] >= INF) {
            cout << "oo\n";
        }
        else {
            cout << dp[n] << "\n";
        }
    }

    return 0;
}
/*
2 2
2 3
5
6
*/
# Verdict Execution time Memory Grader output
1 Correct 82 ms 78584 KB Output is correct
2 Correct 111 ms 78488 KB Output is correct
3 Correct 107 ms 78580 KB Output is correct
4 Correct 68 ms 78548 KB Output is correct
5 Correct 109 ms 78508 KB Output is correct
6 Correct 85 ms 78580 KB Output is correct
7 Correct 114 ms 78584 KB Output is correct
8 Correct 120 ms 78472 KB Output is correct
9 Correct 132 ms 78584 KB Output is correct
10 Correct 157 ms 78604 KB Output is correct
11 Correct 139 ms 78588 KB Output is correct
12 Correct 63 ms 78488 KB Output is correct
13 Correct 180 ms 78588 KB Output is correct
14 Correct 189 ms 78648 KB Output is correct
15 Correct 122 ms 78548 KB Output is correct
16 Correct 106 ms 78588 KB Output is correct
17 Correct 112 ms 78684 KB Output is correct
18 Correct 70 ms 78588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 79784 KB Output is correct
2 Correct 111 ms 95532 KB Output is correct
3 Correct 219 ms 98416 KB Output is correct
4 Correct 138 ms 78968 KB Output is correct
5 Correct 169 ms 87780 KB Output is correct
6 Correct 100 ms 78996 KB Output is correct
7 Correct 87 ms 79892 KB Output is correct
8 Correct 127 ms 78668 KB Output is correct
9 Correct 190 ms 88684 KB Output is correct
10 Correct 220 ms 98384 KB Output is correct
11 Correct 216 ms 85948 KB Output is correct
12 Correct 145 ms 78856 KB Output is correct
13 Correct 88 ms 79528 KB Output is correct
14 Correct 129 ms 78968 KB Output is correct
15 Correct 185 ms 84892 KB Output is correct
16 Correct 110 ms 95492 KB Output is correct
17 Correct 188 ms 79104 KB Output is correct
18 Correct 199 ms 115392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 86732 KB Output is correct
2 Correct 226 ms 84540 KB Output is correct
3 Correct 243 ms 86516 KB Output is correct
4 Correct 173 ms 79492 KB Output is correct
5 Correct 133 ms 87952 KB Output is correct
6 Correct 202 ms 79892 KB Output is correct
7 Correct 191 ms 96216 KB Output is correct
8 Correct 213 ms 86724 KB Output is correct
9 Correct 212 ms 86732 KB Output is correct
10 Correct 169 ms 79180 KB Output is correct
11 Correct 166 ms 79240 KB Output is correct
12 Correct 179 ms 79444 KB Output is correct
13 Correct 216 ms 85072 KB Output is correct
14 Correct 173 ms 79052 KB Output is correct
15 Correct 185 ms 79248 KB Output is correct
16 Correct 203 ms 79252 KB Output is correct
17 Correct 203 ms 84516 KB Output is correct
18 Correct 257 ms 84568 KB Output is correct
19 Correct 108 ms 81100 KB Output is correct
20 Correct 234 ms 86608 KB Output is correct
21 Correct 172 ms 79180 KB Output is correct
22 Correct 280 ms 91180 KB Output is correct
23 Correct 139 ms 81132 KB Output is correct
24 Correct 112 ms 79016 KB Output is correct
25 Correct 185 ms 79180 KB Output is correct
26 Correct 166 ms 79480 KB Output is correct
27 Correct 278 ms 92304 KB Output is correct
28 Correct 120 ms 79428 KB Output is correct
29 Correct 227 ms 90736 KB Output is correct
30 Correct 226 ms 86748 KB Output is correct
31 Correct 146 ms 79708 KB Output is correct
32 Correct 150 ms 79212 KB Output is correct
33 Correct 98 ms 79032 KB Output is correct
34 Correct 196 ms 96216 KB Output is correct
35 Correct 119 ms 79436 KB Output is correct
36 Correct 244 ms 90988 KB Output is correct
37 Correct 139 ms 88024 KB Output is correct
38 Correct 199 ms 79820 KB Output is correct
39 Correct 123 ms 79136 KB Output is correct
40 Correct 183 ms 80340 KB Output is correct
41 Correct 181 ms 127120 KB Output is correct
42 Correct 263 ms 79384 KB Output is correct