結果

問題 No.1116 Cycles of Dense Graph
ユーザー kotatsugamekotatsugame
提出日時 2020-07-17 23:08:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,442 bytes
コンパイル時間 1,047 ms
コンパイル使用メモリ 86,840 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-07 10:44:17
合計ジャッジ時間 2,621 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 43 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 44 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 47 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 47 ms
5,376 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 44 ms
5,376 KB
testcase_40 AC 45 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<map>
using namespace std;
const long mod=998244353;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long fac[1<<17],inv[1<<17];
long comb(int N,int K){return fac[N]*inv[K]%mod*inv[N-K]%mod;}
int N,M;
int a[15],b[15];
map<pair<int,int>,long>memo;
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)cin>>a[i]>>b[i];
	fac[0]=1;
	for(int i=1;i<=N;i++)fac[i]=fac[i-1]*i%mod;
	inv[N]=power(fac[N],mod-2);
	for(int i=N;i--;)inv[i]=inv[i+1]*(i+1)%mod;
	long ans=0;
	for(int k=3;k<=N;k++)
	{
		(ans+=comb(N,k)*fac[k-1]%mod)%=mod;
	}
	for(int i=1;i<1<<M;i++)
	{
		map<int,int>mp;
		bool ok=true;
		int one=0,edge=0;
		for(int j=0;j<M;j++)if(i>>j&1)
		{
			edge++;
			if(mp[a[j]]==2)
			{
				ok=false;
				break;
			}
			else if(mp[a[j]]==1)
			{
				mp[a[j]]=2;
				one--;
			}
			else
			{
				mp[a[j]]=1;
				one++;
			}
			if(mp[b[j]]==2)
			{
				ok=false;
				break;
			}
			else if(mp[b[j]]==1)
			{
				mp[b[j]]=2;
				one--;
			}
			else
			{
				mp[b[j]]=1;
				one++;
			}
		}
		if(!ok)continue;
		int m=mp.size();
		long now;
		pair<int,int>p=make_pair(m,one);
		if(memo.find(p)!=memo.end())now=memo[p];
		else
		{
			now=0;
			for(int k=0;k<=N-m;k++)
			{
				if(m+k>=3)(now+=comb(N-m,k)*fac[k+one/2-1]%mod)%=mod;
			}
			now=now*power(2,one/2)%mod;
			if(one==0)now=2;
			memo[p]=now;
		}
		if(edge%2==1)ans=(ans+mod-now)%mod;
		else ans=(ans+now)%mod;
	}
	cout<<ans*power(2,mod-2)%mod<<endl;
}
0