結果

問題 No.2236 Lights Out On Simple Graph
ユーザー 沙耶花沙耶花
提出日時 2023-03-03 21:46:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,536 ms / 4,000 ms
コード長 1,048 bytes
コンパイル時間 4,904 ms
コンパイル使用メモリ 271,384 KB
実行使用メモリ 134,752 KB
最終ジャッジ日時 2023-10-18 01:45:39
合計ジャッジ時間 57,737 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1,341 ms
134,752 KB
testcase_04 AC 717 ms
101,984 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 894 ms
134,752 KB
testcase_07 AC 1,134 ms
85,600 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 810 ms
71,264 KB
testcase_11 AC 319 ms
4,348 KB
testcase_12 AC 827 ms
73,312 KB
testcase_13 AC 818 ms
69,280 KB
testcase_14 AC 1,025 ms
101,984 KB
testcase_15 AC 731 ms
69,248 KB
testcase_16 AC 686 ms
69,344 KB
testcase_17 AC 610 ms
37,472 KB
testcase_18 AC 736 ms
69,216 KB
testcase_19 AC 751 ms
69,728 KB
testcase_20 AC 873 ms
85,600 KB
testcase_21 AC 777 ms
69,728 KB
testcase_22 AC 1,283 ms
134,752 KB
testcase_23 AC 1,456 ms
134,752 KB
testcase_24 AC 1,130 ms
101,984 KB
testcase_25 AC 707 ms
71,264 KB
testcase_26 AC 1,313 ms
134,752 KB
testcase_27 AC 968 ms
85,600 KB
testcase_28 AC 1,099 ms
101,984 KB
testcase_29 AC 839 ms
69,728 KB
testcase_30 AC 1,271 ms
134,752 KB
testcase_31 AC 1,311 ms
134,752 KB
testcase_32 AC 1,218 ms
134,752 KB
testcase_33 AC 1,343 ms
134,752 KB
testcase_34 AC 1,189 ms
134,752 KB
testcase_35 AC 1,414 ms
101,984 KB
testcase_36 AC 1,243 ms
73,312 KB
testcase_37 AC 1,536 ms
134,752 KB
testcase_38 AC 974 ms
24,160 KB
testcase_39 AC 702 ms
5,216 KB
testcase_40 AC 669 ms
40,544 KB
testcase_41 AC 625 ms
20,320 KB
testcase_42 AC 667 ms
44,640 KB
testcase_43 AC 437 ms
11,936 KB
testcase_44 AC 1,181 ms
52,832 KB
testcase_45 AC 1,324 ms
101,984 KB
testcase_46 AC 1,016 ms
69,216 KB
testcase_47 AC 1,209 ms
101,984 KB
testcase_48 AC 1,200 ms
85,600 KB
testcase_49 AC 1,128 ms
85,600 KB
testcase_50 AC 272 ms
4,348 KB
testcase_51 AC 585 ms
24,160 KB
testcase_52 AC 464 ms
11,904 KB
testcase_53 AC 4 ms
4,348 KB
testcase_54 AC 926 ms
52,832 KB
testcase_55 AC 938 ms
15,968 KB
testcase_56 AC 845 ms
11,872 KB
testcase_57 AC 999 ms
20,064 KB
testcase_58 AC 747 ms
8,800 KB
testcase_59 AC 786 ms
8,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
int n,m;
void go(vector<pair<int,int>> a,map<long long,int> &mp){
	int mm = a.size();
	rep(i,1<<mm){
		long long B = 0;
		int s = 0;
		rep(j,mm){
			if((i>>j)&1){
				B ^= 1LL<<a[j].first;
				B ^= 1LL<<a[j].second;
				s++;
			}
		}
		if(mp.count(B))mp[B] = min(mp[B],s);
		else mp[B] = s;
	}
}
		

int main(){
	
	
	cin>>n>>m;
	
	vector<pair<int,int>> a,b;
	rep(i,m){
		int x,y;
		cin>>x>>y;
		x--,y--;
		if(a.size()<20){
			a.emplace_back(x,y);
		}
		else{
			b.emplace_back(x,y);
		}
	}
	
	map<long long,int> mp1,mp2;
	go(a,mp1);
	go(b,mp2);
	long long c = 0;
	rep(i,n){
		int t;
		cin>>t;
		if(t)c |= 1LL<<i;
	}
	
	int ans = Inf32;
	
	for(auto x:mp1){
		if(mp2.count(c^x.first)){
			ans = min(ans,x.second + mp2[c^x.first]);
		}
	}
	
	
	if(ans==Inf32)ans = -1;
	cout<<ans<<endl;
	
	return 0;
}
0