Submission #994287


Source Code Expand

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b){
	if(b == 0) return a;
	return gcd(b,a%b);
}
LL powmod(LL a, LL n){
	if(n == 0) return 1;
	if(n % 2) return (a*powmod(a,n-1)) % MOD;
	LL c = powmod(a,n/2);
	return (c*c) % MOD;
}
LL inv(LL a){
	return powmod(a,MOD-2) % MOD;
}
int main(){
	int a, b;
	cin >> a >> b;
	int freq[26];
	string s[a];
	for(int i = 0; i < a; i++) cin >> s[i];
	LL ans = 1;
	LL num24 = 0;

	for(int i = 0; i < a-1-i; i++){
		for(int j = 0; j < b-1-j; j++){
			//cout << i << " " << j << endl;
			for(int z = 0; z < 26; z++) freq[z] = 0;
			freq[s[i][j]-'a']++;
			freq[s[a-1-i][j]-'a']++;
			freq[s[i][b-1-j]-'a']++;
			freq[s[a-1-i][b-1-j]-'a']++;
			LL r = 24;
			for(int z = 0; z < 26; z++){
				if(freq[z] == 4) r /= 24;
				if(freq[z] == 3) r /= 6;
				if(freq[z] == 2) r /= 2;
			}
			if(r != 24) num24++;
			ans *= r;
			ans %= MOD;
		}
	}
	if(a >= 4 && b >= 1){
		LL c = (a/2-1)*(b/2-1);
		if(c-num24 >= 0){
			ans *= powmod(inv(2),c-num24);
		}
	}
	if(a % 2){
		int c = (a-1)/2;
		LL ok = 1;
		for(int j = 0; j < b; j++){
			if(s[c][j] != s[c][b-1-j]) ok = 2;
		}
		ans *= ok;
		ans %= MOD;
	}
	if(b % 2){
		int c = (b-1)/2;
		LL ok = 1;
		for(int j = 0; j < a; j++){
			if(s[j][c] != s[a-1-j][c]) ok = 2;
		}
		ans *= ok;
		ans %= MOD;
	}
	cout << ans % MOD << endl;
}

Submission Info

Submission Time
Task A - Where's Snuke?
User ksun48
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1434 Byte
Status WA
Exec Time 116 ms
Memory 384 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 0 / 100
Status
WA × 2
WA × 8
RE × 1
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
Case Name Status Exec Time Memory
01-01.txt WA 3 ms 256 KB
01-02.txt WA 3 ms 256 KB
01-03.txt WA 3 ms 256 KB
01-04.txt WA 3 ms 256 KB
01-05.txt RE 116 ms 384 KB
01-06.txt WA 3 ms 256 KB
01-07.txt WA 3 ms 384 KB
sample-01.txt WA 3 ms 256 KB
sample-02.txt WA 3 ms 256 KB