Submission #5399571


Source Code Expand

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 205
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int H,W;
char s[MAXN][MAXN];
int cnt[27],fa[MAXN * 2];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
int getfa(int x) {
    return x == fa[x] ? x : fa[x] = getfa(x);
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
void Solve() {
    read(H);read(W);
    for(int i = 1 ; i <= H ; ++i) {
	scanf("%s",s[i] + 1);
    }
    for(int i = 1 ; i <= H + W ; ++i) fa[i] = i;
    int ans = 1;
    if(H & 1) {
	bool f = 1;
	for(int j = 1 ; j <= W / 2 ; ++j) {
	    if(s[H / 2 + 1][j] != s[H / 2 + 1][W - j + 1]) {f = 0;break;}
	}
	if(!f) ans = mul(ans,2);
    }
    if(W & 1) {
	bool f = 1;
	for(int i = 1 ; i <= H / 2 ; ++i) {
	    if(s[i][W / 2 + 1] != s[H - i + 1][W / 2 + 1]) {f = 0;break;}
	}
	if(!f) ans = mul(ans,2);
    }
    int c = 0;
    for(int i = 1 ; i <= H / 2 ; ++i) {
	for(int j = 1 ; j <= W / 2 ; ++j) {
	    memset(cnt,0,sizeof(cnt));
	    cnt[s[i][j] - 'a']++;
	    cnt[s[H - i + 1][j] - 'a']++;
	    cnt[s[i][W - j + 1] - 'a']++;
	    cnt[s[H - i + 1][W - j + 1] - 'a']++;
	    bool f = 0;
	    int tmp = 24;
	    for(int k = 0 ; k < 26 ; ++k) {
		if(cnt[k] >= 2) {
		    f = 1;
		    if(cnt[k] == 2) tmp /= 2;
		    if(cnt[k] == 3) tmp /= 6;
		    if(cnt[k] == 4) tmp /= 24;
		}
	    }
	    if(!f) ans = mul(ans,tmp / 2);
	    else ans = mul(ans,tmp);
	    if(!f) {
		if(getfa(i) != getfa(j + H / 2)) {
		    ++c;
		    fa[getfa(i)] = getfa(j + H / 2);
		}
		
	    }
	}
    }
    ans = mul(ans,fpow(2,c));
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

Submission Info

Submission Time
Task I - Reverse Grid
User sigongzi
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2622 Byte
Status RE
Exec Time 220 ms
Memory 262400 KB

Compile Error

./Main.cpp: In function ‘void Solve()’:
./Main.cpp:65:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",s[i] + 1);
                      ^

Judge Result

Set Name sample all
Score / Max Score 0 / 0 0 / 1900
Status
AC × 2
AC × 18
RE × 21
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 2 ms 256 KB
01-11.txt AC 2 ms 256 KB
01-12.txt AC 2 ms 256 KB
01-13.txt AC 2 ms 256 KB
01-14.txt RE 218 ms 262400 KB
01-15.txt RE 218 ms 262400 KB
01-16.txt RE 217 ms 262400 KB
01-17.txt RE 218 ms 262400 KB
01-18.txt RE 218 ms 262400 KB
01-19.txt RE 218 ms 262400 KB
01-20.txt RE 217 ms 262400 KB
01-21.txt RE 218 ms 262400 KB
01-22.txt RE 218 ms 262400 KB
01-23.txt RE 218 ms 262400 KB
01-24.txt RE 218 ms 262400 KB
01-25.txt RE 220 ms 262400 KB
01-26.txt RE 219 ms 262400 KB
01-27.txt RE 218 ms 262400 KB
01-28.txt RE 218 ms 262400 KB
01-29.txt AC 1 ms 256 KB
01-30.txt RE 219 ms 262400 KB
01-31.txt RE 218 ms 262400 KB
01-32.txt RE 220 ms 262400 KB
01-33.txt RE 218 ms 262400 KB
01-34.txt RE 219 ms 262400 KB
01-35.txt RE 218 ms 262400 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB