結果

問題 No.2236 Lights Out On Simple Graph
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-03-02 13:28:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,359 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 123,816 KB
実行使用メモリ 85,208 KB
最終ジャッジ日時 2023-10-17 10:40:07
合計ジャッジ時間 25,995 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 633 ms
85,208 KB
testcase_04 AC 419 ms
77,020 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 450 ms
85,208 KB
testcase_07 AC 681 ms
85,208 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 18 ms
5,900 KB
testcase_14 AC 454 ms
44,284 KB
testcase_15 AC 14 ms
5,668 KB
testcase_16 AC 27 ms
8,012 KB
testcase_17 WA -
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 62 ms
12,492 KB
testcase_20 AC 305 ms
44,284 KB
testcase_21 AC 59 ms
12,492 KB
testcase_22 AC 593 ms
85,208 KB
testcase_23 AC 763 ms
85,208 KB
testcase_24 WA -
testcase_25 AC 117 ms
21,716 KB
testcase_26 AC 645 ms
85,208 KB
testcase_27 AC 331 ms
44,284 KB
testcase_28 AC 595 ms
77,020 KB
testcase_29 AC 56 ms
12,492 KB
testcase_30 AC 608 ms
85,208 KB
testcase_31 AC 623 ms
85,208 KB
testcase_32 AC 641 ms
85,208 KB
testcase_33 AC 1,095 ms
85,208 KB
testcase_34 AC 578 ms
85,208 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 685 ms
85,208 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 235 ms
19,732 KB
testcase_41 AC 50 ms
8,532 KB
testcase_42 AC 282 ms
40,188 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 657 ms
85,208 KB
testcase_46 AC 471 ms
52,472 KB
testcase_47 AC 704 ms
85,208 KB
testcase_48 AC 443 ms
36,104 KB
testcase_49 AC 675 ms
85,208 KB
testcase_50 WA -
testcase_51 AC 159 ms
23,820 KB
testcase_52 WA -
testcase_53 AC 2 ms
4,348 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
            }   
        }
        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