Submission #41068

# Submission time Handle Problem Language Result Execution time Memory
41068 2018-02-12T10:50:58 Z zscoder Snake Escaping (JOI18_snake_escaping) C++14
100 / 100
1665 ms 40128 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 385 ms 19192 KB Output is correct
2 Correct 396 ms 19364 KB Output is correct
3 Correct 342 ms 19364 KB Output is correct
4 Correct 351 ms 19384 KB Output is correct
5 Correct 388 ms 19440 KB Output is correct
6 Correct 403 ms 19440 KB Output is correct
7 Correct 368 ms 19440 KB Output is correct
8 Correct 401 ms 19440 KB Output is correct
9 Correct 379 ms 19500 KB Output is correct
10 Correct 334 ms 19500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 19192 KB Output is correct
2 Correct 396 ms 19364 KB Output is correct
3 Correct 342 ms 19364 KB Output is correct
4 Correct 351 ms 19384 KB Output is correct
5 Correct 388 ms 19440 KB Output is correct
6 Correct 403 ms 19440 KB Output is correct
7 Correct 368 ms 19440 KB Output is correct
8 Correct 401 ms 19440 KB Output is correct
9 Correct 379 ms 19500 KB Output is correct
10 Correct 334 ms 19500 KB Output is correct
11 Correct 969 ms 35020 KB Output is correct
12 Correct 1117 ms 35020 KB Output is correct
13 Correct 867 ms 35020 KB Output is correct
14 Correct 885 ms 35020 KB Output is correct
15 Correct 1129 ms 35100 KB Output is correct
16 Correct 919 ms 35100 KB Output is correct
17 Correct 992 ms 35100 KB Output is correct
18 Correct 855 ms 36068 KB Output is correct
19 Correct 875 ms 36068 KB Output is correct
20 Correct 1032 ms 36068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 19192 KB Output is correct
2 Correct 396 ms 19364 KB Output is correct
3 Correct 342 ms 19364 KB Output is correct
4 Correct 351 ms 19384 KB Output is correct
5 Correct 388 ms 19440 KB Output is correct
6 Correct 403 ms 19440 KB Output is correct
7 Correct 368 ms 19440 KB Output is correct
8 Correct 401 ms 19440 KB Output is correct
9 Correct 379 ms 19500 KB Output is correct
10 Correct 334 ms 19500 KB Output is correct
11 Correct 969 ms 35020 KB Output is correct
12 Correct 1117 ms 35020 KB Output is correct
13 Correct 867 ms 35020 KB Output is correct
14 Correct 885 ms 35020 KB Output is correct
15 Correct 1129 ms 35100 KB Output is correct
16 Correct 919 ms 35100 KB Output is correct
17 Correct 992 ms 35100 KB Output is correct
18 Correct 855 ms 36068 KB Output is correct
19 Correct 875 ms 36068 KB Output is correct
20 Correct 1032 ms 36068 KB Output is correct
21 Correct 1041 ms 36068 KB Output is correct
22 Correct 1113 ms 36068 KB Output is correct
23 Correct 1018 ms 36068 KB Output is correct
24 Correct 1038 ms 36068 KB Output is correct
25 Correct 1221 ms 36264 KB Output is correct
26 Correct 963 ms 36264 KB Output is correct
27 Correct 1000 ms 36264 KB Output is correct
28 Correct 854 ms 37036 KB Output is correct
29 Correct 929 ms 37036 KB Output is correct
30 Correct 1020 ms 37036 KB Output is correct
31 Correct 1074 ms 37036 KB Output is correct
32 Correct 961 ms 37036 KB Output is correct
33 Correct 920 ms 37036 KB Output is correct
34 Correct 987 ms 37036 KB Output is correct
35 Correct 967 ms 37036 KB Output is correct
36 Correct 723 ms 37036 KB Output is correct
37 Correct 1053 ms 37036 KB Output is correct
38 Correct 902 ms 37036 KB Output is correct
39 Correct 927 ms 37036 KB Output is correct
40 Correct 940 ms 37036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 19192 KB Output is correct
2 Correct 396 ms 19364 KB Output is correct
3 Correct 342 ms 19364 KB Output is correct
4 Correct 351 ms 19384 KB Output is correct
5 Correct 388 ms 19440 KB Output is correct
6 Correct 403 ms 19440 KB Output is correct
7 Correct 368 ms 19440 KB Output is correct
8 Correct 401 ms 19440 KB Output is correct
9 Correct 379 ms 19500 KB Output is correct
10 Correct 334 ms 19500 KB Output is correct
11 Correct 521 ms 37036 KB Output is correct
12 Correct 506 ms 37036 KB Output is correct
13 Correct 524 ms 37036 KB Output is correct
14 Correct 564 ms 37036 KB Output is correct
15 Correct 548 ms 37036 KB Output is correct
16 Correct 536 ms 37036 KB Output is correct
17 Correct 520 ms 37036 KB Output is correct
18 Correct 495 ms 37036 KB Output is correct
19 Correct 492 ms 37036 KB Output is correct
20 Correct 479 ms 37036 KB Output is correct
21 Correct 505 ms 37036 KB Output is correct
22 Correct 509 ms 37036 KB Output is correct
23 Correct 509 ms 37036 KB Output is correct
24 Correct 487 ms 37036 KB Output is correct
25 Correct 545 ms 37036 KB Output is correct
26 Correct 517 ms 37036 KB Output is correct
27 Correct 454 ms 37036 KB Output is correct
28 Correct 487 ms 37036 KB Output is correct
29 Correct 465 ms 37036 KB Output is correct
30 Correct 490 ms 37036 KB Output is correct
31 Correct 506 ms 37036 KB Output is correct
32 Correct 490 ms 37036 KB Output is correct
33 Correct 480 ms 37036 KB Output is correct
34 Correct 448 ms 37036 KB Output is correct
35 Correct 469 ms 37036 KB Output is correct
36 Correct 508 ms 37036 KB Output is correct
37 Correct 500 ms 37036 KB Output is correct
38 Correct 515 ms 37036 KB Output is correct
39 Correct 523 ms 37036 KB Output is correct
40 Correct 504 ms 37036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 19192 KB Output is correct
2 Correct 396 ms 19364 KB Output is correct
3 Correct 342 ms 19364 KB Output is correct
4 Correct 351 ms 19384 KB Output is correct
5 Correct 388 ms 19440 KB Output is correct
6 Correct 403 ms 19440 KB Output is correct
7 Correct 368 ms 19440 KB Output is correct
8 Correct 401 ms 19440 KB Output is correct
9 Correct 379 ms 19500 KB Output is correct
10 Correct 334 ms 19500 KB Output is correct
11 Correct 969 ms 35020 KB Output is correct
12 Correct 1117 ms 35020 KB Output is correct
13 Correct 867 ms 35020 KB Output is correct
14 Correct 885 ms 35020 KB Output is correct
15 Correct 1129 ms 35100 KB Output is correct
16 Correct 919 ms 35100 KB Output is correct
17 Correct 992 ms 35100 KB Output is correct
18 Correct 855 ms 36068 KB Output is correct
19 Correct 875 ms 36068 KB Output is correct
20 Correct 1032 ms 36068 KB Output is correct
21 Correct 1041 ms 36068 KB Output is correct
22 Correct 1113 ms 36068 KB Output is correct
23 Correct 1018 ms 36068 KB Output is correct
24 Correct 1038 ms 36068 KB Output is correct
25 Correct 1221 ms 36264 KB Output is correct
26 Correct 963 ms 36264 KB Output is correct
27 Correct 1000 ms 36264 KB Output is correct
28 Correct 854 ms 37036 KB Output is correct
29 Correct 929 ms 37036 KB Output is correct
30 Correct 1020 ms 37036 KB Output is correct
31 Correct 1074 ms 37036 KB Output is correct
32 Correct 961 ms 37036 KB Output is correct
33 Correct 920 ms 37036 KB Output is correct
34 Correct 987 ms 37036 KB Output is correct
35 Correct 967 ms 37036 KB Output is correct
36 Correct 723 ms 37036 KB Output is correct
37 Correct 1053 ms 37036 KB Output is correct
38 Correct 902 ms 37036 KB Output is correct
39 Correct 927 ms 37036 KB Output is correct
40 Correct 940 ms 37036 KB Output is correct
41 Correct 521 ms 37036 KB Output is correct
42 Correct 506 ms 37036 KB Output is correct
43 Correct 524 ms 37036 KB Output is correct
44 Correct 564 ms 37036 KB Output is correct
45 Correct 548 ms 37036 KB Output is correct
46 Correct 536 ms 37036 KB Output is correct
47 Correct 520 ms 37036 KB Output is correct
48 Correct 495 ms 37036 KB Output is correct
49 Correct 492 ms 37036 KB Output is correct
50 Correct 479 ms 37036 KB Output is correct
51 Correct 505 ms 37036 KB Output is correct
52 Correct 509 ms 37036 KB Output is correct
53 Correct 509 ms 37036 KB Output is correct
54 Correct 487 ms 37036 KB Output is correct
55 Correct 545 ms 37036 KB Output is correct
56 Correct 517 ms 37036 KB Output is correct
57 Correct 454 ms 37036 KB Output is correct
58 Correct 487 ms 37036 KB Output is correct
59 Correct 465 ms 37036 KB Output is correct
60 Correct 490 ms 37036 KB Output is correct
61 Correct 506 ms 37036 KB Output is correct
62 Correct 490 ms 37036 KB Output is correct
63 Correct 480 ms 37036 KB Output is correct
64 Correct 448 ms 37036 KB Output is correct
65 Correct 469 ms 37036 KB Output is correct
66 Correct 508 ms 37036 KB Output is correct
67 Correct 500 ms 37036 KB Output is correct
68 Correct 515 ms 37036 KB Output is correct
69 Correct 523 ms 37036 KB Output is correct
70 Correct 504 ms 37036 KB Output is correct
71 Correct 1187 ms 37036 KB Output is correct
72 Correct 1351 ms 37292 KB Output is correct
73 Correct 1342 ms 37292 KB Output is correct
74 Correct 1385 ms 37292 KB Output is correct
75 Correct 1665 ms 38192 KB Output is correct
76 Correct 1324 ms 38192 KB Output is correct
77 Correct 1363 ms 38192 KB Output is correct
78 Correct 920 ms 40128 KB Output is correct
79 Correct 983 ms 40128 KB Output is correct
80 Correct 1220 ms 40128 KB Output is correct
81 Correct 1443 ms 40128 KB Output is correct
82 Correct 1316 ms 40128 KB Output is correct
83 Correct 1171 ms 40128 KB Output is correct
84 Correct 1515 ms 40128 KB Output is correct
85 Correct 1562 ms 40128 KB Output is correct
86 Correct 830 ms 40128 KB Output is correct
87 Correct 1270 ms 40128 KB Output is correct
88 Correct 1040 ms 40128 KB Output is correct
89 Correct 1239 ms 40128 KB Output is correct
90 Correct 1313 ms 40128 KB Output is correct
91 Correct 1101 ms 40128 KB Output is correct
92 Correct 1364 ms 40128 KB Output is correct
93 Correct 1424 ms 40128 KB Output is correct
94 Correct 857 ms 40128 KB Output is correct
95 Correct 1437 ms 40128 KB Output is correct
96 Correct 1396 ms 40128 KB Output is correct
97 Correct 1442 ms 40128 KB Output is correct
98 Correct 1480 ms 40128 KB Output is correct
99 Correct 1357 ms 40128 KB Output is correct
100 Correct 1398 ms 40128 KB Output is correct