結果

問題 No.2236 Lights Out On Simple Graph
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-08-27 00:26:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 850 ms / 4,000 ms
コード長 1,251 bytes
コンパイル時間 2,463 ms
コンパイル使用メモリ 213,708 KB
実行使用メモリ 85,204 KB
最終ジャッジ日時 2023-08-27 00:26:38
合計ジャッジ時間 30,049 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 700 ms
84,976 KB
testcase_04 AC 533 ms
76,868 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 517 ms
85,204 KB
testcase_07 AC 803 ms
85,124 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 168 ms
15,352 KB
testcase_11 AC 70 ms
5,072 KB
testcase_12 AC 275 ms
23,800 KB
testcase_13 AC 19 ms
5,616 KB
testcase_14 AC 620 ms
44,008 KB
testcase_15 AC 16 ms
5,416 KB
testcase_16 AC 30 ms
7,880 KB
testcase_17 AC 88 ms
9,072 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 69 ms
12,232 KB
testcase_20 AC 339 ms
44,240 KB
testcase_21 AC 62 ms
12,300 KB
testcase_22 AC 676 ms
84,992 KB
testcase_23 AC 850 ms
84,944 KB
testcase_24 AC 602 ms
44,148 KB
testcase_25 AC 133 ms
21,460 KB
testcase_26 AC 749 ms
85,076 KB
testcase_27 AC 387 ms
44,204 KB
testcase_28 AC 742 ms
76,656 KB
testcase_29 AC 62 ms
12,252 KB
testcase_30 AC 682 ms
85,012 KB
testcase_31 AC 660 ms
85,068 KB
testcase_32 AC 734 ms
84,844 KB
testcase_33 AC 763 ms
84,812 KB
testcase_34 AC 615 ms
85,012 KB
testcase_35 AC 829 ms
52,288 KB
testcase_36 AC 567 ms
23,760 KB
testcase_37 AC 770 ms
84,888 KB
testcase_38 AC 723 ms
23,432 KB
testcase_39 AC 541 ms
20,360 KB
testcase_40 AC 315 ms
19,396 KB
testcase_41 AC 67 ms
8,028 KB
testcase_42 AC 345 ms
40,072 KB
testcase_43 AC 17 ms
4,564 KB
testcase_44 AC 665 ms
35,796 KB
testcase_45 AC 770 ms
84,756 KB
testcase_46 AC 604 ms
52,400 KB
testcase_47 AC 811 ms
84,984 KB
testcase_48 AC 619 ms
35,680 KB
testcase_49 AC 785 ms
85,060 KB
testcase_50 AC 13 ms
4,376 KB
testcase_51 AC 176 ms
23,440 KB
testcase_52 AC 14 ms
4,376 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 555 ms
27,508 KB
testcase_55 AC 603 ms
23,532 KB
testcase_56 AC 630 ms
23,480 KB
testcase_57 AC 832 ms
27,516 KB
testcase_58 AC 484 ms
20,356 KB
testcase_59 AC 508 ms
20,544 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;
    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