Submission #1801342
Source Code Expand
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
template<unsigned int mod_>
struct ModInt{
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr static uint mod = mod_;
uint v;
ModInt():v(0){}
ModInt(ll v):v(normS(v%mod+mod)){}
explicit operator bool() const {return v!=0;}
static uint normS(const uint &x){return (x<mod)?x:x-mod;} // [0 , 2*mod-1] -> [0 , mod-1]
static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
ModInt operator-() const { return make(normS(mod-v)); }
ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
ModInt operator/(const ModInt& b) const { return *this*b.inv();}
ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
ll extgcd(ll a,ll b,ll &x,ll &y) const{
ll u[]={a,1,0},v[]={b,0,1};
while(*v){
ll t=*u/ *v;
rep(i,3) swap(u[i]-=t*v[i],v[i]);
}
if(u[0]<0) rep(i,3) u[i]=-u[i];
x=u[1],y=u[2];
return u[0];
}
ModInt inv() const{
ll x,y;
extgcd(v,mod,x,y);
return make(normS(x+mod));
}
bool operator==(const ModInt& b) const { return v==b.v;}
bool operator!=(const ModInt& b) const { return v!=b.v;}
friend istream& operator>>(istream &o,ModInt& x){
ll tmp;
o>>tmp;
x=ModInt(tmp);
return o;
}
friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000007>;
struct UnionFind{
vector<int> par,rank;
UnionFind(int N){
par.assign(N,0);
rank.assign(N,0);
rep(i,N) par[i]=i;
}
int find(int x){
if(par[x]==x) return x;
return par[x]=find(par[x]);
}
bool same(int x,int y){
return find(x)==find(y);
}
void unite(int x,int y){
x=find(x),y=find(y);
if(x==y) return;
if(rank[x]<rank[y]) par[x]=y;
else{
par[y]=x;
if(rank[x]==rank[y]) rank[x]++;
}
}
};
int H,W;
string s[200];
int main(){
cin>>H>>W;
rep(i,H) cin>>s[i];
mint ans = 1;
UnionFind UF(H+W);
rep(i,H/2) rep(j,W/2){
string t;
t += s[i][j];
t += s[i][W-1-j];
t += s[H-1-i][j];
t += s[H-1-i][W-1-j];
int o[4]={0,1,2,3};
set<string> st;
do{
string tt;
rep(i,4) tt += t[o[i]];
st.insert(tt);
}while(next_permutation(o,o+4));
int K = st.size();
if(K==24){
ans *= 12;
UF.unite(i,H+j);
}else{
ans *= K;
}
}
rep(i,H/2){
if(UF.find(i) != i) ans *= 2;
}
rep(j,W/2){
if(UF.find(H+j) != H+j) ans *= 2;
}
if(H%2==1){
string t = s[H/2];
string rt = t;
reverse(all(rt));
if(t!=rt) ans *= 2;
}
if(W%2==1){
string t;
rep(i,H) t += s[i][W/2];
string rt = t;
reverse(all(rt));
if(t!=rt) ans *= 2;
}
cout<<ans<<endl;
}
Submission Info
Submission Time |
|
Task |
I - Reverse Grid |
User |
sigma425 |
Language |
C++14 (GCC 5.4.1) |
Score |
1900 |
Code Size |
3594 Byte |
Status |
AC |
Exec Time |
80 ms |
Memory |
384 KB |
Judge Result
Set Name |
sample |
all |
Score / Max Score |
0 / 0 |
1900 / 1900 |
Status |
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
all |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
1 ms |
256 KB |
01-02.txt |
AC |
1 ms |
256 KB |
01-03.txt |
AC |
1 ms |
256 KB |
01-04.txt |
AC |
1 ms |
256 KB |
01-05.txt |
AC |
1 ms |
256 KB |
01-06.txt |
AC |
1 ms |
256 KB |
01-07.txt |
AC |
1 ms |
256 KB |
01-08.txt |
AC |
1 ms |
256 KB |
01-09.txt |
AC |
1 ms |
256 KB |
01-10.txt |
AC |
43 ms |
256 KB |
01-11.txt |
AC |
50 ms |
384 KB |
01-12.txt |
AC |
51 ms |
256 KB |
01-13.txt |
AC |
44 ms |
256 KB |
01-14.txt |
AC |
15 ms |
256 KB |
01-15.txt |
AC |
16 ms |
256 KB |
01-16.txt |
AC |
66 ms |
256 KB |
01-17.txt |
AC |
65 ms |
256 KB |
01-18.txt |
AC |
66 ms |
256 KB |
01-19.txt |
AC |
58 ms |
256 KB |
01-20.txt |
AC |
57 ms |
256 KB |
01-21.txt |
AC |
72 ms |
256 KB |
01-22.txt |
AC |
3 ms |
256 KB |
01-23.txt |
AC |
32 ms |
256 KB |
01-24.txt |
AC |
60 ms |
256 KB |
01-25.txt |
AC |
60 ms |
256 KB |
01-26.txt |
AC |
61 ms |
256 KB |
01-27.txt |
AC |
5 ms |
256 KB |
01-28.txt |
AC |
10 ms |
256 KB |
01-29.txt |
AC |
2 ms |
256 KB |
01-30.txt |
AC |
13 ms |
256 KB |
01-31.txt |
AC |
65 ms |
256 KB |
01-32.txt |
AC |
80 ms |
256 KB |
01-33.txt |
AC |
65 ms |
256 KB |
01-34.txt |
AC |
68 ms |
256 KB |
01-35.txt |
AC |
67 ms |
256 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |