ソースコード 拡げる

Copy
```#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
char ch;
while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
if (ch=='-'){
int s=0;
while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
return -s;
}
int s=ch-'0';
while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
return s;
}

const int L = 10395+10;
const int N = 13;
const int M = (1<<12)+1;

bitset<L>cp[N][N],f[M];
int n,m;
char s[N][N];
bool bz[N];
int tp[L][N];
int k;
int ct[N];

void dfs(int x,bool tg){
if (x>m){
k++;
fo(i,1,m)tp[k][i]=ct[i];
return;
}
if (bz[x]){dfs(x+1,tg);return;}
fo(i,x+1,m)
if (!bz[i]){
bz[x]=bz[i]=1;
ct[x]=i,ct[i]=x;
dfs(x+1,tg);
ct[x]=ct[i]=0;
bz[x]=bz[i]=0;
}
if (!tg&&(m&1)>0){
bz[x]=1;
ct[x]=x;
dfs(x+1,1);
ct[x]=x;
bz[x]=0;
}
}

int cnt[M];

int main(){
//freopen("data.in","r",stdin);
n=get();m=get();
fo(i,1,n)scanf("%s",s[i]+1);
dfs(1,0);
fo(i,1,n){
fo(j,i,n){
fo(w,1,k){
bool pd=1;
fo(x,1,m)pd&=(s[j][tp[w][x]]==s[i][x]);
if (pd)cp[i][j][w-1]=1;
}
}
}
if (n&1){
fo(st,1,n)
f[(1<<(st-1))]=cp[st][st];
}
else
fo(i,0,k-1)f[0][i]=1;
fo(i,1,(1<<n)-1)cnt[i]=cnt[i-(i&-i)]+1;
fo(i,0,(1<<n)-1)
if (cnt[i]+2<=n){
int x;
fo(w,1,n)
if (((1<<(w-1))&i)==0){x=w;break;}
fo(y,x+1,n)
if (((1<<(y-1))&i)==0)f[i|(1<<(x-1))|(1<<(y-1))]=f[i|(1<<(x-1))|(1<<(y-1))]|(f[i]&cp[x][y]);
}
bool ans=0;
fo(i,0,k-1)ans=ans|f[(1<<n)-1][i];
if (ans)printf("YES\n");
else printf("NO\n");
return 0;
}```

#### 提出情報

提出日時 2018-04-14 22:05:15+0900 C - Many Medians samjia2000 C++14 (GCC 5.4.1) 0 1801 Byte RE 1437 ms 29568 KB

#### コンパイルエラー

```./Main.cpp: In function ‘int main()’:
./Main.cpp:72:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
fo(i,1,n)scanf("%s",s[i]+1);
^
```

#### ジャッジ結果

セット名 Sample All

 WA × 3
 WA × 7 RE × 11
セット名 テストケース
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
ケース名 結果 実行時間 メモリ
1.txt WA 1312 ms 6144 KB
10.txt RE 1380 ms 24960 KB
11.txt RE 1362 ms 27392 KB
12.txt RE 1428 ms 24448 KB
2.txt RE 1269 ms 29568 KB
3.txt RE 1409 ms 24960 KB
4.txt RE 1292 ms 24960 KB
5.txt RE 1309 ms 24960 KB
6.txt RE 1386 ms 24960 KB
7.txt RE 1422 ms 25088 KB
8.txt RE 1437 ms 24960 KB
9.txt RE 1235 ms 24960 KB
sample1.txt WA 1 ms 256 KB
sample2.txt WA 1 ms 256 KB
sample3.txt WA 1 ms 384 KB