cf1107d 映射关系
#include<bits/stdc++.h> using namespace std; int n,mp[5500][5500]; int judge(int i){ for(int j=1;j<=n;j++) if(mp[i][j]!=mp[i-1][j])return 0; return 1; } int main(){ cin>>n; char ch;int a; for(int i=1;i<=n;i++) for(int j=1;j<=n;j+=4){ cin>>ch; if(ch<='9'&&ch>='0')a=ch-'0'; else a=10+ch-'A'; for(int k=3;k>=0;k--) mp[i][j+(3-k)]=(a>>k)&1; } int ans=0,tmp=1; for(int i=2;i<=n;i++){ if(judge(i))tmp++; else if(ans==0) ans=tmp,tmp=1; else ans=__gcd(ans,tmp),tmp=1; } for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) swap(mp[i][j],mp[j][i]); tmp=1; for(int i=2;i<=n;i++){ if(judge(i))tmp++; else ans=__gcd(ans,tmp),tmp=1; } printf("%d\n",__gcd(ans,tmp)); }