結果

問題 No.470 Inverse S+T Problem
ユーザー YamyukiYamyuki
提出日時 2016-12-23 01:19:16
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,812 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 27,632 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-24 01:23:55
合計ジャッジ時間 1,777 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 0 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 0 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘search’:
main.c:24:3: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]
   memset(c,1,sizeof(c));
   ^~~~~~
main.c:24:3: warning: incompatible implicit declaration of built-in function ‘memset’
main.c:24:3: note: include ‘<string.h>’ or provide a declaration of ‘memset’
main.c:3:1:
+#include <string.h>
 int f[52][52][4];
main.c:24:3:
   memset(c,1,sizeof(c));
   ^~~~~~
main.c:26:2: warning: implicit declaration of function ‘memcpy’ [-Wimplicit-function-declaration]
  memcpy(cc,c,sizeof(cc));
  ^~~~~~
main.c:26:2: warning: incompatible implicit declaration of built-in function ‘memcpy’
main.c:26:2: note: include ‘<string.h>’ or provide a declaration of ‘memcpy’

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
int f[52][52][4];
int c[52][2];
int next[52];
long n;

void swap(int *a,int *b){
	int c;
	c=*a;
	*a=*b;
	*b=c;
}

int check(char s[52][4],int i,int j,int k){
	if(s[i][(k/2)*2]==s[j][(k%2)*2] || (s[i][1-k/2]==s[j][1-k%2] && s[i][2-k/2]==s[j][2-k%2])) return 0;
	return 1;
}
int search(int k){
	if(k==n) return 1;
	int j,f0,f1,a,id,jj,i=next[k];
	int cc[52][2];
	if(i==0){
		memset(c,1,sizeof(c));
	}
	memcpy(cc,c,sizeof(cc));
	f0=c[i][0];
	f1=c[i][1];
	if(f0){
	c[i][0]=1;
	c[i][1]=0;
	a=2;
	memcpy(cc,c,sizeof(cc));
	for(j=k+1;j<n;j++){
		jj=next[j];
		c[j][0]=(c[j][0] & f[i][j][0]);
		c[j][1]=(c[j][1] & f[i][j][1]);
		if(c[j][0]==0 && c[j][1]==0) break;
		if(c[jj][0]+c[jj][1]) {id=j;a=1;}
	}
	if(j==n){
		if(id!=k+1) swap(&next[k+1],&next[id]);
		if(search(k+1)) return 1;
	}
	memcpy(c,cc,sizeof(cc));
	}
	if(f1){
	c[i][0]=0;
	c[i][1]=1;
	a=2;
	memcpy(cc,c,sizeof(cc));
	for(j=k+1;j<n;j++){
		jj=next[j];
		c[jj][0]=(c[jj][0] & f[i][jj][2]);
		c[jj][1]=(c[jj][1] & f[i][jj][3]);
		if(c[jj][0]==0 && c[jj][1]==0) break;
		if(c[jj][0]+c[jj][1]<a) {id=j;a=1;}
	}
	if(j==n){
		if(id!=k+1) swap(&next[k+1],&next[id]);
		if(search(k+1)) return 1;
	}
	memcpy(c,cc,sizeof(cc));
	}
	c[i][0]=f0;
	c[i][1]=f1;
	return 0;
}

int main(){
	int i,j,k,ff;
	char s[52][4];
	scanf("%ld",&n);
	if(n>52){
		printf("Impossible\n");
		return 0;
	}else{
		for(i=0;i<n;i++){
			scanf("%s",s[i]);
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				for(k=0;k<4;k++){
					f[i][j][k]=check(s,i,j,k);
				}
			}
		}
		for(i=0;i<n;i++){
			next[i]=i;
		}
		ff=search(0);
		if(ff==0) printf("Impossible\n");
		else{
			for(i=0;i<n;i++){
				if(c[i][0]==1){
					printf("%c %c%c\n",s[i][0],s[i][1],s[i][2]);
				}else{
					printf("%c%c %c\n",s[i][0],s[i][1],s[i][2]);
				}
			}
		}
	}
	return 0;
}
0