結果

問題 No.2236 Lights Out On Simple Graph
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-12-25 17:10:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 870 ms / 4,000 ms
コード長 1,261 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 216,780 KB
実行使用メモリ 63,828 KB
最終ジャッジ日時 2023-12-25 17:10:34
合計ジャッジ時間 26,864 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 865 ms
63,828 KB
testcase_04 AC 577 ms
55,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 655 ms
63,828 KB
testcase_07 AC 791 ms
63,828 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 100 ms
12,920 KB
testcase_11 AC 33 ms
6,676 KB
testcase_12 AC 220 ms
18,424 KB
testcase_13 AC 14 ms
6,676 KB
testcase_14 AC 487 ms
33,464 KB
testcase_15 AC 11 ms
6,676 KB
testcase_16 AC 22 ms
6,676 KB
testcase_17 AC 47 ms
8,140 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 53 ms
9,852 KB
testcase_20 AC 363 ms
33,464 KB
testcase_21 AC 47 ms
9,852 KB
testcase_22 AC 870 ms
63,828 KB
testcase_23 AC 828 ms
63,828 KB
testcase_24 AC 575 ms
33,464 KB
testcase_25 AC 123 ms
16,292 KB
testcase_26 AC 831 ms
63,828 KB
testcase_27 AC 415 ms
33,464 KB
testcase_28 AC 700 ms
55,676 KB
testcase_29 AC 48 ms
9,852 KB
testcase_30 AC 848 ms
63,828 KB
testcase_31 AC 858 ms
63,828 KB
testcase_32 AC 843 ms
63,828 KB
testcase_33 AC 860 ms
63,828 KB
testcase_34 AC 848 ms
63,828 KB
testcase_35 AC 569 ms
41,628 KB
testcase_36 AC 300 ms
22,400 KB
testcase_37 AC 854 ms
63,828 KB
testcase_38 AC 275 ms
22,400 KB
testcase_39 AC 248 ms
20,484 KB
testcase_40 AC 215 ms
17,020 KB
testcase_41 AC 36 ms
7,116 KB
testcase_42 AC 320 ms
29,416 KB
testcase_43 AC 12 ms
6,676 KB
testcase_44 AC 430 ms
30,720 KB
testcase_45 AC 862 ms
63,828 KB
testcase_46 AC 651 ms
41,628 KB
testcase_47 AC 773 ms
63,828 KB
testcase_48 AC 435 ms
30,720 KB
testcase_49 AC 855 ms
63,828 KB
testcase_50 AC 8 ms
6,676 KB
testcase_51 AC 143 ms
18,424 KB
testcase_52 AC 8 ms
6,676 KB
testcase_53 AC 2 ms
6,676 KB
testcase_54 AC 395 ms
22,524 KB
testcase_55 AC 300 ms
22,400 KB
testcase_56 AC 287 ms
22,400 KB
testcase_57 AC 326 ms
25,216 KB
testcase_58 AC 257 ms
20,484 KB
testcase_59 AC 270 ms
20,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){

    ll N, M, m, a, b, vtx, ans=1e9, c=0, mx;
    cin >> N >> M;
    m = M/2;
    vector<pair<ll, ll>> e(M);
    for (int i=0; i<M; i++){
        cin >> a >> b; a--; b--;
        e[i] = {a, b};
    }

    for (int i=0; i<N; i++){
        cin >> a;
        c |= a*(1LL<<i);
    }

    vector<pair<ll, ll>> v;
    unordered_map<ll, ll> mp;

    mx = 1<<m;
    for (int i=0; i<mx; i++){
        vtx = 0;
        for (int j=0; j<m; j++){
            if (i & (1<<j)){
                tie(a, b) = e[j];
                vtx ^= (1LL<<a); vtx ^= (1LL<<b);
            }
        }
        v.push_back({vtx, __builtin_popcount(i)});
    }

    mx = 1<<(M-m);
    for (int i=0; i<mx; i++){
        vtx = 0;
        for (int j=0; j<(M-m); j++){
            if (i & (1<<j)){
                tie(a, b) = e[m+j];
                vtx ^= (1LL<<a); vtx ^= (1LL<<b);
            }   
        }
        if (mp.count(vtx)) mp[vtx] = min(mp[vtx], (ll)__builtin_popcount(i));
        else mp[vtx] = __builtin_popcount(i);
    }

    for (auto [vtx, cnt] : v){
        if (mp.count(vtx ^ c)) ans = min(ans, cnt+mp[vtx ^ c]);
    }

    if (ans == 1e9) ans = -1;
    cout << ans << endl;

    return 0;
}

0