CODE FESTIVAL 2016 Final

Submission #5399571

Source codeソースコード

#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

Task問題 I - Reverse Grid
User nameユーザ名 sigongzi
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 RE
Score得点 0
Source lengthソースコード長 2622 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./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);
^

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
all 0 / 1900 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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
01-15.txt RE
01-16.txt RE
01-17.txt RE
01-18.txt RE
01-19.txt RE
01-20.txt RE
01-21.txt RE
01-22.txt RE
01-23.txt RE
01-24.txt RE
01-25.txt RE
01-26.txt RE
01-27.txt RE
01-28.txt RE
01-29.txt AC 1 ms 256 KB
01-30.txt RE
01-31.txt RE
01-32.txt RE
01-33.txt RE
01-34.txt RE
01-35.txt RE
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB