結果

問題 No.2236 Lights Out On Simple Graph
ユーザー ripityripity
提出日時 2023-03-03 22:28:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,414 ms / 4,000 ms
コード長 1,135 bytes
コンパイル時間 3,378 ms
コンパイル使用メモリ 230,704 KB
実行使用メモリ 69,172 KB
最終ジャッジ日時 2023-10-18 02:38:21
合計ジャッジ時間 33,626 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 972 ms
69,172 KB
testcase_04 AC 412 ms
36,404 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 752 ms
69,172 KB
testcase_07 AC 568 ms
20,020 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 223 ms
20,020 KB
testcase_11 AC 66 ms
4,348 KB
testcase_12 AC 283 ms
20,020 KB
testcase_13 AC 24 ms
5,684 KB
testcase_14 AC 495 ms
36,404 KB
testcase_15 AC 12 ms
4,660 KB
testcase_16 AC 25 ms
5,684 KB
testcase_17 AC 119 ms
11,828 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 54 ms
7,732 KB
testcase_20 AC 460 ms
36,404 KB
testcase_21 AC 56 ms
7,732 KB
testcase_22 AC 914 ms
69,172 KB
testcase_23 AC 1,108 ms
69,172 KB
testcase_24 AC 571 ms
36,404 KB
testcase_25 AC 106 ms
11,828 KB
testcase_26 AC 920 ms
69,172 KB
testcase_27 AC 491 ms
36,404 KB
testcase_28 AC 502 ms
36,404 KB
testcase_29 AC 57 ms
7,732 KB
testcase_30 AC 932 ms
69,172 KB
testcase_31 AC 987 ms
69,172 KB
testcase_32 AC 791 ms
69,172 KB
testcase_33 AC 968 ms
69,172 KB
testcase_34 AC 934 ms
69,172 KB
testcase_35 AC 1,108 ms
69,172 KB
testcase_36 AC 1,414 ms
69,172 KB
testcase_37 AC 1,132 ms
69,172 KB
testcase_38 AC 1,081 ms
20,020 KB
testcase_39 AC 619 ms
4,660 KB
testcase_40 AC 418 ms
20,020 KB
testcase_41 AC 56 ms
7,732 KB
testcase_42 AC 195 ms
11,828 KB
testcase_43 AC 18 ms
4,660 KB
testcase_44 AC 966 ms
36,404 KB
testcase_45 AC 857 ms
36,404 KB
testcase_46 AC 610 ms
36,404 KB
testcase_47 AC 705 ms
36,404 KB
testcase_48 AC 1,005 ms
69,172 KB
testcase_49 AC 565 ms
20,020 KB
testcase_50 AC 11 ms
4,348 KB
testcase_51 AC 153 ms
7,732 KB
testcase_52 AC 14 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 451 ms
20,020 KB
testcase_55 AC 806 ms
11,828 KB
testcase_56 AC 556 ms
7,732 KB
testcase_57 AC 876 ms
11,828 KB
testcase_58 AC 570 ms
7,732 KB
testcase_59 AC 621 ms
7,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	long long state_init = 0;
	vector<int> a(M), b(M);
	for( int i = 0; i < M; i++ ) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
	}
	for( int i = 0; i < N; i++ ) {
		long long c;
		cin >> c;
		state_init |= c<<i;
	}
	int m1 = M/2, m2 = (M+1)/2, ans = 100;
	map<long long, int> mp;
	for( int S = 0; S < 1<<m1; S++ ) {
		long long state = 0;
		for( int i = 0; i < m1; i++ ) {
			if( (S>>i)&1 ) {
				state ^= 1LL<<a[i];
				state ^= 1LL<<b[i];
			}
		}
		if( !mp.count(state) ) {
			mp[state] = M;
		}
		mp[state] = min(mp[state], __builtin_popcount(S));
	}
	for( int S = 0; S < 1<<m2; S++ ) {
		long long state = 0;
		for( int i = m1; i < m1+m2; i++ ) {
			if( (S>>(i-m1))&1 ) {
				state ^= 1LL<<a[i];
				state ^= 1LL<<b[i];
			}
		}
		if( mp.count(state^state_init) ) {
			ans = min(ans, mp[state^state_init]+__builtin_popcount(S));
		}
	}
	if( ans == 100 ) {
		cout << -1 << endl;
	}else {
		cout << ans << endl;
	}
}
0