結果

問題 No.2236 Lights Out On Simple Graph
ユーザー t98slidert98slider
提出日時 2023-03-04 00:34:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 448 ms / 4,000 ms
コード長 1,296 bytes
コンパイル時間 1,834 ms
コンパイル使用メモリ 176,392 KB
実行使用メモリ 19,628 KB
最終ジャッジ日時 2023-10-18 03:58:11
合計ジャッジ時間 15,185 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 296 ms
19,628 KB
testcase_04 AC 184 ms
19,628 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 309 ms
19,628 KB
testcase_07 AC 299 ms
19,628 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 77 ms
7,364 KB
testcase_11 AC 52 ms
5,320 KB
testcase_12 AC 118 ms
11,452 KB
testcase_13 AC 10 ms
4,348 KB
testcase_14 AC 236 ms
19,628 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 15 ms
4,348 KB
testcase_17 AC 42 ms
5,320 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 29 ms
5,320 KB
testcase_20 AC 146 ms
11,452 KB
testcase_21 AC 30 ms
5,320 KB
testcase_22 AC 296 ms
19,628 KB
testcase_23 AC 320 ms
19,628 KB
testcase_24 AC 275 ms
19,628 KB
testcase_25 AC 57 ms
7,364 KB
testcase_26 AC 292 ms
19,628 KB
testcase_27 AC 154 ms
11,452 KB
testcase_28 AC 242 ms
19,628 KB
testcase_29 AC 30 ms
5,320 KB
testcase_30 AC 284 ms
19,628 KB
testcase_31 AC 293 ms
19,628 KB
testcase_32 AC 286 ms
19,628 KB
testcase_33 AC 300 ms
19,628 KB
testcase_34 AC 285 ms
19,628 KB
testcase_35 AC 371 ms
19,628 KB
testcase_36 AC 377 ms
19,628 KB
testcase_37 AC 300 ms
19,628 KB
testcase_38 AC 397 ms
19,628 KB
testcase_39 AC 384 ms
19,628 KB
testcase_40 AC 165 ms
11,452 KB
testcase_41 AC 30 ms
5,320 KB
testcase_42 AC 120 ms
11,452 KB
testcase_43 AC 11 ms
4,348 KB
testcase_44 AC 355 ms
19,628 KB
testcase_45 AC 305 ms
19,628 KB
testcase_46 AC 297 ms
19,628 KB
testcase_47 AC 307 ms
19,628 KB
testcase_48 AC 314 ms
19,628 KB
testcase_49 AC 298 ms
19,628 KB
testcase_50 AC 11 ms
4,348 KB
testcase_51 AC 72 ms
7,364 KB
testcase_52 AC 9 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 272 ms
19,628 KB
testcase_55 AC 447 ms
19,628 KB
testcase_56 AC 354 ms
19,628 KB
testcase_57 AC 448 ms
19,628 KB
testcase_58 AC 356 ms
19,628 KB
testcase_59 AC 350 ms
19,628 KB
権限があれば一括ダウンロードができます

ソースコード

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 = m / 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