답안 #138541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138541 2019-07-30T06:39:29 Z 이온조(#3319) Who wants to live forever? (CERC12_B) C++14
0 / 1
1000 ms 876 KB
#include <bits/stdc++.h>
using namespace std;

char S[200009];
vector<bool> A[2];

bool sim(int N, int c) {
	for(int j=0; j<c; j++) for(int i=1; i<=N; i++) A[j+1&1][i] = (A[j&1][i-1] ^ A[j&1][i+1]);
	bool f = 0;
	for(int i=1; i<=N; i++) f |= A[c-1&1][i];
	return f;
}

int main() {
	A[0].resize(200009);
	A[1].resize(200009);
	int T; scanf("%d",&T);
	while(T--) {
		scanf(" %s", S+1);
		int N = strlen(S+1);
		bool f = (((N+1) &- (N+1)) != N+1);
		for(int i=1; i<=N; i++) A[0][i] = (S[i] == '1');
		A[0][0] = A[0][N+1] = A[1][0] = A[1][N+1] = 0;
		f &= sim(N, 240);
		puts(f ? "LIVES" : "DIES");
	}
	// for(int k=1; k<=30; k++) {
	// 	int cnt = 0;
	// 	for(int i=0; i<(1<<k); i++) {
	// 		for(int j=0; j<k; j++) A[j+1] = ((i >> j) & 1);
	// 		if(!sim(k, 300)) {
	// 			for(int j=0; j<k; j++) printf("%d", ((i>>j) & 1));
	// 			puts("");
	// 			++cnt;
	// 		}
	// 		if(cnt > 50) break;
	// 	}
	// 	printf("k: %d, cnt: %d\n", k, cnt);
	// }
	return 0;
}

Compilation message

B.cpp: In function 'bool sim(int, int)':
B.cpp:8:52: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
  for(int j=0; j<c; j++) for(int i=1; i<=N; i++) A[j+1&1][i] = (A[j&1][i-1] ^ A[j&1][i+1]);
                                                   ~^~
B.cpp:10:34: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  for(int i=1; i<=N; i++) f |= A[c-1&1][i];
                                 ~^~
B.cpp: In function 'int main()':
B.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int T; scanf("%d",&T);
         ~~~~~^~~~~~~~~
B.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", S+1);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Execution timed out 1069 ms 876 KB Time limit exceeded
4 Halted 0 ms 0 KB -