# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
256801 | 2020-08-03T08:31:33 Z | 문홍윤(#5040) | Snake Escaping (JOI18_snake_escaping) | C++17 | 530 ms | 14932 KB |
#include <bits/stdc++.h> #define eb emplace_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define svec(x) sort(x.begin(), x.end()) #define press(x) x.erase(unique(x.begin(), x.end()), x.end()) #define lb(x, v) lower_bound(x.begin(), x.end(), v) #define ub(x, v) upper_bound(x.begin(), x.end(), v) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<int, LL> pil; typedef pair<LL, int> pli; const LL llinf=2000000000000000000; const LL mod1=1000000007; const LL mod2=998244353; const int inf=2000000000; int n, q, dp[2000010], pw[30]; char str[1100000]; int arr[1100000]; char qu[30]; int main(){ scanf("%d %d", &n, &q); scanf("%s", str); int len=strlen(str); for(int i=0; i<len; i++)arr[i]=(int)(str[i]-'0'); pw[0]=1; for(int i=1; i<=n; i++)pw[i]=pw[i-1]*3; for(int u=0; u<pw[n]; u++){ int tmp=u, num=0; for(int i=n; i>=1; i--){ if(tmp%3==0)qu[i]='0'; if(tmp%3==1)qu[i]='1'; if(tmp%3==2){ qu[i]='?'; num=i; } tmp/=3; } if(num)dp[u]=dp[u-pw[n-num]]+dp[u-2*pw[n-num]]; else{ int temp=0; for(int i=1; i<=n; i++){ temp*=2; if(qu[i]=='1')temp++; } dp[u]=arr[temp]; } } for(int u=1; u<=q; u++){ memset(qu, 0, sizeof qu); scanf("%s", qu+1); int nw=0; for(int i=1; i<=n; i++){ nw*=3; if(qu[i]=='1')nw++; if(qu[i]=='?')nw+=2; } printf("%d\n", dp[nw]); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 512 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
3 | Correct | 6 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 512 KB | Output is correct |
8 | Correct | 5 ms | 640 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 5 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 512 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
3 | Correct | 6 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 512 KB | Output is correct |
8 | Correct | 5 ms | 640 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 5 ms | 512 KB | Output is correct |
11 | Correct | 290 ms | 4584 KB | Output is correct |
12 | Correct | 262 ms | 4344 KB | Output is correct |
13 | Correct | 278 ms | 3448 KB | Output is correct |
14 | Correct | 275 ms | 3764 KB | Output is correct |
15 | Correct | 285 ms | 4600 KB | Output is correct |
16 | Correct | 292 ms | 3704 KB | Output is correct |
17 | Correct | 289 ms | 3704 KB | Output is correct |
18 | Correct | 259 ms | 6648 KB | Output is correct |
19 | Correct | 284 ms | 4984 KB | Output is correct |
20 | Correct | 308 ms | 6736 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 512 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
3 | Correct | 6 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 512 KB | Output is correct |
8 | Correct | 5 ms | 640 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 5 ms | 512 KB | Output is correct |
11 | Correct | 290 ms | 4584 KB | Output is correct |
12 | Correct | 262 ms | 4344 KB | Output is correct |
13 | Correct | 278 ms | 3448 KB | Output is correct |
14 | Correct | 275 ms | 3764 KB | Output is correct |
15 | Correct | 285 ms | 4600 KB | Output is correct |
16 | Correct | 292 ms | 3704 KB | Output is correct |
17 | Correct | 289 ms | 3704 KB | Output is correct |
18 | Correct | 259 ms | 6648 KB | Output is correct |
19 | Correct | 284 ms | 4984 KB | Output is correct |
20 | Correct | 308 ms | 6736 KB | Output is correct |
21 | Correct | 530 ms | 12916 KB | Output is correct |
22 | Correct | 409 ms | 13048 KB | Output is correct |
23 | Correct | 473 ms | 12152 KB | Output is correct |
24 | Correct | 480 ms | 11896 KB | Output is correct |
25 | Correct | 442 ms | 13944 KB | Output is correct |
26 | Correct | 496 ms | 12536 KB | Output is correct |
27 | Correct | 484 ms | 12540 KB | Output is correct |
28 | Correct | 394 ms | 14932 KB | Output is correct |
29 | Correct | 430 ms | 11000 KB | Output is correct |
30 | Correct | 455 ms | 13176 KB | Output is correct |
31 | Correct | 461 ms | 13048 KB | Output is correct |
32 | Correct | 455 ms | 12920 KB | Output is correct |
33 | Correct | 452 ms | 12152 KB | Output is correct |
34 | Correct | 480 ms | 12024 KB | Output is correct |
35 | Correct | 529 ms | 12588 KB | Output is correct |
36 | Correct | 395 ms | 10904 KB | Output is correct |
37 | Correct | 388 ms | 13052 KB | Output is correct |
38 | Correct | 434 ms | 11000 KB | Output is correct |
39 | Correct | 457 ms | 12200 KB | Output is correct |
40 | Correct | 447 ms | 11896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 512 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
3 | Correct | 6 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 512 KB | Output is correct |
8 | Correct | 5 ms | 640 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 5 ms | 512 KB | Output is correct |
11 | Runtime error | 14 ms | 10880 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 512 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
3 | Correct | 6 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 512 KB | Output is correct |
8 | Correct | 5 ms | 640 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 5 ms | 512 KB | Output is correct |
11 | Correct | 290 ms | 4584 KB | Output is correct |
12 | Correct | 262 ms | 4344 KB | Output is correct |
13 | Correct | 278 ms | 3448 KB | Output is correct |
14 | Correct | 275 ms | 3764 KB | Output is correct |
15 | Correct | 285 ms | 4600 KB | Output is correct |
16 | Correct | 292 ms | 3704 KB | Output is correct |
17 | Correct | 289 ms | 3704 KB | Output is correct |
18 | Correct | 259 ms | 6648 KB | Output is correct |
19 | Correct | 284 ms | 4984 KB | Output is correct |
20 | Correct | 308 ms | 6736 KB | Output is correct |
21 | Correct | 530 ms | 12916 KB | Output is correct |
22 | Correct | 409 ms | 13048 KB | Output is correct |
23 | Correct | 473 ms | 12152 KB | Output is correct |
24 | Correct | 480 ms | 11896 KB | Output is correct |
25 | Correct | 442 ms | 13944 KB | Output is correct |
26 | Correct | 496 ms | 12536 KB | Output is correct |
27 | Correct | 484 ms | 12540 KB | Output is correct |
28 | Correct | 394 ms | 14932 KB | Output is correct |
29 | Correct | 430 ms | 11000 KB | Output is correct |
30 | Correct | 455 ms | 13176 KB | Output is correct |
31 | Correct | 461 ms | 13048 KB | Output is correct |
32 | Correct | 455 ms | 12920 KB | Output is correct |
33 | Correct | 452 ms | 12152 KB | Output is correct |
34 | Correct | 480 ms | 12024 KB | Output is correct |
35 | Correct | 529 ms | 12588 KB | Output is correct |
36 | Correct | 395 ms | 10904 KB | Output is correct |
37 | Correct | 388 ms | 13052 KB | Output is correct |
38 | Correct | 434 ms | 11000 KB | Output is correct |
39 | Correct | 457 ms | 12200 KB | Output is correct |
40 | Correct | 447 ms | 11896 KB | Output is correct |
41 | Runtime error | 14 ms | 10880 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
42 | Halted | 0 ms | 0 KB | - |