답안 #539323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539323 2022-03-18T17:33:10 Z pnm1384 Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
1002 ms 20208 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 21;
int dp[1 << N], dp2[1 << N], cnt[3], bads[N];
string ss;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int len, q;
	cin >> len >> q >> ss;
	for (int i = 0; i < (1 << len); i++)
	{
		dp[i] = ss[i] - '0';
		dp2[i] = ss[i] - '0';
	}
	for (int i = 0; i < len; i++)
	{
		for (int mask = 0; mask < (1 << len); mask++)
		{
			if (!((mask >> i) & 1)) dp[mask] += dp[mask ^ (1 << i)];
			else dp2[mask] += dp2[mask ^ (1 << i)];
		}
	}
	for (int jj = 0; jj < q; jj++)
	{
		string s2;
		cin >> s2;
		reverse(s2.begin(), s2.end());
		for (int j = 0; j < 3; j++) cnt[j] = 0;
		for (int i = 0; i < len; i++)
		{
			if (s2[i] == '?') cnt[0]++;
			else cnt[s2[i] - '0' + 1]++;
		}
		int ans = 0;
		if (cnt[0] <= 6)
		{
			int msk = 0;
			for (int i = 0; i < len; i++)
			{
				if (s2[i] == '1') msk ^= (1 << i);
			}
			int ttt = 0;
			for (int i = 0; i < len; i++)
			{
				if (s2[i] == '?') bads[ttt++] = i;
			}
			for (int mask = 0; mask < (1 << ttt); mask++)
			{
				int msk2 = msk;
				for (int i = 0; i < ttt; i++)
				{
					if ((mask >> i) & 1) msk2 |= (1 << bads[i]);
				}
				ans += ss[msk2] - '0';
			}
			cout << ans << '\n';
			continue;
		}
		if (cnt[1] <= 6)
		{
			int msk = 0;
			for (int i = 0; i < len; i++)
			{
				if (s2[i] == '1') msk ^= (1 << i);
			}
			int ttt = 0;
			for (int i = 0; i < len; i++)
			{
				if (s2[i] == '0') bads[ttt++] = i;
			}
			for (int mask = 0; mask < (1 << ttt); mask++)
			{
				int msk2 = msk;
				for (int i = 0; i < ttt; i++)
				{
					if ((mask >> i) & 1) msk2 |= (1 << bads[i]);
				}
				int f = 1;
				if (__builtin_parity(mask)) f = -1;
				ans += f * dp[msk2];
			}
			cout << ans << '\n';
			continue;
		}
		int msk = 0;
		for (int i = 0; i < len; i++)
		{
			if (s2[i] == '?') msk ^= (1 << i);
		}
		int ttt = 0;
		for (int i = 0; i < len; i++)
		{
			if (s2[i] == '1') bads[ttt++] = i;
		}
		for (int mask = 0; mask < (1 << ttt); mask++)
		{
			int msk2 = msk;
			for (int i = 0; i < ttt; i++)
			{
				if ((mask >> i) & 1) msk2 |= (1 << bads[i]);
			}
			int f = 1;
			if (__builtin_parity(mask)) f = -1;
			ans += f * dp2[msk2];
		}
		cout << ans << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 500 ms 15048 KB Output is correct
12 Correct 555 ms 14732 KB Output is correct
13 Correct 385 ms 14004 KB Output is correct
14 Correct 323 ms 14100 KB Output is correct
15 Correct 877 ms 15136 KB Output is correct
16 Correct 445 ms 14260 KB Output is correct
17 Correct 439 ms 14140 KB Output is correct
18 Correct 255 ms 16076 KB Output is correct
19 Correct 266 ms 13124 KB Output is correct
20 Correct 551 ms 14660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 500 ms 15048 KB Output is correct
12 Correct 555 ms 14732 KB Output is correct
13 Correct 385 ms 14004 KB Output is correct
14 Correct 323 ms 14100 KB Output is correct
15 Correct 877 ms 15136 KB Output is correct
16 Correct 445 ms 14260 KB Output is correct
17 Correct 439 ms 14140 KB Output is correct
18 Correct 255 ms 16076 KB Output is correct
19 Correct 266 ms 13124 KB Output is correct
20 Correct 551 ms 14660 KB Output is correct
21 Correct 330 ms 18092 KB Output is correct
22 Correct 755 ms 18456 KB Output is correct
23 Correct 509 ms 17300 KB Output is correct
24 Correct 450 ms 17132 KB Output is correct
25 Correct 390 ms 19064 KB Output is correct
26 Correct 606 ms 17620 KB Output is correct
27 Correct 636 ms 17488 KB Output is correct
28 Correct 242 ms 20208 KB Output is correct
29 Correct 302 ms 16104 KB Output is correct
30 Correct 563 ms 18208 KB Output is correct
31 Correct 1002 ms 18344 KB Output is correct
32 Correct 609 ms 18064 KB Output is correct
33 Correct 433 ms 16936 KB Output is correct
34 Correct 455 ms 17068 KB Output is correct
35 Correct 589 ms 17584 KB Output is correct
36 Correct 247 ms 16084 KB Output is correct
37 Correct 990 ms 18116 KB Output is correct
38 Correct 310 ms 16076 KB Output is correct
39 Correct 519 ms 17304 KB Output is correct
40 Correct 440 ms 17096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 58 ms 11896 KB Output is correct
12 Correct 55 ms 11952 KB Output is correct
13 Incorrect 63 ms 11856 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 500 ms 15048 KB Output is correct
12 Correct 555 ms 14732 KB Output is correct
13 Correct 385 ms 14004 KB Output is correct
14 Correct 323 ms 14100 KB Output is correct
15 Correct 877 ms 15136 KB Output is correct
16 Correct 445 ms 14260 KB Output is correct
17 Correct 439 ms 14140 KB Output is correct
18 Correct 255 ms 16076 KB Output is correct
19 Correct 266 ms 13124 KB Output is correct
20 Correct 551 ms 14660 KB Output is correct
21 Correct 330 ms 18092 KB Output is correct
22 Correct 755 ms 18456 KB Output is correct
23 Correct 509 ms 17300 KB Output is correct
24 Correct 450 ms 17132 KB Output is correct
25 Correct 390 ms 19064 KB Output is correct
26 Correct 606 ms 17620 KB Output is correct
27 Correct 636 ms 17488 KB Output is correct
28 Correct 242 ms 20208 KB Output is correct
29 Correct 302 ms 16104 KB Output is correct
30 Correct 563 ms 18208 KB Output is correct
31 Correct 1002 ms 18344 KB Output is correct
32 Correct 609 ms 18064 KB Output is correct
33 Correct 433 ms 16936 KB Output is correct
34 Correct 455 ms 17068 KB Output is correct
35 Correct 589 ms 17584 KB Output is correct
36 Correct 247 ms 16084 KB Output is correct
37 Correct 990 ms 18116 KB Output is correct
38 Correct 310 ms 16076 KB Output is correct
39 Correct 519 ms 17304 KB Output is correct
40 Correct 440 ms 17096 KB Output is correct
41 Correct 58 ms 11896 KB Output is correct
42 Correct 55 ms 11952 KB Output is correct
43 Incorrect 63 ms 11856 KB Output isn't correct
44 Halted 0 ms 0 KB -