답안 #101816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
101816 2019-03-20T11:59:30 Z KCSC Snake Escaping (JOI18_snake_escaping) C++14
58 / 100
2000 ms 14236 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 20;

char str[1 << DIM | 3], aux[DIM + 2];
int udp[1 << DIM], ddp[1 << DIM], cbit[1 << DIM];

int main(void) {
#ifdef HOME
	freopen("snake.in", "r", stdin);
	freopen("snake.out", "w", stdout);
#endif
	int n, q; cin >> n >> q >> str;
	for (int msk = 0; msk < (1 << n); ++msk) {
		cbit[msk] = cbit[msk >> 1] + (msk & 1);
		udp[msk] = ddp[msk] = str[msk] - '0'; }
	for (int b = 0; b < n; ++b) {
		for (int msk = 0; msk < (1 << n); ++msk) {
			if (msk & (1 << b)) {
				udp[msk ^ (1 << b)] += udp[msk]; }
			else {
				ddp[msk ^ (1 << b)] += ddp[msk]; } } }
	while (q--) {
		int msk0 = 0, msk1 = 0, mskq = 0; 
		cin >> aux; reverse(aux, aux + n);
		for (int i = 0; i < n; ++i) {
			if (aux[i] == '0') { msk0 ^= (1 << i); } 
			if (aux[i] == '1') { msk1 ^= (1 << i); }
			if (aux[i] == '?') { mskq ^= (1 << i); } }
		int ans = 0;
		if (cbit[mskq] <= 7) {
			for (int axm = mskq, nr = (1 << cbit[mskq]); nr; (--axm) &= mskq, --nr) {
				ans += str[axm ^ msk1] - '0'; } }
		else if (cbit[msk0] <= 7) {
			for (int axm = msk0, nr = (1 << cbit[msk0]); nr; (--axm) &= msk0, --nr) {
				ans += udp[msk1 ^ axm] * ((cbit[axm] & 1) ? -1 : 1); } }
		else if (cbit[msk1] <= 7) {
			for (int axm = msk1, nr = (1 << cbit[msk1]); nr; (--axm) &= msk1, --nr) {
				ans += ddp[mskq ^ msk1 ^ axm] * ((cbit[axm] & 1) ? -1 : 1); } }
		cout << ans << "\n"; }		   
	return 0; }
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Execution timed out 2053 ms 4172 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Execution timed out 2053 ms 4172 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 214 ms 13952 KB Output is correct
12 Correct 208 ms 13860 KB Output is correct
13 Correct 211 ms 13796 KB Output is correct
14 Correct 232 ms 13944 KB Output is correct
15 Correct 218 ms 14096 KB Output is correct
16 Correct 251 ms 13832 KB Output is correct
17 Correct 260 ms 13972 KB Output is correct
18 Correct 211 ms 14072 KB Output is correct
19 Correct 277 ms 13816 KB Output is correct
20 Correct 215 ms 14024 KB Output is correct
21 Correct 219 ms 13944 KB Output is correct
22 Correct 223 ms 13816 KB Output is correct
23 Correct 196 ms 13944 KB Output is correct
24 Correct 207 ms 13884 KB Output is correct
25 Correct 237 ms 14236 KB Output is correct
26 Correct 200 ms 13816 KB Output is correct
27 Correct 247 ms 13844 KB Output is correct
28 Correct 192 ms 13816 KB Output is correct
29 Correct 236 ms 13944 KB Output is correct
30 Correct 228 ms 14072 KB Output is correct
31 Correct 227 ms 13916 KB Output is correct
32 Correct 248 ms 13944 KB Output is correct
33 Correct 272 ms 13952 KB Output is correct
34 Correct 184 ms 13560 KB Output is correct
35 Correct 212 ms 13816 KB Output is correct
36 Correct 216 ms 13816 KB Output is correct
37 Correct 205 ms 13816 KB Output is correct
38 Correct 221 ms 13816 KB Output is correct
39 Correct 212 ms 13944 KB Output is correct
40 Correct 213 ms 13916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Execution timed out 2053 ms 4172 KB Time limit exceeded
12 Halted 0 ms 0 KB -