CODE FESTIVAL 2016 Final

Submission #10080939

Source codeソースコード

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
struct unionfind{
    vector<int> par, sz; int cnt;
    unionfind() {}
    unionfind(int n):cnt(n), par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x]; cnt--;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
	int h, w;
	cin>>h>>w;
	string s[202];
	for(int i=0; i<h; i++) cin>>s[i];
	ll ans=1;
	if(h&1){
		string t=s[h/2];
		reverse(t.begin(), t.end());
		if(s[h/2]!=t) ans*=2;
	}
	if(w&1){
		string t, u;
		for(int i=0; i<h; i++) t+=s[i][w/2];
		u=t;
		reverse(u.begin(), u.end());
		if(t!=u) ans*=2;
	}
  unionfind uf(h/2+w/2);
	for(int i=0; i<h/2; i++){
		for(int j=0; j<w/2; j++){
			string t; int cnt[3]={};
			t+=s[i][j];
			t+=s[h-1-i][j];
			t+=s[i][w-1-j];
			t+=s[h-1-i][w-1-j];
			int ind[4]={0, 1, 2, 3};
			set<string> st[2];
			do{
				int c=0;
				for(int k=0; k<4; k++) for(int l=k+1; l<4; l++) if(ind[k]>ind[l]) c^=1;
				string u;
				for(int k=0; k<4; k++) u+=t[ind[k]];
				st[c].insert(u);
			}while(next_permutation(ind, ind+4));
          for(auto u:st[0]) if(st[1].find(u)!=st[1].end()) cnt[2]++;
          for(int k=0; k<2; k++) cnt[k]=st[k].size()-cnt[2];
          if(cnt[0]==0) (ans*=cnt[2])%=MOD;
          else (ans*=cnt[0])%=MOD, uf.unite(i, j+h/2);
		}
	}
  for(int i=0; i<h/2+w/2-uf.cnt; i++) (ans*=2)%=MOD;
  cout<<ans<<endl;
	return 0;
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
all 1900 / 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 2 ms 256 KB
01-04.txt AC 2 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 2 ms 256 KB
01-09.txt AC 2 ms 256 KB
01-10.txt AC 47 ms 256 KB
01-11.txt AC 58 ms 256 KB
01-12.txt AC 59 ms 256 KB
01-13.txt AC 47 ms 256 KB
01-14.txt AC 20 ms 256 KB
01-15.txt AC 19 ms 256 KB
01-16.txt AC 76 ms 256 KB
01-17.txt AC 75 ms 256 KB
01-18.txt AC 79 ms 256 KB
01-19.txt AC 73 ms 256 KB
01-20.txt AC 86 ms 256 KB
01-21.txt AC 74 ms 256 KB
01-22.txt AC 3 ms 256 KB
01-23.txt AC 37 ms 256 KB
01-24.txt AC 69 ms 256 KB
01-25.txt AC 70 ms 256 KB
01-26.txt AC 71 ms 256 KB
01-27.txt AC 5 ms 256 KB
01-28.txt AC 13 ms 256 KB
01-29.txt AC 2 ms 256 KB
01-30.txt AC 14 ms 256 KB
01-31.txt AC 74 ms 256 KB
01-32.txt AC 74 ms 256 KB
01-33.txt AC 72 ms 256 KB
01-34.txt AC 87 ms 256 KB
01-35.txt AC 74 ms 256 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB