結果

問題 No.470 Inverse S+T Problem
ユーザー YamyukiYamyuki
提出日時 2016-12-23 00:01:22
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,270 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 26,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 01:23:47
合計ジャッジ時間 1,842 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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 i){
	if(i==n) return 1;
	int j,f0,f1;
	if(i==0){
		memset(c,1,sizeof(c));
	}
	f0=c[i][0];
	f1=c[i][1];
	if(f0){
	c[i][0]=1;
	c[i][1]=0;
	for(j=i+1;j<n;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(j==n) if(search(i+1)) return 1;
	}
	if(f1){
	c[i][0]=0;
	c[i][1]=1;
	for(j=i+1;j<n;j++){
		c[j][0]=c[j][0] && f[i][j][2];
		c[j][1]=c[j][1] && f[i][j][3];
		if(c[j][0]==0 && c[j][1]==0) break;
	}
	if(j==n) if(search(i+1)) return 1;
	}
	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);
				}
			}
		}
		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