結果

問題 No.2236 Lights Out On Simple Graph
ユーザー TsReaperTsReaper
提出日時 2023-03-03 22:23:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,201 ms / 4,000 ms
コード長 1,245 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 176,676 KB
実行使用メモリ 47,344 KB
最終ジャッジ日時 2023-10-18 02:33:14
合計ジャッジ時間 27,616 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 961 ms
47,344 KB
testcase_04 AC 512 ms
25,288 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 700 ms
47,344 KB
testcase_07 AC 538 ms
14,256 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 173 ms
14,256 KB
testcase_11 AC 29 ms
4,348 KB
testcase_12 AC 250 ms
14,256 KB
testcase_13 AC 13 ms
4,832 KB
testcase_14 AC 573 ms
25,288 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 17 ms
4,832 KB
testcase_17 AC 58 ms
8,804 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 35 ms
5,976 KB
testcase_20 AC 407 ms
25,288 KB
testcase_21 AC 34 ms
5,976 KB
testcase_22 AC 969 ms
47,344 KB
testcase_23 AC 987 ms
47,344 KB
testcase_24 AC 613 ms
25,288 KB
testcase_25 AC 90 ms
8,804 KB
testcase_26 AC 964 ms
47,344 KB
testcase_27 AC 425 ms
25,288 KB
testcase_28 AC 583 ms
25,288 KB
testcase_29 AC 35 ms
5,976 KB
testcase_30 AC 938 ms
47,344 KB
testcase_31 AC 945 ms
47,344 KB
testcase_32 AC 939 ms
47,344 KB
testcase_33 AC 943 ms
47,344 KB
testcase_34 AC 952 ms
47,344 KB
testcase_35 AC 1,201 ms
47,344 KB
testcase_36 AC 772 ms
47,344 KB
testcase_37 AC 1,002 ms
47,344 KB
testcase_38 AC 427 ms
14,256 KB
testcase_39 AC 234 ms
4,348 KB
testcase_40 AC 284 ms
14,256 KB
testcase_41 AC 34 ms
5,976 KB
testcase_42 AC 146 ms
8,804 KB
testcase_43 AC 10 ms
4,348 KB
testcase_44 AC 762 ms
25,288 KB
testcase_45 AC 727 ms
25,288 KB
testcase_46 AC 701 ms
25,288 KB
testcase_47 AC 635 ms
25,288 KB
testcase_48 AC 945 ms
47,344 KB
testcase_49 AC 523 ms
14,256 KB
testcase_50 AC 7 ms
4,348 KB
testcase_51 AC 79 ms
5,976 KB
testcase_52 AC 8 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 366 ms
14,256 KB
testcase_55 AC 317 ms
8,804 KB
testcase_56 AC 283 ms
5,976 KB
testcase_57 AC 352 ms
8,804 KB
testcase_58 AC 271 ms
5,976 KB
testcase_59 AC 263 ms
5,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MAXN 40
#define MAXM 40
using namespace std;

int n, m, ans, A[MAXM][2];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &A[i][0], &A[i][1]);
        A[i][0]--; A[i][1]--;
    }
    long long goal = 0;
    for (int i = 0; i < n; i++) {
        long long x; scanf("%lld", &x);
        goal |= x << i;
    }

    unordered_map<long long, int> mp;
    int half = m / 2;
    for (int i = 0; i < (1 << half); i++) {
        long long msk = 0;
        int cnt = 0;
        for (int j = 0; j < half; j++) if (i >> j & 1) {
            msk ^= 1LL << A[j][0];
            msk ^= 1LL << A[j][1];
            cnt++;
        }
        if (mp.count(msk) == 0) mp[msk] = cnt;
        else mp[msk] = min(mp[msk], cnt);
    }

    ans = m + 1;
    for (int i = 0; i < (1 << (m - half)); i++) {
        long long msk = 0;
        int cnt = 0;
        for (int j = 0; j < m - half; j++) if (i >> j & 1) {
            msk ^= 1LL << A[j + half][0];
            msk ^= 1LL << A[j + half][1];
            cnt++;
        }
        if (mp.count(goal ^ msk)) ans = min(ans, cnt + mp[goal ^ msk]);
    }

    if (ans == m + 1) printf("-1\n");
    else printf("%d\n", ans);
    return 0;
}
0