답안 #242154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242154 2020-06-27T03:02:34 Z thecodingwizard Brunhilda’s Birthday (BOI13_brunhilda) C++11
0 / 100
320 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

#define ii pair<int, int>
#define f first
#define s second

int A[100000]; 
int dp[10000001]; 
vector<int> transitions[10000001];

int main() {
    int m, q; cin >> m >> q;
    for (int i = 0; i < m; i++) cin >> A[i];
    for (int i = 0; i < 1000001; i++) dp[i] = -1;
    dp[0] = 0;

    priority_queue<ii, vector<ii>, greater<ii>> pq;
    for (int i = 0; i < m; i++) {
        pq.push(make_pair(0, -A[i]));

        for (int j = 0; j <= 10000000; j+=A[i]) {
            transitions[j].push_back(A[i]);
        }
    }

    while (!pq.empty()) {
        ii u = pq.top(); pq.pop();
        if (dp[u.f] == -1) continue;

        int mx = u.f - u.s;
        mx = min(mx, 10000001);
        for (int i = u.f + 1; i < mx; i++) {
            for (int x : transitions[i]) {
                pq.push({i, -x});
            }
            if (dp[i] == -1) dp[i] = dp[u.f]+1;
        }

        // while (!pq.empty() && pq.top().f < mx) pq.pop();
    }

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

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 164 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 146 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 150 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 247 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 166 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 160 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 156 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 145 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 155 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 144 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 155 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 252 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 153 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 151 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 150 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 148 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 183 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 235 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 230 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 233 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 177 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 150 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 172 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 158 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 229 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 162 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 196 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 166 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 150 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 155 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 152 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 171 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 225 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 163 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 196 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 167 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 167 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 172 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 154 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 320 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 149 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 215 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 180 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 148 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
11 Runtime error 163 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
12 Runtime error 153 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Runtime error 159 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 143 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 157 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
16 Runtime error 157 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Runtime error 176 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Runtime error 175 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Runtime error 157 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Runtime error 170 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Runtime error 147 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Runtime error 200 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
23 Runtime error 270 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
24 Runtime error 177 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
25 Runtime error 159 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
26 Runtime error 154 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Runtime error 198 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
28 Runtime error 149 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Runtime error 216 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
30 Runtime error 205 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
31 Runtime error 157 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
32 Runtime error 156 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
33 Runtime error 179 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
34 Runtime error 233 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
35 Runtime error 155 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 189 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
37 Runtime error 308 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
38 Runtime error 154 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 175 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Runtime error 165 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
41 Runtime error 204 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 145 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)