답안 #288684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
288684 2020-09-01T18:41:20 Z luciocf Snake Escaping (JOI18_snake_escaping) C++14
12 / 100
508 ms 65540 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 13;
 
int n, q;
char v[1<<maxn];
 
int b[1<<maxn];
 
map<int, int> dp[1<<maxn];
 
int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0);
 
	cin >> n >> q;
 
	for (int i = 0; i < (1<<n); i++)
	{
		cin >> v[i];
		v[i] = (int)(v[i]-'0');
	}
 
	for (int i = 1; i < (1<<n); i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i&(1<<j))
			{
				b[i] = j;
				break;
			}
		}
	}
 
	for (int fixo = (1<<n)-1; fixo >= 0; fixo--)
	{
		dp[fixo][0] = v[fixo];
 
		int mask = ((1<<n)-1)^fixo;
 
		vector<int> sub;
 
		for (int outro = mask; outro > 0; outro = (outro-1)&mask)
			sub.push_back(outro);
 
		sort(sub.begin(), sub.end());
 
		for (auto outro: sub)
		{
			int p = 0, q = 0;

			if (dp[fixo].find(outro^(1<<b[outro])) != dp[fixo].end())
				p = dp[fixo][outro^(1<<b[outro])];

			if (dp[fixo|(1<<b[outro])].find(outro^(1<<b[outro])) != dp[fixo|(1<<b[outro])].end())
				q = dp[fixo|(1<<b[outro])][outro^(1<<b[outro])];

			dp[fixo][outro] = p+q;
		}
	}
 
	while (q--)
	{
		int fixo = 0, outro = 0;
 
		for (int i = 0; i < n; i++)
		{
			char c;
			cin >> c;
 
			if (c == '?') outro += (1<<(n-i-1));
			else if (c == '1') fixo += (1<<(n-i-1));
		}
 
		cout << dp[fixo][outro] << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3584 KB Output is correct
2 Correct 15 ms 3584 KB Output is correct
3 Correct 15 ms 3584 KB Output is correct
4 Correct 15 ms 3584 KB Output is correct
5 Correct 16 ms 3584 KB Output is correct
6 Correct 15 ms 3584 KB Output is correct
7 Correct 16 ms 3584 KB Output is correct
8 Correct 16 ms 3584 KB Output is correct
9 Correct 15 ms 3584 KB Output is correct
10 Correct 15 ms 3584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3584 KB Output is correct
2 Correct 15 ms 3584 KB Output is correct
3 Correct 15 ms 3584 KB Output is correct
4 Correct 15 ms 3584 KB Output is correct
5 Correct 16 ms 3584 KB Output is correct
6 Correct 15 ms 3584 KB Output is correct
7 Correct 16 ms 3584 KB Output is correct
8 Correct 16 ms 3584 KB Output is correct
9 Correct 15 ms 3584 KB Output is correct
10 Correct 15 ms 3584 KB Output is correct
11 Correct 380 ms 7664 KB Output is correct
12 Correct 397 ms 7288 KB Output is correct
13 Correct 463 ms 6584 KB Output is correct
14 Correct 430 ms 6720 KB Output is correct
15 Correct 468 ms 7672 KB Output is correct
16 Correct 487 ms 6844 KB Output is correct
17 Correct 508 ms 6816 KB Output is correct
18 Correct 304 ms 8568 KB Output is correct
19 Correct 351 ms 5624 KB Output is correct
20 Correct 429 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3584 KB Output is correct
2 Correct 15 ms 3584 KB Output is correct
3 Correct 15 ms 3584 KB Output is correct
4 Correct 15 ms 3584 KB Output is correct
5 Correct 16 ms 3584 KB Output is correct
6 Correct 15 ms 3584 KB Output is correct
7 Correct 16 ms 3584 KB Output is correct
8 Correct 16 ms 3584 KB Output is correct
9 Correct 15 ms 3584 KB Output is correct
10 Correct 15 ms 3584 KB Output is correct
11 Correct 380 ms 7664 KB Output is correct
12 Correct 397 ms 7288 KB Output is correct
13 Correct 463 ms 6584 KB Output is correct
14 Correct 430 ms 6720 KB Output is correct
15 Correct 468 ms 7672 KB Output is correct
16 Correct 487 ms 6844 KB Output is correct
17 Correct 508 ms 6816 KB Output is correct
18 Correct 304 ms 8568 KB Output is correct
19 Correct 351 ms 5624 KB Output is correct
20 Correct 429 ms 7288 KB Output is correct
21 Runtime error 357 ms 65540 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3584 KB Output is correct
2 Correct 15 ms 3584 KB Output is correct
3 Correct 15 ms 3584 KB Output is correct
4 Correct 15 ms 3584 KB Output is correct
5 Correct 16 ms 3584 KB Output is correct
6 Correct 15 ms 3584 KB Output is correct
7 Correct 16 ms 3584 KB Output is correct
8 Correct 16 ms 3584 KB Output is correct
9 Correct 15 ms 3584 KB Output is correct
10 Correct 15 ms 3584 KB Output is correct
11 Runtime error 3 ms 1920 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3584 KB Output is correct
2 Correct 15 ms 3584 KB Output is correct
3 Correct 15 ms 3584 KB Output is correct
4 Correct 15 ms 3584 KB Output is correct
5 Correct 16 ms 3584 KB Output is correct
6 Correct 15 ms 3584 KB Output is correct
7 Correct 16 ms 3584 KB Output is correct
8 Correct 16 ms 3584 KB Output is correct
9 Correct 15 ms 3584 KB Output is correct
10 Correct 15 ms 3584 KB Output is correct
11 Correct 380 ms 7664 KB Output is correct
12 Correct 397 ms 7288 KB Output is correct
13 Correct 463 ms 6584 KB Output is correct
14 Correct 430 ms 6720 KB Output is correct
15 Correct 468 ms 7672 KB Output is correct
16 Correct 487 ms 6844 KB Output is correct
17 Correct 508 ms 6816 KB Output is correct
18 Correct 304 ms 8568 KB Output is correct
19 Correct 351 ms 5624 KB Output is correct
20 Correct 429 ms 7288 KB Output is correct
21 Runtime error 357 ms 65540 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -