답안 #310129

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
310129 2020-10-05T22:10:51 Z caoash Brunhilda’s Birthday (BOI13_brunhilda) C++14
20 / 100
1000 ms 262148 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

const int MX = 200005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

gp_hash_table<ll, ll> dp;
int n, m; 
vector<ll> prim;

ll solve(ll x) {
    if (dp.find(x) != dp.end()) {
        return dp[x];
    } else if (x == 0) {
        return dp[x] = 0;
    } else {
        ll curr = INT_MAX;
        for (auto p : prim) {
            ll to = x - (x % p);
            if (to != x) {
                curr = min(curr, solve(to) + 1); 
            }
        }
        return dp[x] = curr;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        prim.pb(x);
    }
    for (int i = 0; i < m; i++) {
        ll v; cin >> v;
        ll ans = solve(v);
        if (ans == INT_MAX) cout << "oo" << '\n';
        else cout << ans << '\n';
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 7 ms 1088 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 9 ms 1664 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 2 ms 1088 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 2 ms 1216 KB Output is correct
11 Correct 3 ms 1216 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 90 ms 1784 KB Output is correct
14 Correct 75 ms 1656 KB Output is correct
15 Correct 2 ms 1088 KB Output is correct
16 Correct 6 ms 1088 KB Output is correct
17 Correct 7 ms 1660 KB Output is correct
18 Correct 13 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 5892 KB Time limit exceeded
2 Execution timed out 1061 ms 20976 KB Time limit exceeded
3 Execution timed out 1103 ms 124652 KB Time limit exceeded
4 Execution timed out 1100 ms 37120 KB Time limit exceeded
5 Execution timed out 1050 ms 38388 KB Time limit exceeded
6 Execution timed out 1051 ms 16888 KB Time limit exceeded
7 Execution timed out 1098 ms 6068 KB Time limit exceeded
8 Execution timed out 1034 ms 22244 KB Time limit exceeded
9 Execution timed out 1089 ms 28656 KB Time limit exceeded
10 Execution timed out 1096 ms 124656 KB Time limit exceeded
11 Execution timed out 1106 ms 262132 KB Time limit exceeded
12 Execution timed out 1104 ms 80644 KB Time limit exceeded
13 Execution timed out 1099 ms 38656 KB Time limit exceeded
14 Execution timed out 1098 ms 37124 KB Time limit exceeded
15 Execution timed out 1101 ms 65524 KB Time limit exceeded
16 Execution timed out 1101 ms 20856 KB Time limit exceeded
17 Runtime error 1022 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
18 Execution timed out 1110 ms 174060 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1104 ms 240756 KB Time limit exceeded
2 Execution timed out 1091 ms 14324 KB Time limit exceeded
3 Execution timed out 1101 ms 184816 KB Time limit exceeded
4 Execution timed out 1092 ms 114468 KB Time limit exceeded
5 Execution timed out 1086 ms 2028 KB Time limit exceeded
6 Execution timed out 1101 ms 170276 KB Time limit exceeded
7 Execution timed out 1091 ms 36404 KB Time limit exceeded
8 Execution timed out 1105 ms 240756 KB Time limit exceeded
9 Execution timed out 1112 ms 240596 KB Time limit exceeded
10 Execution timed out 1083 ms 10912 KB Time limit exceeded
11 Execution timed out 1067 ms 47536 KB Time limit exceeded
12 Execution timed out 1046 ms 132536 KB Time limit exceeded
13 Execution timed out 1104 ms 88760 KB Time limit exceeded
14 Runtime error 494 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Execution timed out 1110 ms 251808 KB Time limit exceeded
16 Execution timed out 1049 ms 150556 KB Time limit exceeded
17 Execution timed out 1095 ms 17524 KB Time limit exceeded
18 Execution timed out 1092 ms 14324 KB Time limit exceeded
19 Execution timed out 1095 ms 16136 KB Time limit exceeded
20 Execution timed out 1105 ms 184820 KB Time limit exceeded
21 Runtime error 251 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
22 Execution timed out 1112 ms 187632 KB Time limit exceeded
23 Execution timed out 1094 ms 2260 KB Time limit exceeded
24 Execution timed out 1094 ms 13940 KB Time limit exceeded
25 Execution timed out 1092 ms 11576 KB Time limit exceeded
26 Execution timed out 1099 ms 114304 KB Time limit exceeded
27 Execution timed out 1109 ms 184936 KB Time limit exceeded
28 Execution timed out 1096 ms 58156 KB Time limit exceeded
29 Execution timed out 1094 ms 54388 KB Time limit exceeded
30 Execution timed out 1095 ms 30112 KB Time limit exceeded
31 Execution timed out 1075 ms 38200 KB Time limit exceeded
32 Execution timed out 1095 ms 43424 KB Time limit exceeded
33 Execution timed out 1096 ms 14216 KB Time limit exceeded
34 Execution timed out 1102 ms 36336 KB Time limit exceeded
35 Execution timed out 1096 ms 20596 KB Time limit exceeded
36 Execution timed out 1074 ms 31536 KB Time limit exceeded
37 Execution timed out 1093 ms 2028 KB Time limit exceeded
38 Execution timed out 1045 ms 170112 KB Time limit exceeded
39 Execution timed out 1092 ms 13572 KB Time limit exceeded
40 Execution timed out 1094 ms 64436 KB Time limit exceeded
41 Execution timed out 1093 ms 55152 KB Time limit exceeded
42 Runtime error 617 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)