結果

問題 No.2435 Order All Company
ユーザー cho435cho435
提出日時 2023-08-26 01:56:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 3,922 ms
コンパイル使用メモリ 268,772 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 01:57:05
合計ジャッジ時間 6,360 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 45 ms
4,380 KB
testcase_06 AC 41 ms
4,380 KB
testcase_07 AC 23 ms
4,376 KB
testcase_08 AC 38 ms
4,380 KB
testcase_09 AC 39 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 29 ms
4,380 KB
testcase_15 AC 33 ms
4,376 KB
testcase_16 AC 26 ms
4,380 KB
testcase_17 AC 38 ms
4,380 KB
testcase_18 AC 24 ms
4,380 KB
testcase_19 AC 25 ms
4,376 KB
testcase_20 AC 24 ms
4,380 KB
testcase_21 AC 29 ms
4,376 KB
testcase_22 AC 30 ms
4,380 KB
testcase_23 AC 19 ms
4,380 KB
testcase_24 AC 30 ms
4,380 KB
testcase_25 AC 28 ms
4,380 KB
testcase_26 AC 28 ms
4,380 KB
testcase_27 AC 30 ms
4,376 KB
testcase_28 AC 25 ms
4,380 KB
testcase_29 AC 29 ms
4,376 KB
testcase_30 AC 30 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;


int n;
using mat=vector<vector<mint>>;

void tri(mat &a){
	rep(i,n-1){
		if(a.at(i).at(i)==0){
			for(int j=i+1;j<n;j++){
				if(a.at(j).at(i)!=0){
					swap(a.at(i),a.at(j));
					rep(k,n) a.at(j).at(k)*=-1;
					break;
				}
			}
			if(a.at(i).at(i)==0) continue;
		}
		for(int j=i+1;j<n;j++){
			mint p=a.at(j).at(i)/a.at(i).at(i);
			rep(k,n) a.at(j).at(k)-=a.at(i).at(k)*p;
		}
	}
}

int main(){
	int k;
	cin>>n>>k;
	vector<mat> g(k,mat(n,vector<mint>(n,0)));
	rep(i,k){
		int t;
		cin>>t;
		rep(lp,t){
			int a,b;
			cin>>a>>b;
			a--; b--;
			g.at(i).at(a).at(a)++;
			g.at(i).at(b).at(b)++;
			g.at(i).at(a).at(b)--;
			g.at(i).at(b).at(a)--;
		}
	}
	mint ans=0;
	rep(bit,(1<<k)){
		mat ad(n,vector<mint>(n,0));
		rep(i,k){
			if(bit>>i&1){
				rep(a,n) rep(b,n) ad.at(a).at(b)+=g.at(i).at(a).at(b);
			}
		}
		tri(ad);
		mint tmp=1;
		rep(i,n-1) tmp*=ad.at(i).at(i);
		if((k-__builtin_popcount(bit))%2==0) ans+=tmp;
		else ans-=tmp;
	}
	cout<<ans.val()<<endl;
}
0