Submission #1004396


Source Code Expand

#include <cstdio>
#include <cmath>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w;
char s[200][201];
const int MOD = 1000000007;
LL ans = 1;
bool ii[100], jj[100];

void calc(int i, int j) {
	char a = s[        i][        j];
	char b = s[        i][w - 1 - j];
	char c = s[h - 1 - i][        j];
	char d = s[h - 1 - i][w - 1 - j];
	
	int eq = 0;
	if(a == b) { eq++; }
	if(a == c) { eq++; }
	if(a == d) { eq++; }
	if(b == c) { eq++; }
	if(b == d) { eq++; }
	if(c == d) { eq++; }
	
	if(eq == 0) {
		ii[i] = true;
		jj[j] = true;
	}
	
	int map[] = { 12, 12, 6, 4, 0, 0, 1 };
	(ans *= map[eq]) %= MOD;
}

int main() {
	scanf("%d%d", &h, &w);
	inc(i, h) { scanf("%s", s[i]); }
	
	if(h % 2 == 1) {
		bool flag = true;
		inc(i, w / 2) { if(s[h / 2][i] != s[h / 2][w - 1 - i]) { flag = false; break; } }
		if(! flag) { ans *= 2; }
	}
	if(w % 2 == 1) {
		bool flag = true;
		inc(i, h / 2) { if(s[i][w / 2] != s[h - 1 - i][w / 2]) { flag = false; break; } }
		if(! flag) { ans *= 2; }
	}
	
	inc(i, h / 2) {
	inc(j, w / 2) {
		calc(i, j);
	}
	}
	
	bool one = false;
	inc(i, h / 2) { if(ii[i]) { if(one) { (ans *= 2) %= MOD; } else { one = true; } } }
	inc(j, w / 2) { if(jj[j]) { if(one) { (ans *= 2) %= MOD; } else { one = true; } } }
	
	printf("%lld\n", ans);
	
	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:60:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &h, &w);
                       ^
./Main.cpp:61:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  inc(i, h) { scanf("%s", s[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 1 ms 128 KB
01-02.txt AC 1 ms 128 KB
01-03.txt AC 1 ms 128 KB
01-04.txt AC 1 ms 128 KB
01-05.txt AC 1 ms 128 KB
01-06.txt AC 1 ms 128 KB
01-07.txt AC 1 ms 128 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 AC 1 ms 128 KB
01-15.txt AC 1 ms 256 KB
01-16.txt AC 2 ms 256 KB
01-17.txt AC 2 ms 256 KB
01-18.txt AC 2 ms 256 KB
01-19.txt AC 2 ms 256 KB
01-20.txt AC 2 ms 256 KB
01-21.txt AC 2 ms 256 KB
01-22.txt AC 1 ms 128 KB
01-23.txt AC 2 ms 128 KB
01-24.txt AC 2 ms 256 KB
01-25.txt AC 2 ms 256 KB
01-26.txt AC 2 ms 256 KB
01-27.txt AC 1 ms 128 KB
01-28.txt AC 1 ms 128 KB
01-29.txt AC 1 ms 256 KB
01-30.txt AC 1 ms 128 KB
01-31.txt AC 2 ms 256 KB
01-32.txt AC 2 ms 256 KB
01-33.txt AC 2 ms 256 KB
01-34.txt AC 2 ms 256 KB
01-35.txt AC 2 ms 256 KB
sample-01.txt AC 1 ms 128 KB
sample-02.txt AC 1 ms 128 KB