답안 #26320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
26320 2017-06-29T08:00:19 Z 서규호(#1103) Ili (COI17_ili) C++14
0 / 100
0 ms 2224 KB
#include <bits/stdc++.h>

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 1000000007
#define left lleft
#define right rright
#define Inf 2000000000
#define Linf 1000000000000000000LL
#define next nnext
#define minus mminus

using namespace std;

int N,M;
int a[10002],num1[10002],num2[10002];
int tmp[20002];
char s[10010];

bool calc(int x,int y){
	for(int i=1; i<=M; i++) tmp[N+i] = a[i];
	for(int i=1; i<=N; i++) tmp[i] = 2;
	tmp[x+N] = y;
	for(int i=M+N; i>N; i--){
		if(tmp[i] != 0) continue;
		if(tmp[num1[i-N]] == 1 || tmp[num2[i-N]] == 1) return false;
		tmp[num1[i-N]] = tmp[num2[i-N]] = 0;
	}
	for(int i=1; i<=N+M; i++){
		if(tmp[i] != 0) tmp[i] = 1;
	}
	for(int i=1; i<=M; i++){
		if(tmp[i+N] == 1 && tmp[num1[i]]+tmp[num2[i]] == 0) return false;
	}
	return true;
}

int main(){
	scanf("%d %d",&N,&M);
	scanf("%s",s);
	for(int i=1; i<=M; i++){
		if(s[i-1] == '?') a[i] = 2;
		else a[i] = s[i-1]-'0';
	}
	for(int i=1; i<=M; i++){
		int ten;
		char s1[10],s2[10];
		scanf("%s %s",s1,s2);
		ten = 1;
		for(int j=strlen(s1)-1; j>=1; j--){
			num1[i] += ten*(s1[j]-'0');
			ten *= 10;
		}
		ten = 1;
		for(int j=strlen(s2)-1; j>=1; j--){
			num2[i] += ten*(s2[j]-'0');
			ten *= 10;
		}
		if(s1[0] == 'c') num1[i] += N;
		if(s2[0] == 'c') num2[i] += N;
	}
	for(int i=M; i>=1; i--){
		if(a[i] != 2) continue;
		bool flag1,flag2;
		flag1 = calc(i,0);
		flag2 = calc(i,1);
		if(!flag2) a[i] = 0;
		else if(!flag1) a[i] = 1;
	}
	for(int i=1; i<=M; i++){
		if(a[i] == 2) printf("?");
		else printf("%c",'0'+a[i]);
	}

	return 0;
}

Compilation message

ili.cpp: In function 'int main()':
ili.cpp:40:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&M);
                      ^
ili.cpp:41:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s);
               ^
ili.cpp:49:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s %s",s1,s2);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 2224 KB Output isn't correct
2 Halted 0 ms 0 KB -