結果
問題 | No.470 Inverse S+T Problem |
ユーザー | Yamyuki |
提出日時 | 2016-12-23 01:21:37 |
言語 | C90 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,832 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 23,808 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-06-01 22:46:07 |
合計ジャッジ時間 | 4,249 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 0 ms
10,624 KB |
testcase_01 | AC | 0 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 0 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 0 ms
5,376 KB |
testcase_08 | AC | 0 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 0 ms
5,376 KB |
testcase_20 | WA | - |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 0 ms
5,376 KB |
testcase_23 | AC | 0 ms
5,376 KB |
testcase_24 | AC | 0 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
testcase_26 | TLE | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
コンパイルメッセージ
main.c: In function ‘search’: main.c:24:17: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration] 24 | memset(c,1,sizeof(c)); | ^~~~~~ main.c:3:1: note: include ‘<string.h>’ or provide a declaration of ‘memset’ 2 | #include<stdlib.h> +++ |+#include <string.h> 3 | int f[52][52][4]; main.c:24:17: warning: incompatible implicit declaration of built-in function ‘memset’ [-Wbuiltin-declaration-mismatch] 24 | memset(c,1,sizeof(c)); | ^~~~~~ main.c:24:17: note: include ‘<string.h>’ or provide a declaration of ‘memset’ main.c:26:9: warning: implicit declaration of function ‘memcpy’ [-Wimplicit-function-declaration] 26 | memcpy(cc,c,sizeof(cc)); | ^~~~~~ main.c:26:9: note: include ‘<string.h>’ or provide a declaration of ‘memcpy’ main.c:26:9: warning: incompatible implicit declaration of built-in function ‘memcpy’ [-Wbuiltin-declaration-mismatch] main.c:26:9: note: include ‘<string.h>’ or provide a declaration of ‘memcpy’ main.c: In function ‘main’: main.c:75:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 75 | scanf("%ld",&n); | ^~~~~~~~~~~~~~~ main.c:81:25: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 81 | scanf("%s",s[i]); | ^~~~~~~~~~~~~~~~
ソースコード
#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; id=k+1; 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]<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)); } if(f1){ c[i][0]=0; c[i][1]=1; a=2; id=k+1; 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; }