답안 #125705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125705 2019-07-06T09:07:41 Z 김세빈(#3068) Snake Escaping (JOI18_snake_escaping) C++14
58 / 100
2000 ms 10104 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 >= 11){
			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 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 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 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 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 471 ms 4380 KB Output is correct
12 Correct 612 ms 4052 KB Output is correct
13 Correct 320 ms 3308 KB Output is correct
14 Correct 312 ms 3360 KB Output is correct
15 Correct 621 ms 4364 KB Output is correct
16 Correct 390 ms 3588 KB Output is correct
17 Correct 393 ms 3548 KB Output is correct
18 Execution timed out 2045 ms 2412 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 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 471 ms 4380 KB Output is correct
12 Correct 612 ms 4052 KB Output is correct
13 Correct 320 ms 3308 KB Output is correct
14 Correct 312 ms 3360 KB Output is correct
15 Correct 621 ms 4364 KB Output is correct
16 Correct 390 ms 3588 KB Output is correct
17 Correct 393 ms 3548 KB Output is correct
18 Execution timed out 2045 ms 2412 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 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 332 ms 9856 KB Output is correct
12 Correct 147 ms 9992 KB Output is correct
13 Correct 84 ms 9720 KB Output is correct
14 Correct 100 ms 9720 KB Output is correct
15 Correct 69 ms 9848 KB Output is correct
16 Correct 126 ms 9784 KB Output is correct
17 Correct 116 ms 9848 KB Output is correct
18 Correct 54 ms 10104 KB Output is correct
19 Correct 57 ms 9720 KB Output is correct
20 Correct 185 ms 9848 KB Output is correct
21 Correct 339 ms 10020 KB Output is correct
22 Correct 99 ms 9720 KB Output is correct
23 Correct 63 ms 9728 KB Output is correct
24 Correct 81 ms 9720 KB Output is correct
25 Correct 128 ms 9784 KB Output is correct
26 Correct 53 ms 9720 KB Output is correct
27 Correct 343 ms 9816 KB Output is correct
28 Correct 57 ms 9692 KB Output is correct
29 Correct 78 ms 9692 KB Output is correct
30 Correct 81 ms 9848 KB Output is correct
31 Correct 64 ms 9688 KB Output is correct
32 Correct 124 ms 9848 KB Output is correct
33 Correct 114 ms 9760 KB Output is correct
34 Correct 52 ms 9596 KB Output is correct
35 Correct 124 ms 9720 KB Output is correct
36 Correct 124 ms 9848 KB Output is correct
37 Correct 126 ms 9820 KB Output is correct
38 Correct 125 ms 9852 KB Output is correct
39 Correct 123 ms 9720 KB Output is correct
40 Correct 126 ms 9864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 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 471 ms 4380 KB Output is correct
12 Correct 612 ms 4052 KB Output is correct
13 Correct 320 ms 3308 KB Output is correct
14 Correct 312 ms 3360 KB Output is correct
15 Correct 621 ms 4364 KB Output is correct
16 Correct 390 ms 3588 KB Output is correct
17 Correct 393 ms 3548 KB Output is correct
18 Execution timed out 2045 ms 2412 KB Time limit exceeded
19 Halted 0 ms 0 KB -