提出 #485177


ソースコード 拡げる

#include<cstdio>
#include<cstring>
#include<unordered_map>
#define Q 1000000009
#define N 1000100
using namespace std;
int a[18],b[18],c[18],dp[N];
int count(int n){
	if(n==0) return 1;
	if(dp[n]>=0) return dp[n];
	return dp[n]=1LL*(3*n-1)*(3*n-2)/2%Q*count(n-1)%Q;
}
int main(){
	unordered_map<int,int> f,sz;
	memset(dp,-1,sizeof(dp));
	int n,m,i,ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
	}
	for(int i=0;i<(1<<m);i++){
		int coe=1,tmp=1,cnt[4]={};
		bool wrong=false;
		f.clear();
		sz.clear();
		for(int j=0;j<m;j++){
			if(i&(1<<j)){
				if(c[j]) coe*=-1;
				if(!f.count(a[j])) f[a[j]]=a[j],sz[a[j]]=1;
				if(!f.count(b[j])) f[b[j]]=b[j],sz[b[j]]=1;
				if(f[a[j]]!=f[b[j]]){
					if(sz[f[a[j]]]+sz[f[b[j]]]>3) wrong=true;
					else if(sz[f[a[j]]]<sz[f[b[j]]]) f[a[j]]=f[b[j]],sz[f[b[j]]]++;
					else f[b[j]]=f[a[j]],sz[f[a[j]]]++;
				}
			}
			else{
				if(!c[j]) coe*=0;
			}
		}
		if(!wrong){
			for(auto it=f.begin();it!=f.end();++it){
				if(it->first==it->second){
					cnt[sz[it->first]]++;
				}
			}
			cnt[1]=3*n-2*cnt[2]-3*cnt[3];
			for(int i=0;i<cnt[2];i++){
				tmp=1LL*tmp*cnt[1]%Q;
				cnt[1]--;
			}
			tmp=1LL*tmp*count(cnt[1]/3)%Q;
		}
		else tmp=0;
		ans+=tmp*coe;
		if(ans<0) ans+=Q;
		else if(ans>=Q) ans-=Q;
	}
	printf("%d\n",ans);
	return 0;
}

提出情報

提出日時
問題 F - ICPC Teams
ユーザ NCTU_Thor
言語 C++11 (GCC 4.9.2)
得点 100
コード長 1382 Byte
結果 AC
実行時間 1990 ms
メモリ 35872 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:17:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
                     ^
