結果

問題 No.2236 Lights Out On Simple Graph
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-02-23 22:45:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 835 ms / 4,000 ms
コード長 1,442 bytes
コンパイル時間 1,300 ms
コンパイル使用メモリ 124,468 KB
実行使用メモリ 85,228 KB
最終ジャッジ日時 2023-10-17 18:44:50
合計ジャッジ時間 26,954 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 694 ms
85,228 KB
testcase_04 AC 486 ms
77,040 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 507 ms
85,228 KB
testcase_07 AC 783 ms
85,228 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 153 ms
15,656 KB
testcase_11 AC 72 ms
5,384 KB
testcase_12 AC 274 ms
23,840 KB
testcase_13 AC 20 ms
5,920 KB
testcase_14 AC 593 ms
44,304 KB
testcase_15 AC 17 ms
5,680 KB
testcase_16 AC 30 ms
8,032 KB
testcase_17 AC 88 ms
9,328 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 70 ms
12,512 KB
testcase_20 AC 334 ms
44,304 KB
testcase_21 AC 66 ms
12,512 KB
testcase_22 AC 642 ms
85,228 KB
testcase_23 AC 835 ms
85,228 KB
testcase_24 AC 551 ms
44,304 KB
testcase_25 AC 134 ms
21,736 KB
testcase_26 AC 716 ms
85,228 KB
testcase_27 AC 369 ms
44,304 KB
testcase_28 AC 694 ms
77,040 KB
testcase_29 AC 65 ms
12,512 KB
testcase_30 AC 653 ms
85,228 KB
testcase_31 AC 658 ms
85,228 KB
testcase_32 AC 706 ms
85,228 KB
testcase_33 AC 695 ms
85,228 KB
testcase_34 AC 585 ms
85,228 KB
testcase_35 AC 803 ms
52,492 KB
testcase_36 AC 561 ms
23,716 KB
testcase_37 AC 752 ms
85,228 KB
testcase_38 AC 679 ms
23,716 KB
testcase_39 AC 528 ms
20,284 KB
testcase_40 AC 301 ms
19,752 KB
testcase_41 AC 68 ms
8,552 KB
testcase_42 AC 322 ms
40,208 KB
testcase_43 AC 17 ms
4,864 KB
testcase_44 AC 655 ms
36,124 KB
testcase_45 AC 755 ms
85,228 KB
testcase_46 AC 594 ms
52,492 KB
testcase_47 AC 781 ms
85,228 KB
testcase_48 AC 572 ms
36,124 KB
testcase_49 AC 776 ms
85,228 KB
testcase_50 AC 13 ms
4,348 KB
testcase_51 AC 178 ms
23,840 KB
testcase_52 AC 14 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 519 ms
27,936 KB
testcase_55 AC 572 ms
23,716 KB
testcase_56 AC 580 ms
23,716 KB
testcase_57 AC 792 ms
27,940 KB
testcase_58 AC 451 ms
20,812 KB
testcase_59 AC 488 ms
20,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

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