結果

問題 No.2236 Lights Out On Simple Graph
ユーザー pengin_2000pengin_2000
提出日時 2023-03-03 22:47:54
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,372 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 32,004 KB
実行使用メモリ 27,760 KB
最終ジャッジ日時 2023-10-18 03:05:22
合計ジャッジ時間 18,996 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,048 KB
testcase_01 AC 2 ms
6,048 KB
testcase_02 AC 2 ms
6,048 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
6,056 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
6,048 KB
testcase_09 AC 2 ms
6,048 KB
testcase_10 RE -
testcase_11 AC 26 ms
8,128 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 26 ms
14,908 KB
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 AC 190 ms
25,280 KB
testcase_39 AC 183 ms
20,772 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 10 ms
12,860 KB
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 AC 6 ms
6,064 KB
testcase_51 RE -
testcase_52 AC 7 ms
8,764 KB
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 189 ms
27,328 KB
testcase_56 AC 185 ms
27,328 KB
testcase_57 AC 196 ms
27,328 KB
testcase_58 AC 182 ms
27,328 KB
testcase_59 AC 182 ms
27,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int popcount(long long int n)
{
	long long int res = 0;
	for (; n > 0; n /= 2)
		res += n % 2;
	return res;
}
long long int a[44], b[44], c[44];
long long int dp1[1100006], dp2[1100006];
long long int dp3[1100006];
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int i, j, k;
	for (i = 0; i < m; i++)
	{
		scanf("%lld %lld", &a[i], &b[i]);
		a[i]--;
		b[i]--;
	}
	for (i = 0; i < n; i++)
		scanf("%lld", &c[i]);
	for (i = 0; i < (1 << (m / 2)); i++)
	{
		dp1[i] = 0;
		for (k = 0; k < m / 2; k++)
		{
			if ((i & (1 << k)) == 0)
				continue;
			dp1[i] ^= (1 << a[k]);
			dp1[i] ^= (1 << b[k]);
		}
	}
	for (i = 0; i < (1 << (m - m / 2)); i++)
	{
		dp2[i] = 0;
		for (k = m / 2; k < m; k++)
		{
			if ((i & (1 << (k - m / 2))) == 0)
				continue;
			dp2[i] ^= (1 << a[k]);
			dp2[i] ^= (1 << b[k]);
		}
	}
	for (i = 0; i < (1 << n); i++)
		dp3[i] = -1;
	for (i = 0; i < (1 << (m - m / 2)); i++)
	{
		if (dp3[dp2[i]] < 0)
			dp3[dp2[i]] = popcount(i);
		else if (dp3[dp2[i]] > popcount(i))
			dp3[dp2[i]] = popcount(i);
	}
	long long int ans = -1, cc = 0;
	for (i = 0; i < n; i++)
		cc ^= c[i] * (1 << i);
	for (i = 0; i < (1 << (m / 2)); i++)
	{
		if (dp3[cc ^ dp1[i]] < 0)
			continue;
		if (ans<0 || ans>dp3[cc ^ dp1[i]] + popcount(i))
			ans = dp3[cc ^ dp1[i]] + popcount(i);
	}
	printf("%lld\n", ans);
	return 0;
}
0