結果

問題 No.2236 Lights Out On Simple Graph
ユーザー t98slidert98slider
提出日時 2023-03-04 00:33:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,296 bytes
コンパイル時間 1,812 ms
コンパイル使用メモリ 176,548 KB
実行使用メモリ 134,352 KB
最終ジャッジ日時 2023-10-18 03:57:37
合計ジャッジ時間 11,838 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 275 ms
19,616 KB
testcase_04 AC 166 ms
11,440 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 296 ms
19,616 KB
testcase_07 AC 275 ms
19,616 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1,703 ms
134,352 KB
testcase_11 RE -
testcase_12 AC 793 ms
68,704 KB
testcase_13 AC 44 ms
7,384 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, m1, m2, u, v;
    cin >> n >> m;
    m1 = n / 2, m2 = m - m1;
    ll S;
    vector<ll> edge1(m1), edge2(m2);
    vector<pair<ll,int>> b(1 << m2);
    for(int i = 0; i < m; i++){
        cin >> u >> v;
        u--, v--;
        if(i < m1) edge1[i] = (1ll << u) | (1ll << v);
        else edge2[i - m1] = (1ll << u) | (1ll << v);
    }
    S = 0;
    for(int i = 0; i < n; i++){
        cin >> v;
        if(v) S |= 1ll << i;
    }
    for(int i = 0; i < (1 << m2); i++){
        ll S = 0;
        for(int j = 0; j < m2; j++){
            if(i >> j & 1) S ^= edge2[j];
        }
        b[i] = make_pair(S, __builtin_popcount(i));
    }
    sort(b.begin(), b.end());
    auto f = [&](ll S){
        int j = lower_bound(b.begin(), b.end(), make_pair(S, -1)) - b.begin();
        if(j == b.size() || S != b[j].first) return 1 << 30;
        return b[j].second;
    };
    int ans = 1 << 30;
    for(int i = 0; i < (1 << m1); i++){
        ll T = 0;
        for(int j = 0; j < m1; j++){
            if(i >> j & 1) T ^= edge1[j];
        }
        ans = min(ans, f(S ^ T) + __builtin_popcount(i));
    }
    if(ans >> 30) ans = -1;
    cout << ans << '\n';
}
0