結果

問題 No.2236 Lights Out On Simple Graph
ユーザー no wayno way
提出日時 2023-03-03 22:18:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,321 ms / 4,000 ms
コード長 772 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 176,976 KB
実行使用メモリ 134,912 KB
最終ジャッジ日時 2023-10-18 02:28:12
合計ジャッジ時間 37,466 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1,119 ms
134,788 KB
testcase_04 AC 514 ms
102,144 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 726 ms
134,912 KB
testcase_07 AC 915 ms
85,752 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 234 ms
28,352 KB
testcase_11 AC 68 ms
4,348 KB
testcase_12 AC 334 ms
36,600 KB
testcase_13 AC 28 ms
7,928 KB
testcase_14 AC 677 ms
69,312 KB
testcase_15 AC 18 ms
6,912 KB
testcase_16 AC 37 ms
9,984 KB
testcase_17 AC 118 ms
15,104 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 84 ms
16,124 KB
testcase_20 AC 502 ms
69,376 KB
testcase_21 AC 83 ms
16,128 KB
testcase_22 AC 1,034 ms
134,912 KB
testcase_23 AC 1,290 ms
134,880 KB
testcase_24 AC 751 ms
69,360 KB
testcase_25 AC 160 ms
28,416 KB
testcase_26 AC 1,059 ms
134,912 KB
testcase_27 AC 576 ms
69,344 KB
testcase_28 AC 823 ms
102,144 KB
testcase_29 AC 79 ms
16,128 KB
testcase_30 AC 1,025 ms
134,912 KB
testcase_31 AC 1,129 ms
134,912 KB
testcase_32 AC 986 ms
134,912 KB
testcase_33 AC 1,126 ms
134,912 KB
testcase_34 AC 972 ms
134,912 KB
testcase_35 AC 1,242 ms
101,632 KB
testcase_36 AC 1,321 ms
71,424 KB
testcase_37 AC 1,250 ms
134,784 KB
testcase_38 AC 1,003 ms
20,224 KB
testcase_39 AC 617 ms
4,864 KB
testcase_40 AC 441 ms
28,292 KB
testcase_41 AC 72 ms
11,908 KB
testcase_42 AC 370 ms
44,784 KB
testcase_43 AC 21 ms
5,856 KB
testcase_44 AC 1,030 ms
51,968 KB
testcase_45 AC 1,132 ms
102,136 KB
testcase_46 AC 743 ms
69,252 KB
testcase_47 AC 1,063 ms
102,140 KB
testcase_48 AC 919 ms
85,636 KB
testcase_49 AC 916 ms
85,636 KB
testcase_50 AC 12 ms
4,348 KB
testcase_51 AC 237 ms
24,320 KB
testcase_52 AC 14 ms
4,592 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 580 ms
36,352 KB
testcase_55 AC 822 ms
15,104 KB
testcase_56 AC 657 ms
11,520 KB
testcase_57 AC 999 ms
18,176 KB
testcase_58 AC 615 ms
8,832 KB
testcase_59 AC 648 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int N=44;
int n,m;
int a[N],b[N],x;
long long s;
map<long long,int>mp;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d%d",&a[i],&b[i]);
	for (int i=1;i<=n;i++){
		scanf("%d",&x);
		if (x) s+=(1ll<<(i-1));
	}
	int w=(m/2);
	for (int i=0;i<(1<<w);i++){
		long long t=0;
		int sum=0;
		for (int j=0;j<w;j++) if ((i>>j)&1) t^=(1ll<<(a[j+1]-1))^(1ll<<(b[j+1]-1)),sum++;
		if (!mp[s^t]) mp[s^t]=sum+1;
		else mp[s^t]=min(mp[s^t],sum+1);
	}
	int ans=m+1;
	for (int i=0;i<(1<<(m-w));i++){
		long long t=0;
		int sum=0;
		for (int j=0;j<(m-w);j++) if ((i>>j)&1) t^=(1ll<<(a[j+1+w]-1))^(1ll<<(b[j+1+w]-1)),sum++;
		if (mp[t]) ans=min(ans,mp[t]+sum-1);
 	}
	if (ans==(m+1)) puts("-1"); else printf("%d\n",ans);
}
0