結果

問題 No.2236 Lights Out On Simple Graph
ユーザー りあんりあん
提出日時 2023-03-03 22:17:13
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,342 ms / 4,000 ms
コード長 1,554 bytes
コンパイル時間 3,837 ms
コンパイル使用メモリ 268,756 KB
実行使用メモリ 47,244 KB
最終ジャッジ日時 2023-10-18 02:26:46
合計ジャッジ時間 32,438 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,084 ms
47,244 KB
testcase_04 AC 558 ms
25,188 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 774 ms
47,244 KB
testcase_07 AC 584 ms
14,156 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 201 ms
14,156 KB
testcase_11 AC 28 ms
4,348 KB
testcase_12 AC 277 ms
14,156 KB
testcase_13 AC 14 ms
4,664 KB
testcase_14 AC 624 ms
25,188 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 17 ms
4,664 KB
testcase_17 AC 77 ms
8,704 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 40 ms
5,876 KB
testcase_20 AC 457 ms
25,188 KB
testcase_21 AC 38 ms
5,876 KB
testcase_22 AC 1,082 ms
47,244 KB
testcase_23 AC 1,069 ms
47,244 KB
testcase_24 AC 661 ms
25,188 KB
testcase_25 AC 111 ms
8,704 KB
testcase_26 AC 1,072 ms
47,244 KB
testcase_27 AC 487 ms
25,188 KB
testcase_28 AC 661 ms
25,188 KB
testcase_29 AC 39 ms
5,876 KB
testcase_30 AC 1,061 ms
47,244 KB
testcase_31 AC 1,089 ms
47,244 KB
testcase_32 AC 1,083 ms
47,244 KB
testcase_33 AC 1,056 ms
47,244 KB
testcase_34 AC 1,048 ms
47,244 KB
testcase_35 AC 1,342 ms
47,244 KB
testcase_36 AC 873 ms
47,244 KB
testcase_37 AC 1,126 ms
47,244 KB
testcase_38 AC 458 ms
14,156 KB
testcase_39 AC 223 ms
4,348 KB
testcase_40 AC 333 ms
14,156 KB
testcase_41 AC 40 ms
5,876 KB
testcase_42 AC 180 ms
8,704 KB
testcase_43 AC 11 ms
4,348 KB
testcase_44 AC 871 ms
25,188 KB
testcase_45 AC 817 ms
25,188 KB
testcase_46 AC 766 ms
25,188 KB
testcase_47 AC 703 ms
25,188 KB
testcase_48 AC 1,060 ms
47,244 KB
testcase_49 AC 598 ms
14,156 KB
testcase_50 AC 6 ms
4,348 KB
testcase_51 AC 91 ms
5,876 KB
testcase_52 AC 8 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 435 ms
14,156 KB
testcase_55 AC 338 ms
8,704 KB
testcase_56 AC 289 ms
5,876 KB
testcase_57 AC 384 ms
8,704 KB
testcase_58 AC 271 ms
5,876 KB
testcase_59 AC 257 ms
5,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

using P = pair<int, int>;

const int M = 998244353;
const long long LM = 1LL << 60;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<P> edges(m);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        edges[i] = { u, v };
    }
    vector<int> c(n);
    long long st = 0;
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        if (c[i] == 1) {
            st ^= 1LL << i;
        }
    }
    int n1 = m / 2;
    int n2 = m - n1;
    unordered_map<long long, int> mp;
    for (int i = 0; i < (1 << n1); ++i) {
        long long p = 0;
        int c = 0;
        for (int j = 0; j < n1; ++j) {
            if ((i >> j) & 1) {
                p ^= (1LL << edges[j].first) ^ (1LL << edges[j].second);
                ++c;
            }
        }
        if (!mp.count(p)) {
            mp[p] = c;
        }
        mp[p] = min(mp[p], c);
    }
    int ans = M;
    for (int i = 0; i < (1 << n2); ++i) {
        long long p = 0;
        int c = 0;
        for (int j = 0; j < n2; ++j) {
            if ((i >> j) & 1) {
                p ^= (1LL << edges[n1 + j].first) ^ (1LL << edges[n1 + j].second);
                ++c;
            }
        }
        if (mp.count(p ^ st)) {
            ans = min(ans, mp[p ^ st] + c);
        }
    }
    cout << (ans == M ? -1 : ans) << '\n';

    return 0;
}
0