結果

問題 No.470 Inverse S+T Problem
ユーザー YamyukiYamyuki
提出日時 2016-12-25 09:24:57
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 26,240 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 01:25:45
合計ジャッジ時間 1,853 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,384 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 0 ms
4,376 KB
testcase_12 AC 0 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 0 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 0 ms
4,376 KB
testcase_19 AC 0 ms
4,376 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 0 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 0 ms
4,376 KB
testcase_24 AC 0 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 0 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
int c[52],tmp[52];
int next[52];
int cur,t,ch;
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 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;
	}
		for(i=0;i<n;i++){
			scanf("%s",s[i]);
		}
		for(i=0;i<n;i++) c[i]=-1;
		for(i=0;i<n;i++){
			if(c[i]!=-1) continue;
			for(j=0;j<2;j++){
				ch=1;
				for(t=0;t<n;t++) tmp[t]=c[t];
				tmp[i]=j;
				next[0]=i;
				t=1;
				cur=0;
				while(cur<t && ch){
					for(k=0;k<n;k++){
						if(k==next[cur]) continue;
						ff=0;
						if(tmp[k]==0) ff=(ff | 1);
						else if(tmp[k]==1) ff=(ff | 2);
						if(check(s,next[cur],k,tmp[next[cur]]*2+1)) ff=(ff | 1);
						if(check(s,next[cur],k,tmp[next[cur]]*2)) ff= (ff | 2);
						if(ff==3){
							ch=0;
							break;
						}
						if(ff!=0 && tmp[k]==-1){
							tmp[k]=ff-1;
							next[t]=k;
							t++;
						}
					}
					cur++;
				}
				if(ch==1){
					for(k=0;k<n;k++) c[k]=tmp[k];
					break;
				}
				c[i]=-1;
			}
			if(c[i]==-1){
				printf("Impossible\n");
				return 0;
			}
		}
			for(i=0;i<n;i++){
				if(c[i]==0){
					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