Submission #1016268


Source Code Expand

#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}


template<lint mod>
struct Int_{
  unsigned x;
  unsigned mpow(Int_ a,unsigned k){
    Int_ res=1;
    while(k){
      if(k&1) res=res*a;
      a=a*a;
      k>>=1;
    }
    return res.x;
  }
  unsigned inverse(Int_ a){
    return mpow(a,mod-2);
  }
  Int_(): x(0) { }
  Int_(long long sig) {
    int sigt=sig%mod;
    if(sigt<0) sigt+=mod;
    x=sigt;
  }
  unsigned get() const { return (unsigned)x; }
  
  Int_ &operator+=(Int_ that) { if((x += that.x) >= mod) x -= mod; return *this; }
  Int_ &operator-=(Int_ that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
  Int_ &operator*=(Int_ that) { x = (unsigned long long)x * that.x % mod; return *this; }
  Int_ &operator=(Int_ that) { x=that.x; return *this;}
  Int_ &operator/=(Int_ that) { x=(unsigned long long) x * inverse(that.x)%mod; return *this;}
  bool operator==(Int_ that) const { return x==that.x; }
  bool operator!=(Int_ that) const { return x!=that.x; }

  Int_ operator-() const { return Int_(0)-Int_(*this);}
  Int_ operator+(Int_ that) const { return Int_(*this) += that; }
  Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
  Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
  Int_ operator/(Int_ that) const { return Int_(*this) /= that; }

};

namespace std{
  template<lint mod>
  ostream &operator <<(ostream& out,const Int_<mod>& a){
    out<<a.get();
    return out;
  }
  template<lint mod>
  istream &operator >>(istream& in,Int_<mod>& a){
    in>>a.x;
    return in;
  }
};

typedef Int_<1000000007> Int;

//const int INF=5e8;
int h,w;
char buf[205][205];


struct uf{

  static const int MAXN=405;;
  int par[MAXN];
  int size[MAXN];
  void init(){
    memset(par,-1,sizeof(par));
    REP(i,MAXN) size[i]=1;
  }
  int root(int a){
    if(par[a]==-1) return a;
    return par[a]=root(par[a]);
  }
  void unite(int a,int b){
    a=root(a);b=root(b);
    if(a==b) return;
    if(size[a]<size[b]) swap(a,b);

    par[b]=a;
    size[a]+=size[b];
  }
  bool same(int a,int b){
    return root(a)==root(b);
  }
};

uf u;
int deg[405];
int main(){
  u.init();
  cin>>h>>w;
  REP(i,h) scanf("%s",buf[i]);
  Int res=1;
  if(h&1){
    bool same=true;
    REP(i,w) if(buf[h/2][i]!=buf[h/2][w-1-i]) same=false;
    if(!same) res*=2;
  }
  if(w&1){
    bool same=true;
    REP(i,h) if(buf[i][w/2]!=buf[h-1-i][w/2]) same=false;
    if(!same) res*=2;
  }
  Int fact[5];
  fact[0]=1;
  REP(i,4) fact[i+1]=fact[i]*(i+1);

  int K=h/2,L=w/2;
  REP(i,h/2) REP(j,w/2){
    int ys[]={i,h-1-i},xs[]={j,w-1-j};
    map<char,int> cs;
    REP(k,2) REP(l,2) cs[buf[ys[k]][xs[l]]]++;
    dump(cs.size());
    if(cs.size()<4){
      Int tmp=fact[4];
      for(auto e:cs) tmp/=fact[e.sc];
      res*=tmp;
    }
    if(cs.size()==4){
      u.unite(i,j+K);
      u.unite(j+K,j);
      ++deg[i];
      ++deg[j+K];
      res*=fact[3]*2;
    }
  }

  REP(i,K+L) if(deg[i]>0 && u.root(i)!=i) res*=2;

  cout<<res<<endl;
  return 0;
}



Submission Info

Submission Time
Task I - Reverse Grid
User hogloid
Language C++14 (GCC 5.4.1)
Score 1900
Code Size 4016 Byte
Status AC
Exec Time 61 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:130:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   REP(i,h) scanf("%s",buf[i]);
                              ^

Judge Result

Set Name sample all
Score / Max Score 0 / 0 1900 / 1900
Status
AC × 2
AC × 37
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
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 256 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 3 ms 256 KB
01-07.txt AC 2 ms 256 KB
01-08.txt AC 3 ms 256 KB
01-09.txt AC 3 ms 256 KB
01-10.txt AC 57 ms 256 KB
01-11.txt AC 57 ms 256 KB
01-12.txt AC 58 ms 256 KB
01-13.txt AC 56 ms 256 KB
01-14.txt AC 14 ms 256 KB
01-15.txt AC 16 ms 256 KB
01-16.txt AC 59 ms 256 KB
01-17.txt AC 58 ms 256 KB
01-18.txt AC 59 ms 256 KB
01-19.txt AC 60 ms 256 KB
01-20.txt AC 59 ms 256 KB
01-21.txt AC 61 ms 256 KB
01-22.txt AC 4 ms 256 KB
01-23.txt AC 31 ms 256 KB
01-24.txt AC 58 ms 256 KB
01-25.txt AC 58 ms 256 KB
01-26.txt AC 59 ms 256 KB
01-27.txt AC 5 ms 256 KB
01-28.txt AC 11 ms 256 KB
01-29.txt AC 3 ms 256 KB
01-30.txt AC 13 ms 256 KB
01-31.txt AC 58 ms 256 KB
01-32.txt AC 57 ms 256 KB
01-33.txt AC 58 ms 256 KB
01-34.txt AC 59 ms 256 KB
01-35.txt AC 59 ms 256 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB