# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
74690 | 2018-09-06T14:44:38 Z | kjain_1810 | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 350 ms | 41216 KB |
#include<bits/stdc++.h> #define f first #define s second #define pb push_back #define ind(n) scanf("%d", &n) #define ind2(n, m) scanf("%d%d", &n, &m) #define ind3(n, m, k) scanf("%d%d%d", &n, &m, &k) #define inlld(n) scanf("%lld", &n) #define inlld2(n, m) scanf("%lld%lld", &n, &m) #define inlld3(n, m, k) scanf("%lld%lld%lld", &n, &m, &k) using namespace std; const int N=1e7+5; const int MOD=1e9+7; typedef long long ll; typedef long double ld; int n, q; int arr[N], dp[N]; int solve(int i) { if(i==0) return 0; if(dp[i]!=-1) return dp[i]; int ans=-1e8, best=0; if(q==1) { for(int a=n; a>=1; a--) { if(i%arr[a]==0) continue; if(i%arr[a]>ans) { ans=i%arr[a]; best=a; } } } else { for(int a=n; a>=max(1, n-500); a--) { if(i%arr[a]==0) continue; if(i%arr[a]>ans) { ans=i%arr[a]; best=a; } } } if(best) return dp[i]=solve(i-ans)+1; else return dp[i]=1e8; } signed main() { ind2(n, q); for(int a=1; a<=n; a++) ind(arr[a]); memset(dp, -1, sizeof(dp)); while(q--) { int x; ind(x); int ans=solve(x); if(ans<1e8) printf("%d\n", ans); else printf("oo\n"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 39544 KB | Output is correct |
2 | Correct | 31 ms | 39800 KB | Output is correct |
3 | Correct | 33 ms | 39800 KB | Output is correct |
4 | Correct | 40 ms | 39800 KB | Output is correct |
5 | Correct | 31 ms | 39800 KB | Output is correct |
6 | Correct | 34 ms | 39800 KB | Output is correct |
7 | Correct | 32 ms | 39800 KB | Output is correct |
8 | Correct | 33 ms | 39800 KB | Output is correct |
9 | Correct | 39 ms | 39800 KB | Output is correct |
10 | Correct | 31 ms | 39800 KB | Output is correct |
11 | Correct | 35 ms | 39800 KB | Output is correct |
12 | Correct | 39 ms | 39800 KB | Output is correct |
13 | Correct | 35 ms | 39800 KB | Output is correct |
14 | Correct | 52 ms | 39800 KB | Output is correct |
15 | Correct | 33 ms | 39800 KB | Output is correct |
16 | Correct | 34 ms | 39800 KB | Output is correct |
17 | Correct | 37 ms | 39800 KB | Output is correct |
18 | Correct | 37 ms | 39800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 39808 KB | Output is correct |
2 | Correct | 45 ms | 40196 KB | Output is correct |
3 | Correct | 41 ms | 40196 KB | Output is correct |
4 | Correct | 33 ms | 40196 KB | Output is correct |
5 | Correct | 39 ms | 40196 KB | Output is correct |
6 | Correct | 34 ms | 40196 KB | Output is correct |
7 | Correct | 35 ms | 40196 KB | Output is correct |
8 | Correct | 34 ms | 40196 KB | Output is correct |
9 | Correct | 44 ms | 40196 KB | Output is correct |
10 | Correct | 43 ms | 40196 KB | Output is correct |
11 | Incorrect | 40 ms | 40196 KB | Output isn't correct |
12 | Correct | 32 ms | 40196 KB | Output is correct |
13 | Correct | 34 ms | 40196 KB | Output is correct |
14 | Correct | 32 ms | 40196 KB | Output is correct |
15 | Correct | 38 ms | 40196 KB | Output is correct |
16 | Correct | 47 ms | 40208 KB | Output is correct |
17 | Correct | 35 ms | 40208 KB | Output is correct |
18 | Incorrect | 49 ms | 40208 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 153 ms | 40208 KB | Output is correct |
2 | Correct | 131 ms | 40208 KB | Output is correct |
3 | Correct | 174 ms | 40208 KB | Output is correct |
4 | Correct | 293 ms | 40208 KB | Output is correct |
5 | Correct | 306 ms | 40468 KB | Output is correct |
6 | Correct | 313 ms | 40468 KB | Output is correct |
7 | Correct | 179 ms | 40468 KB | Output is correct |
8 | Correct | 152 ms | 40468 KB | Output is correct |
9 | Correct | 152 ms | 40468 KB | Output is correct |
10 | Correct | 101 ms | 40468 KB | Output is correct |
11 | Correct | 125 ms | 40468 KB | Output is correct |
12 | Correct | 128 ms | 40468 KB | Output is correct |
13 | Correct | 270 ms | 40468 KB | Output is correct |
14 | Correct | 111 ms | 41216 KB | Output is correct |
15 | Correct | 146 ms | 41216 KB | Output is correct |
16 | Correct | 146 ms | 41216 KB | Output is correct |
17 | Correct | 82 ms | 41216 KB | Output is correct |
18 | Correct | 115 ms | 41216 KB | Output is correct |
19 | Correct | 104 ms | 41216 KB | Output is correct |
20 | Correct | 173 ms | 41216 KB | Output is correct |
21 | Correct | 116 ms | 41216 KB | Output is correct |
22 | Correct | 309 ms | 41216 KB | Output is correct |
23 | Correct | 308 ms | 41216 KB | Output is correct |
24 | Correct | 293 ms | 41216 KB | Output is correct |
25 | Correct | 321 ms | 41216 KB | Output is correct |
26 | Correct | 288 ms | 41216 KB | Output is correct |
27 | Correct | 188 ms | 41216 KB | Output is correct |
28 | Correct | 272 ms | 41216 KB | Output is correct |
29 | Correct | 314 ms | 41216 KB | Output is correct |
30 | Correct | 312 ms | 41216 KB | Output is correct |
31 | Correct | 272 ms | 41216 KB | Output is correct |
32 | Correct | 310 ms | 41216 KB | Output is correct |
33 | Correct | 298 ms | 41216 KB | Output is correct |
34 | Correct | 197 ms | 41216 KB | Output is correct |
35 | Correct | 279 ms | 41216 KB | Output is correct |
36 | Correct | 297 ms | 41216 KB | Output is correct |
37 | Correct | 289 ms | 41216 KB | Output is correct |
38 | Correct | 350 ms | 41216 KB | Output is correct |
39 | Correct | 307 ms | 41216 KB | Output is correct |
40 | Correct | 304 ms | 41216 KB | Output is correct |
41 | Correct | 175 ms | 41216 KB | Output is correct |
42 | Correct | 274 ms | 41216 KB | Output is correct |