CODE FESTIVAL 2016 Final

Submission #994363

Source codeソースコード

#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
using namespace std;
char map[200][200];
#define SIZE 1000
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for(int i=0;i<SIZE;i++)
		{
			par[i]=i;
			ran[i]=0;
			ren[i]=1;
		}
	}
	int find(int a)
	{
		if(a==par[a])return a;
		else return par[a]=find(par[a]);
	}
	void unite(int a,int b)
	{
		a=find(a);
		b=find(b);
		if(a==b)return;
		if(ran[a]>ran[b])
		{
			par[b]=a;
			ren[a]+=ren[b];
		}
		else
		{
			par[a]=b;
			ren[b]+=ren[a];
		}
		if(ran[a]==ran[b])ran[b]++;
	}
};
unionfind uf;
typedef long long ll;
ll mod=1000000007;
int main()
{
	int mx,my;
	scanf("%d%d",&mx,&my);
	for(int i=0;i<mx;i++)
	{
		for(int j=0;j<my;j++)
		{
			scanf(" %c",&map[i][j]);
		}
	}
	ll ret=1;
	if(mx%2==1)
	{
		for(int i=0;i<my;i++)
		{
			if(map[mx/2][i]!=map[mx/2][my-1-i])
			{
				ret*=2;
				break;
			}
		}
	}
	if(my%2==1)
	{
		for(int i=0;i<mx;i++)
		{
			if(map[i][my/2]!=map[mx-1-i][my/2])
			{
				ret*=2;
				break;
			}
		}
	}
	uf.init();
	for(int i=0;i<mx/2;i++)
	{
		for(int j=0;j<my/2;j++)
		{
			vector<char>v;
			v.push_back(map[i][j]);
			v.push_back(map[mx-1-i][j]);
			v.push_back(map[i][my-1-j]);
			v.push_back(map[mx-1-i][my-1-j]);
			sort(v.begin(),v.end());
			int r=0;
			for(;;)
			{
				r++;
				if(!next_permutation(v.begin(),v.end()))break;
			}
			if(r==24)
			{
				if(uf.find(i)!=uf.find(j+200))
				{
					uf.unite(i,j+200);
				}
				else r/=2;
			}
			ret*=r;
			ret%=mod;
		}
	}
	printf("%lld\n",ret);
}

Submission

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

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:54:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&mx,&my);
^
./Main.cpp:59:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&map[i][j]);
^

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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 3 ms 256 KB
01-02.txt AC 3 ms 256 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 2 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 3 ms 256 KB
01-07.txt AC 3 ms 256 KB
01-08.txt AC 3 ms 256 KB
01-09.txt AC 3 ms 256 KB
01-10.txt AC 6 ms 256 KB
01-11.txt AC 6 ms 256 KB
01-12.txt AC 6 ms 256 KB
01-13.txt AC 6 ms 256 KB
01-14.txt AC 3 ms 256 KB
01-15.txt AC 4 ms 256 KB
01-16.txt AC 7 ms 256 KB
01-17.txt AC 7 ms 256 KB
01-18.txt AC 7 ms 256 KB
01-19.txt AC 6 ms 256 KB
01-20.txt AC 6 ms 256 KB
01-21.txt AC 6 ms 256 KB
01-22.txt AC 3 ms 256 KB
01-23.txt AC 5 ms 256 KB
01-24.txt AC 6 ms 256 KB
01-25.txt AC 6 ms 256 KB
01-26.txt AC 7 ms 256 KB
01-27.txt AC 3 ms 256 KB
01-28.txt AC 3 ms 256 KB
01-29.txt AC 3 ms 256 KB
01-30.txt AC 3 ms 256 KB
01-31.txt AC 7 ms 256 KB
01-32.txt AC 7 ms 256 KB
01-33.txt AC 7 ms 256 KB
01-34.txt AC 7 ms 256 KB
01-35.txt AC 7 ms 256 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB