Submission #437224

# Submission time Handle Problem Language Result Execution time Memory
437224 2021-06-26T05:13:46 Z cpp219 Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1608 ms 61496 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
ii queries[1000011];
char a[(1<<20)+12];
int ans[1000011];
 
const int N = 1594323;
const int LG = 13;
const int N2 = 2187;
const int LG2 = 7;
 
int dp[N+3];
int nxt[N+3][2];
bitset<(1<<LG2)+1> subbit[N2+3];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	for(int i=0;i<N;i++)
	{
		int cur=i; bool pos=0; int t=1;
		for(int j=LG-1;j>=0;j--)
		{
			if(cur%3==2)
			{
				nxt[i][1] = i - t;
				nxt[i][0] = i - t - t;
				pos=1; break;
			}
			cur/=3; t*=3;
		}
		if(!pos)
		{
			nxt[i][0]=nxt[i][1]=-1;
		}
	}
	for(int i=0;i<N2;i++)
	{
		int tmp[LG2+1]={};
		int cur=i;
		for(int j=LG2-1;j>=0;j--)
		{
			tmp[j] = cur%3;
			cur/=3;
		}
		for(int j=0;j<(1<<LG2);j++)
		{
			bool pos=1; int cur2=j;
			for(int k=LG2-1;k>=0;k--)
			{
				int t=cur2&1; cur2>>=1;
				if(tmp[k]==2) continue;
				if(tmp[k]==t) continue;
				pos=0; break;
			}
			if(pos) subbit[i].set(j,1);
		}
	}
	int l,q; cin>>l>>q;
	cin>>a;
	for(int i=0;i<q;i++)
	{
		char x[21]; cin>>x;
		for(int j=0;j<min(l,LG2);j++)
		{
			queries[i].fi*=3;
			queries[i].fi+=(x[j]=='0'?0:(x[j]=='1'?1:2));
		}
		for(int j=LG2;j<l;j++)
		{
			queries[i].se*=3;
			queries[i].se+=(x[j]=='0'?0:(x[j]=='1'?1:2));
		}
	}
	int rhs = max(0, l - LG2);
	for(int i=0;i<(1<<min(l,LG2));i++)
	{
		for(int j=0;j<N;j++)
		{
			if(nxt[j][0]==-1)
			{
				int cur=j; int bit = 0;
				for(int k=0;k<rhs;k++)
				{
					if(cur%3) bit^=(1<<k);
					cur/=3;
				}
				dp[j] = a[(i<<rhs)^bit]-'0';
			}
			else
			{
				dp[j] = dp[nxt[j][0]]+dp[nxt[j][1]];
			}
		}
		for(int j=0;j<q;j++)
		{
			if(subbit[queries[j].fi][i])
			{
				ans[j] += dp[queries[j].se];
			}
		}
	}
	for(int i=0;i<q;i++)
	{
		cout<<ans[i]<<'\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 304 ms 19148 KB Output is correct
2 Correct 332 ms 19108 KB Output is correct
3 Correct 324 ms 19108 KB Output is correct
4 Correct 345 ms 19104 KB Output is correct
5 Correct 353 ms 19116 KB Output is correct
6 Correct 314 ms 19048 KB Output is correct
7 Correct 309 ms 19020 KB Output is correct
8 Correct 323 ms 18996 KB Output is correct
9 Correct 327 ms 19020 KB Output is correct
10 Correct 316 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 19148 KB Output is correct
2 Correct 332 ms 19108 KB Output is correct
3 Correct 324 ms 19108 KB Output is correct
4 Correct 345 ms 19104 KB Output is correct
5 Correct 353 ms 19116 KB Output is correct
6 Correct 314 ms 19048 KB Output is correct
7 Correct 309 ms 19020 KB Output is correct
8 Correct 323 ms 18996 KB Output is correct
9 Correct 327 ms 19020 KB Output is correct
10 Correct 316 ms 19028 KB Output is correct
11 Correct 898 ms 34884 KB Output is correct
12 Correct 1012 ms 34396 KB Output is correct
13 Correct 871 ms 33688 KB Output is correct
14 Correct 882 ms 33872 KB Output is correct
15 Correct 1012 ms 34728 KB Output is correct
16 Correct 902 ms 33988 KB Output is correct
17 Correct 900 ms 33884 KB Output is correct
18 Correct 719 ms 35808 KB Output is correct
19 Correct 834 ms 32740 KB Output is correct
20 Correct 970 ms 34536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 19148 KB Output is correct
2 Correct 332 ms 19108 KB Output is correct
3 Correct 324 ms 19108 KB Output is correct
4 Correct 345 ms 19104 KB Output is correct
5 Correct 353 ms 19116 KB Output is correct
6 Correct 314 ms 19048 KB Output is correct
7 Correct 309 ms 19020 KB Output is correct
8 Correct 323 ms 18996 KB Output is correct
9 Correct 327 ms 19020 KB Output is correct
10 Correct 316 ms 19028 KB Output is correct
11 Correct 898 ms 34884 KB Output is correct
12 Correct 1012 ms 34396 KB Output is correct
13 Correct 871 ms 33688 KB Output is correct
14 Correct 882 ms 33872 KB Output is correct
15 Correct 1012 ms 34728 KB Output is correct
16 Correct 902 ms 33988 KB Output is correct
17 Correct 900 ms 33884 KB Output is correct
18 Correct 719 ms 35808 KB Output is correct
19 Correct 834 ms 32740 KB Output is correct
20 Correct 970 ms 34536 KB Output is correct
21 Correct 975 ms 34792 KB Output is correct
22 Correct 1075 ms 34928 KB Output is correct
23 Correct 923 ms 34012 KB Output is correct
24 Correct 899 ms 33832 KB Output is correct
25 Correct 1102 ms 35828 KB Output is correct
26 Correct 906 ms 34308 KB Output is correct
27 Correct 955 ms 34280 KB Output is correct
28 Correct 750 ms 36800 KB Output is correct
29 Correct 870 ms 32876 KB Output is correct
30 Correct 968 ms 34928 KB Output is correct
31 Correct 971 ms 34884 KB Output is correct
32 Correct 898 ms 34808 KB Output is correct
33 Correct 868 ms 33760 KB Output is correct
34 Correct 932 ms 33924 KB Output is correct
35 Correct 939 ms 34244 KB Output is correct
36 Correct 728 ms 32912 KB Output is correct
37 Correct 995 ms 34932 KB Output is correct
38 Correct 860 ms 32788 KB Output is correct
39 Correct 875 ms 33908 KB Output is correct
40 Correct 922 ms 33760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 19148 KB Output is correct
2 Correct 332 ms 19108 KB Output is correct
3 Correct 324 ms 19108 KB Output is correct
4 Correct 345 ms 19104 KB Output is correct
5 Correct 353 ms 19116 KB Output is correct
6 Correct 314 ms 19048 KB Output is correct
7 Correct 309 ms 19020 KB Output is correct
8 Correct 323 ms 18996 KB Output is correct
9 Correct 327 ms 19020 KB Output is correct
10 Correct 316 ms 19028 KB Output is correct
11 Correct 365 ms 20956 KB Output is correct
12 Correct 461 ms 20956 KB Output is correct
13 Correct 453 ms 20828 KB Output is correct
14 Correct 398 ms 20804 KB Output is correct
15 Correct 420 ms 20960 KB Output is correct
16 Correct 383 ms 20840 KB Output is correct
17 Correct 411 ms 20828 KB Output is correct
18 Correct 384 ms 21188 KB Output is correct
19 Correct 378 ms 20736 KB Output is correct
20 Correct 371 ms 20840 KB Output is correct
21 Correct 459 ms 20956 KB Output is correct
22 Correct 400 ms 20832 KB Output is correct
23 Correct 388 ms 20932 KB Output is correct
24 Correct 399 ms 20840 KB Output is correct
25 Correct 401 ms 20908 KB Output is correct
26 Correct 378 ms 20804 KB Output is correct
27 Correct 371 ms 20956 KB Output is correct
28 Correct 450 ms 20700 KB Output is correct
29 Correct 370 ms 20836 KB Output is correct
30 Correct 400 ms 20900 KB Output is correct
31 Correct 374 ms 20840 KB Output is correct
32 Correct 390 ms 20828 KB Output is correct
33 Correct 466 ms 20836 KB Output is correct
34 Correct 363 ms 20696 KB Output is correct
35 Correct 411 ms 20828 KB Output is correct
36 Correct 403 ms 20824 KB Output is correct
37 Correct 404 ms 20828 KB Output is correct
38 Correct 428 ms 20904 KB Output is correct
39 Correct 410 ms 20932 KB Output is correct
40 Correct 387 ms 20928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 19148 KB Output is correct
2 Correct 332 ms 19108 KB Output is correct
3 Correct 324 ms 19108 KB Output is correct
4 Correct 345 ms 19104 KB Output is correct
5 Correct 353 ms 19116 KB Output is correct
6 Correct 314 ms 19048 KB Output is correct
7 Correct 309 ms 19020 KB Output is correct
8 Correct 323 ms 18996 KB Output is correct
9 Correct 327 ms 19020 KB Output is correct
10 Correct 316 ms 19028 KB Output is correct
11 Correct 898 ms 34884 KB Output is correct
12 Correct 1012 ms 34396 KB Output is correct
13 Correct 871 ms 33688 KB Output is correct
14 Correct 882 ms 33872 KB Output is correct
15 Correct 1012 ms 34728 KB Output is correct
16 Correct 902 ms 33988 KB Output is correct
17 Correct 900 ms 33884 KB Output is correct
18 Correct 719 ms 35808 KB Output is correct
19 Correct 834 ms 32740 KB Output is correct
20 Correct 970 ms 34536 KB Output is correct
21 Correct 975 ms 34792 KB Output is correct
22 Correct 1075 ms 34928 KB Output is correct
23 Correct 923 ms 34012 KB Output is correct
24 Correct 899 ms 33832 KB Output is correct
25 Correct 1102 ms 35828 KB Output is correct
26 Correct 906 ms 34308 KB Output is correct
27 Correct 955 ms 34280 KB Output is correct
28 Correct 750 ms 36800 KB Output is correct
29 Correct 870 ms 32876 KB Output is correct
30 Correct 968 ms 34928 KB Output is correct
31 Correct 971 ms 34884 KB Output is correct
32 Correct 898 ms 34808 KB Output is correct
33 Correct 868 ms 33760 KB Output is correct
34 Correct 932 ms 33924 KB Output is correct
35 Correct 939 ms 34244 KB Output is correct
36 Correct 728 ms 32912 KB Output is correct
37 Correct 995 ms 34932 KB Output is correct
38 Correct 860 ms 32788 KB Output is correct
39 Correct 875 ms 33908 KB Output is correct
40 Correct 922 ms 33760 KB Output is correct
41 Correct 365 ms 20956 KB Output is correct
42 Correct 461 ms 20956 KB Output is correct
43 Correct 453 ms 20828 KB Output is correct
44 Correct 398 ms 20804 KB Output is correct
45 Correct 420 ms 20960 KB Output is correct
46 Correct 383 ms 20840 KB Output is correct
47 Correct 411 ms 20828 KB Output is correct
48 Correct 384 ms 21188 KB Output is correct
49 Correct 378 ms 20736 KB Output is correct
50 Correct 371 ms 20840 KB Output is correct
51 Correct 459 ms 20956 KB Output is correct
52 Correct 400 ms 20832 KB Output is correct
53 Correct 388 ms 20932 KB Output is correct
54 Correct 399 ms 20840 KB Output is correct
55 Correct 401 ms 20908 KB Output is correct
56 Correct 378 ms 20804 KB Output is correct
57 Correct 371 ms 20956 KB Output is correct
58 Correct 450 ms 20700 KB Output is correct
59 Correct 370 ms 20836 KB Output is correct
60 Correct 400 ms 20900 KB Output is correct
61 Correct 374 ms 20840 KB Output is correct
62 Correct 390 ms 20828 KB Output is correct
63 Correct 466 ms 20836 KB Output is correct
64 Correct 363 ms 20696 KB Output is correct
65 Correct 411 ms 20828 KB Output is correct
66 Correct 403 ms 20824 KB Output is correct
67 Correct 404 ms 20828 KB Output is correct
68 Correct 428 ms 20904 KB Output is correct
69 Correct 410 ms 20932 KB Output is correct
70 Correct 387 ms 20928 KB Output is correct
71 Correct 994 ms 36884 KB Output is correct
72 Correct 1153 ms 36932 KB Output is correct
73 Correct 1169 ms 35500 KB Output is correct
74 Correct 1345 ms 41196 KB Output is correct
75 Correct 1572 ms 59440 KB Output is correct
76 Correct 1532 ms 57832 KB Output is correct
77 Correct 1500 ms 57516 KB Output is correct
78 Correct 810 ms 61496 KB Output is correct
79 Correct 966 ms 55364 KB Output is correct
80 Correct 1094 ms 58540 KB Output is correct
81 Correct 1594 ms 58436 KB Output is correct
82 Correct 1450 ms 57428 KB Output is correct
83 Correct 974 ms 56592 KB Output is correct
84 Correct 1401 ms 57384 KB Output is correct
85 Correct 1608 ms 57512 KB Output is correct
86 Correct 808 ms 55432 KB Output is correct
87 Correct 1179 ms 58408 KB Output is correct
88 Correct 1122 ms 55340 KB Output is correct
89 Correct 1266 ms 57000 KB Output is correct
90 Correct 1423 ms 57388 KB Output is correct
91 Correct 1096 ms 56528 KB Output is correct
92 Correct 1547 ms 57712 KB Output is correct
93 Correct 1600 ms 57520 KB Output is correct
94 Correct 803 ms 55344 KB Output is correct
95 Correct 1487 ms 57516 KB Output is correct
96 Correct 1498 ms 57512 KB Output is correct
97 Correct 1474 ms 57516 KB Output is correct
98 Correct 1477 ms 57516 KB Output is correct
99 Correct 1478 ms 57468 KB Output is correct
100 Correct 1606 ms 57512 KB Output is correct