Submission #2832864
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define N 32 #define INF 0x3f3f3f3f string s[N],str[N],col[N],col2[N]; int hash[N],hash2[N]; vector <string> Hash[N<<17]; vector <string> Hash2[N<<17]; map <string,bool> vis; map <string,bool> vis2; int main() { //freopen("qc.in","r",stdin); int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { cin>>s[i]; for(int j=0;j<m;j++) { hash[i]+=s[i][j]; } Hash[hash[i]].push_back(s[i]); } int cnt1=0,cnt2=0; for(int i=1;i<=n;i++) { if(Hash[hash[i]].size()%2==0)cnt2++; else cnt1++; } if(cnt1>=2) { puts("NO"); return 0; } if(n%2==1) { for(int i=1;i<=n;i++) { if(Hash[hash[i]].size()%2==1) { str[n/2+1]=Hash[hash[i]][0]; Hash[hash[i]].erase(Hash[hash[i]].begin()); break; } } } int t=1; for(int i=1;i<=n;i++) { int len=Hash[hash[i]].size(); for(int j=0;j<len;j++) { if(vis[Hash[hash[i]][j]])continue; vis[Hash[hash[i]][j]]=1; str[t]=Hash[hash[i]][j]; str[n-t+1]=Hash[hash[i]][len-j-1]; vis[Hash[hash[i]][len-j-1]]=1; t++; } } /*for(int i=1;i<=n;i++) { cout<<str[i]<<endl; } puts("");*/ for(int j=1;j<=m;j++) { for(int i=1;i<=n;i++) { col[j]=col[j]+str[i][j-1]; } } /*for(int j=1;j<=m;j++) { cout<<col[j]<<endl; } puts("");*/ for(int j=1;j<=m;j++) { for(int i=0;i<n;i++) { hash2[j]+=col[j][i]; } Hash2[hash2[j]].push_back(col[j]); } cnt1=0,cnt2=0; for(int i=1;i<=m;i++) { if(Hash2[hash2[i]].size()%2==0)cnt2++; else cnt1++; } if(cnt1>=2) { puts("NO"); return 0; } if(m%2==1) { for(int i=1;i<=m;i++) { if(Hash2[hash2[i]].size()%2==1) { col2[n/2+1]=Hash2[hash2[i]][0]; Hash2[hash2[i]].erase(Hash2[hash2[i]].begin()); break; } } } t=1; for(int i=1;i<=m;i++) { int len=Hash2[hash2[i]].size(); for(int j=0;j<len;j++) { if(vis2[Hash2[hash2[i]][j]])continue; vis2[Hash2[hash2[i]][j]]=1; col2[t]=Hash2[hash2[i]][j]; col2[m-t+1]=Hash2[hash2[i]][len-j-1]; vis2[Hash2[hash2[i]][len-j-1]]=1; t++; } } /*for(int i=1;i<=m;i++) { cout<<col2[i]<<endl; }*/ /*for(int i=1;i<=m;i++) { for(int j=0;j<n;j++) { if(col2[i][j]!=col2[m-i+1][n-j-1]) { //printf("<%d,%d>[%c]<%d,%d>[%c]\n",i,j,col2[i][j],m-i+1,n-j-1,col2[m-i+1][n-j-1]); puts("NO"); return 0; } } }*/ puts("YES"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Symmetric Grid |
User | We_R_Young |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2487 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:21:4: error: reference to ‘hash’ is ambiguous hash[i]+=s[i][j]; ^ ./Main.cpp:6:5: note: candidates are: int hash [32] int hash[N],hash2[N]; ^ In file included from /usr/include/c++/5/bits/basic_string.h:5556:0, from /usr/include/c++/5/string:52, from /usr/include/c++/5/bits/locale_classes.h:40, from /usr/include/c++/5/bits/ios_base.h:41, from /usr/include/c++/5/ios:42, from /usr/include/c++/5/istream:38, from /usr/include/c++/5/sstream:38, from /usr/include/c++/5/complex:45, from /usr/include/c++/5/ccomplex:38, from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52, from ./Main.cpp:1: /usr/include/c++/5/bits/functional_hash.h:58:12: note: template<class _Tp> struct std::hash struct hash; ^ ./Main.cpp:23:8: error: reference to ‘hash’ is ambiguo...