Submission #2353651


Source Code Expand

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;
}

Submission Info

Submission Time
Task E - Symmetric Grid
User samjia2000
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1801 Byte
Status AC
Exec Time 24 ms
Memory 6144 KB

Compile Error

./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);
                             ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 63
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 100.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 4.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 5.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 1 ms 256 KB
10.txt AC 4 ms 768 KB
100.txt AC 2 ms 640 KB
11.txt AC 4 ms 1664 KB
12.txt AC 4 ms 1664 KB
13.txt AC 15 ms 4352 KB
14.txt AC 24 ms 6016 KB
15.txt AC 15 ms 4352 KB
16.txt AC 23 ms 6016 KB
17.txt AC 15 ms 4352 KB
18.txt AC 22 ms 6016 KB
19.txt AC 15 ms 4352 KB
2.txt AC 1 ms 256 KB
20.txt AC 22 ms 6016 KB
21.txt AC 15 ms 4352 KB
22.txt AC 22 ms 6016 KB
23.txt AC 15 ms 4352 KB
24.txt AC 15 ms 4352 KB
25.txt AC 22 ms 6016 KB
26.txt AC 15 ms 4352 KB
27.txt AC 15 ms 4352 KB
28.txt AC 23 ms 6144 KB
29.txt AC 22 ms 6016 KB
3.txt AC 1 ms 256 KB
30.txt AC 14 ms 4352 KB
31.txt AC 15 ms 4352 KB
32.txt AC 22 ms 6016 KB
33.txt AC 15 ms 4352 KB
34.txt AC 22 ms 6016 KB
35.txt AC 21 ms 6016 KB
36.txt AC 15 ms 4352 KB
37.txt AC 23 ms 6016 KB
38.txt AC 15 ms 4352 KB
39.txt AC 15 ms 4352 KB
4.txt AC 2 ms 768 KB
40.txt AC 22 ms 6016 KB
41.txt AC 15 ms 4352 KB
42.txt AC 21 ms 6016 KB
43.txt AC 22 ms 6016 KB
44.txt AC 15 ms 4352 KB
45.txt AC 22 ms 6016 KB
46.txt AC 15 ms 4352 KB
47.txt AC 22 ms 6016 KB
48.txt AC 15 ms 4352 KB
49.txt AC 21 ms 6016 KB
5.txt AC 5 ms 768 KB
50.txt AC 15 ms 4352 KB
51.txt AC 22 ms 6016 KB
52.txt AC 22 ms 6016 KB
53.txt AC 22 ms 6016 KB
54.txt AC 24 ms 6144 KB
55.txt AC 16 ms 4480 KB
56.txt AC 22 ms 6016 KB
6.txt AC 2 ms 768 KB
7.txt AC 3 ms 768 KB
8.txt AC 3 ms 768 KB
9.txt AC 4 ms 768 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 22 ms 6016 KB