답안 #125703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125703 2019-07-06T09:06:32 Z 김세빈(#3068) Snake Escaping (JOI18_snake_escaping) C++14
58 / 100
2000 ms 9988 KB
#include <bits/stdc++.h>

using namespace std;

char S[1101010];
int D1[1101010], D2[1101010];
int n, q;

int main()
{
	vector <int> X;
	int i, j, v, s, x, ans;
	
	scanf("%d%d%s", &n, &q, S);
	
	for(i=0; i<(1<<n); i++){
		D1[i] = D2[i] = S[i] - '0';
	}
	
	for(i=0; i<n; i++){
		for(j=0; j<(1<<n); j++){
			if(j & (1 << i)){
				D1[j] += D1[j - (1 << i)];
			}
		}
	}
	
	for(; q--; ){
		scanf("%s", S); reverse(S, S + n);
		
		for(i=0, s=0; i<n; i++){
			if(S[i] == '?') s ++;
		}
		
		X.clear();
		ans = 0; v = 0;
		
		if(s >= 13){
			for(i=0; i<n; i++){
				if(S[i] == '1') v += 1 << i, X.push_back(i);
				else if(S[i] == '?') v += 1 << i;
			}
			
			s = X.size(); x = 1;
			
			for(i=0; i<(1<<s); i++){
				ans += D1[v] * x;
				for(j=0; (2<<j)<(i^i+1); j++){
					v += 1 << X[j]; x = -x;
				}
				if(j < s) v -= 1 << X[j], x = -x;
			}
		}
		else{	
			for(i=0; i<n; i++){
				if(S[i] == '?') X.push_back(i);
				else v += S[i] - '0' << i;
			}
			
			s = X.size();
			
			for(i=0; i<(1<<s); i++){
				ans += D2[v];
				for(j=0; (2<<j)<(i^i+1); j++){
					v -= 1 << X[j];
				}
				if(j < s) v += 1 << X[j];
			}
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:48:25: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
     for(j=0; (2<<j)<(i^i+1); j++){
                        ~^~
snake_escaping.cpp:57:20: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
     else v += S[i] - '0' << i;
               ~~~~~^~~~~
snake_escaping.cpp:64:25: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
     for(j=0; (2<<j)<(i^i+1); j++){
                        ~^~
snake_escaping.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%s", &n, &q, S);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", S); reverse(S, S + n);
   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 472 ms 4388 KB Output is correct
12 Correct 622 ms 4108 KB Output is correct
13 Correct 321 ms 3320 KB Output is correct
14 Correct 310 ms 3320 KB Output is correct
15 Correct 626 ms 4328 KB Output is correct
16 Correct 391 ms 3704 KB Output is correct
17 Correct 390 ms 3576 KB Output is correct
18 Execution timed out 2070 ms 2520 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 472 ms 4388 KB Output is correct
12 Correct 622 ms 4108 KB Output is correct
13 Correct 321 ms 3320 KB Output is correct
14 Correct 310 ms 3320 KB Output is correct
15 Correct 626 ms 4328 KB Output is correct
16 Correct 391 ms 3704 KB Output is correct
17 Correct 390 ms 3576 KB Output is correct
18 Execution timed out 2070 ms 2520 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 345 ms 9884 KB Output is correct
12 Correct 363 ms 9988 KB Output is correct
13 Correct 78 ms 9720 KB Output is correct
14 Correct 104 ms 9720 KB Output is correct
15 Correct 64 ms 9848 KB Output is correct
16 Correct 138 ms 9848 KB Output is correct
17 Correct 139 ms 9824 KB Output is correct
18 Correct 55 ms 9936 KB Output is correct
19 Correct 57 ms 9720 KB Output is correct
20 Correct 369 ms 9848 KB Output is correct
21 Correct 336 ms 9976 KB Output is correct
22 Correct 104 ms 9868 KB Output is correct
23 Correct 66 ms 9788 KB Output is correct
24 Correct 81 ms 9720 KB Output is correct
25 Correct 138 ms 9820 KB Output is correct
26 Correct 53 ms 9720 KB Output is correct
27 Correct 335 ms 9812 KB Output is correct
28 Correct 57 ms 9720 KB Output is correct
29 Correct 84 ms 9720 KB Output is correct
30 Correct 81 ms 9848 KB Output is correct
31 Correct 65 ms 9848 KB Output is correct
32 Correct 138 ms 9848 KB Output is correct
33 Correct 138 ms 9732 KB Output is correct
34 Correct 53 ms 9596 KB Output is correct
35 Correct 141 ms 9720 KB Output is correct
36 Correct 143 ms 9968 KB Output is correct
37 Correct 139 ms 9720 KB Output is correct
38 Correct 143 ms 9708 KB Output is correct
39 Correct 145 ms 9844 KB Output is correct
40 Correct 145 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 472 ms 4388 KB Output is correct
12 Correct 622 ms 4108 KB Output is correct
13 Correct 321 ms 3320 KB Output is correct
14 Correct 310 ms 3320 KB Output is correct
15 Correct 626 ms 4328 KB Output is correct
16 Correct 391 ms 3704 KB Output is correct
17 Correct 390 ms 3576 KB Output is correct
18 Execution timed out 2070 ms 2520 KB Time limit exceeded
19 Halted 0 ms 0 KB -