./Main.cpp:19:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&a[i],&b[i],&c[i]);
                                    ^

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 96
セット名 テストケース
All 00_sample_00, 10_VerySmallRandom_00, 10_VerySmallRandom_01, 10_VerySmallRandom_02, 10_VerySmallRandom_03, 10_VerySmallRandom_04, 10_VerySmallRandom_05, 10_VerySmallRandom_06, 10_VerySmallRandom_07, 10_VerySmallRandom_08, 10_VerySmallRandom_09, 10_VerySmallRandom_10, 10_VerySmallRandom_11, 10_VerySmallRandom_12, 10_VerySmallRandom_13, 10_VerySmallRandom_14, 10_VerySmallRandom_15, 10_VerySmallRandom_16, 10_VerySmallRandom_17, 10_VerySmallRandom_18, 10_VerySmallRandom_19, 10_VerySmallRandom_20, 10_VerySmallRandom_21, 10_VerySmallRandom_22, 10_VerySmallRandom_23, 10_VerySmallRandom_24, 20_SmallRandom_00, 20_SmallRandom_01, 20_SmallRandom_02, 20_SmallRandom_03, 20_SmallRandom_04, 20_SmallRandom_05, 20_SmallRandom_06, 20_SmallRandom_07, 20_SmallRandom_08, 20_SmallRandom_09, 30_LargeRandom_00, 30_LargeRandom_01, 30_LargeRandom_02, 30_LargeRandom_03, 30_LargeRandom_04, 30_LargeRandom_05, 30_LargeRandom_06, 30_LargeRandom_07, 30_LargeRandom_08, 30_LargeRandom_09, 30_LargeRandom_10, 30_LargeRandom_11, 30_LargeRandom_12, 30_LargeRandom_13, 30_LargeRandom_14, 40_AllOne_00, 40_AllOne_01, 40_AllOne_02, 40_AllOne_03, 40_AllOne_04, 40_AllOne_05, 40_AllOne_06, 40_AllOne_07, 40_AllOne_08, 40_AllOne_09, 40_AllOne_10, 40_AllOne_11, 40_AllOne_12, 40_AllOne_13, 40_AllOne_14, 50_ManyBigComponents_00, 50_ManyBigComponents_01, 50_ManyBigComponents_02, 50_ManyBigComponents_03, 50_ManyBigComponents_04, 50_ManyBigComponents_05, 50_ManyBigComponents_06, 50_ManyBigComponents_07, 50_ManyBigComponents_08, 50_ManyBigComponents_09, 50_ManyBigComponents_10, 50_ManyBigComponents_11, 50_ManyBigComponents_12, 50_ManyBigComponents_13, 50_ManyBigComponents_14, 60_FewIsolatedPoints_00, 60_FewIsolatedPoints_01, 60_FewIsolatedPoints_02, 60_FewIsolatedPoints_03, 60_FewIsolatedPoints_04, 60_FewIsolatedPoints_05, 60_FewIsolatedPoints_06, 60_FewIsolatedPoints_07, 60_FewIsolatedPoints_08, 60_FewIsolatedPoints_09, 60_FewIsolatedPoints_10, 60_FewIsolatedPoints_11, 60_FewIsolatedPoints_12, 60_FewIsolatedPoints_13, 60_FewIsolatedPoints_14
ケース名 結果 実行時間 メモリ
00_sample_00 AC 35 ms 4632 KiB
10_VerySmallRandom_00 AC 36 ms 4632 KiB
10_VerySmallRandom_01 AC 35 ms 4640 KiB
10_VerySmallRandom_02 AC 34 ms 4636 KiB
10_VerySmallRandom_03 AC 33 ms 4648 KiB
10_VerySmallRandom_04 AC 33 ms 4640 KiB
10_VerySmallRandom_05 AC 34 ms 4580 KiB
10_VerySmallRandom_06 AC 35 ms 4764 KiB
10_VerySmallRandom_07 AC 35 ms 4772 KiB
10_VerySmallRandom_08 AC 34 ms 4612 KiB
10_VerySmallRandom_09 AC 33 ms 4640 KiB
10_VerySmallRandom_10 AC 35 ms 4640 KiB
10_VerySmallRandom_11 AC 34 ms 4652 KiB
10_VerySmallRandom_12 AC 34 ms 4648 KiB
10_VerySmallRandom_13 AC 34 ms 4644 KiB
10_VerySmallRandom_14 AC 35 ms 4644 KiB
10_VerySmallRandom_15 AC 35 ms 4644 KiB
10_VerySmallRandom_16 AC 35 ms 4632 KiB
10_VerySmallRandom_17 AC 34 ms 4648 KiB
10_VerySmallRandom_18 AC 38 ms 4588 KiB
10_VerySmallRandom_19 AC 35 ms 4640 KiB
10_VerySmallRandom_20 AC 36 ms 4644 KiB
10_VerySmallRandom_21 AC 35 ms 4636 KiB
10_VerySmallRandom_22 AC 34 ms 4568 KiB
10_VerySmallRandom_23 AC 33 ms 4640 KiB
10_VerySmallRandom_24 AC 34 ms 4640 KiB
20_SmallRandom_00 AC 1630 ms 4636 KiB
20_SmallRandom_01 AC 35 ms 4644 KiB
20_SmallRandom_02 AC 37 ms 4768 KiB
20_SmallRandom_03 AC 34 ms 4648 KiB
20_SmallRandom_04 AC 76 ms 4648 KiB
20_SmallRandom_05 AC 789 ms 4648 KiB
20_SmallRandom_06 AC 122 ms 4644 KiB
20_SmallRandom_07 AC 35 ms 4644 KiB
20_SmallRandom_08 AC 75 ms 4640 KiB
20_SmallRandom_09 AC 33 ms 4760 KiB
30_LargeRandom_00 AC 1917 ms 35748 KiB
30_LargeRandom_01 AC 1921 ms 32932 KiB
30_LargeRandom_02 AC 1939 ms 33700 KiB
30_LargeRandom_03 AC 1941 ms 34212 KiB
30_LargeRandom_04 AC 1932 ms 35616 KiB
30_LargeRandom_05 AC 1917 ms 33188 KiB
30_LargeRandom_06 AC 1917 ms 35236 KiB
30_LargeRandom_07 AC 1939 ms 34584 KiB
30_LargeRandom_08 AC 1919 ms 34208 KiB
30_LargeRandom_09 AC 1925 ms 33180 KiB
30_LargeRandom_10 AC 1920 ms 34468 KiB
30_LargeRandom_11 AC 1956 ms 32860 KiB
30_LargeRandom_12 AC 1950 ms 33056 KiB
30_LargeRandom_13 AC 1933 ms 34476 KiB
30_LargeRandom_14 AC 1966 ms 35748 KiB
40_AllOne_00 AC 1901 ms 33188 KiB
40_AllOne_01 AC 1925 ms 34848 KiB
40_AllOne_02 AC 1922 ms 34716 KiB
40_AllOne_03 AC 1966 ms 34972 KiB
40_AllOne_04 AC 1990 ms 35368 KiB
40_AllOne_05 AC 1944 ms 35872 KiB
40_AllOne_06 AC 1937 ms 33832 KiB
40_AllOne_07 AC 1914 ms 34600 KiB
40_AllOne_08 AC 1933 ms 33316 KiB
40_AllOne_09 AC 1949 ms 33952 KiB
40_AllOne_10 AC 1916 ms 34464 KiB
40_AllOne_11 AC 1909 ms 34204 KiB
40_AllOne_12 AC 1966 ms 33700 KiB
40_AllOne_13 AC 1950 ms 33828 KiB
40_AllOne_14 AC 1944 ms 35492 KiB
50_ManyBigComponents_00 AC 1413 ms 35228 KiB
50_ManyBigComponents_01 AC 1374 ms 35492 KiB
50_ManyBigComponents_02 AC 1438 ms 34076 KiB
50_ManyBigComponents_03 AC 1488 ms 35168 KiB
50_ManyBigComponents_04 AC 1463 ms 34600 KiB
50_ManyBigComponents_05 AC 1363 ms 33440 KiB
50_ManyBigComponents_06 AC 1410 ms 35492 KiB
50_ManyBigComponents_07 AC 1376 ms 34460 KiB
50_ManyBigComponents_08 AC 1453 ms 34084 KiB
50_ManyBigComponents_09 AC 1456 ms 34216 KiB
50_ManyBigComponents_10 AC 1384 ms 33056 KiB
50_ManyBigComponents_11 AC 1322 ms 33436 KiB
50_ManyBigComponents_12 AC 1385 ms 35620 KiB
50_ManyBigComponents_13 AC 1435 ms 35248 KiB
50_ManyBigComponents_14 AC 1388 ms 35096 KiB
60_FewIsolatedPoints_00 AC 1629 ms 4648 KiB
60_FewIsolatedPoints_01 AC 1628 ms 4656 KiB
60_FewIsolatedPoints_02 AC 1687 ms 4644 KiB
60_FewIsolatedPoints_03 AC 1640 ms 4736 KiB
60_FewIsolatedPoints_04 AC 1723 ms 4636 KiB
60_FewIsolatedPoints_05 AC 1688 ms 4644 KiB
60_FewIsolatedPoints_06 AC 1697 ms 4636 KiB
60_FewIsolatedPoints_07 AC 1682 ms 4640 KiB
60_FewIsolatedPoints_08 AC 1617 ms 4644 KiB
60_FewIsolatedPoints_09 AC 1624 ms 4768 KiB
60_FewIsolatedPoints_10 AC 1689 ms 4648 KiB
60_FewIsolatedPoints_11 AC 1704 ms 4640 KiB
60_FewIsolatedPoints_12 AC 1657 ms 4644 KiB
60_FewIsolatedPoints_13 AC 1630 ms 4644 KiB
60_FewIsolatedPoints_14 AC 1666 ms 4644 KiB