結果

問題 No.2236 Lights Out On Simple Graph
ユーザー momoyuumomoyuu
提出日時 2023-10-24 15:43:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,096 ms / 4,000 ms
コード長 1,566 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 118,320 KB
実行使用メモリ 69,180 KB
最終ジャッジ日時 2023-10-24 15:43:35
合計ジャッジ時間 29,335 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 708 ms
69,180 KB
testcase_04 AC 804 ms
69,180 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 918 ms
69,180 KB
testcase_07 AC 709 ms
69,180 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 152 ms
11,836 KB
testcase_11 AC 52 ms
4,372 KB
testcase_12 AC 254 ms
11,836 KB
testcase_13 AC 17 ms
5,692 KB
testcase_14 AC 544 ms
36,412 KB
testcase_15 AC 15 ms
5,628 KB
testcase_16 AC 32 ms
7,740 KB
testcase_17 AC 65 ms
5,628 KB
testcase_18 AC 4 ms
4,372 KB
testcase_19 AC 67 ms
11,772 KB
testcase_20 AC 342 ms
36,412 KB
testcase_21 AC 72 ms
11,836 KB
testcase_22 AC 629 ms
69,180 KB
testcase_23 AC 733 ms
69,180 KB
testcase_24 AC 730 ms
69,180 KB
testcase_25 AC 142 ms
20,028 KB
testcase_26 AC 799 ms
69,180 KB
testcase_27 AC 298 ms
19,964 KB
testcase_28 AC 686 ms
69,180 KB
testcase_29 AC 64 ms
11,836 KB
testcase_30 AC 683 ms
69,180 KB
testcase_31 AC 770 ms
69,180 KB
testcase_32 AC 579 ms
69,180 KB
testcase_33 AC 711 ms
69,180 KB
testcase_34 AC 575 ms
69,180 KB
testcase_35 AC 838 ms
36,348 KB
testcase_36 AC 1,032 ms
69,116 KB
testcase_37 AC 773 ms
69,116 KB
testcase_38 AC 560 ms
7,676 KB
testcase_39 AC 618 ms
4,604 KB
testcase_40 AC 373 ms
20,028 KB
testcase_41 AC 64 ms
11,836 KB
testcase_42 AC 242 ms
11,836 KB
testcase_43 AC 16 ms
4,604 KB
testcase_44 AC 630 ms
19,964 KB
testcase_45 AC 740 ms
69,116 KB
testcase_46 AC 706 ms
69,180 KB
testcase_47 AC 539 ms
36,348 KB
testcase_48 AC 676 ms
69,180 KB
testcase_49 AC 668 ms
69,180 KB
testcase_50 AC 13 ms
4,372 KB
testcase_51 AC 158 ms
19,964 KB
testcase_52 AC 13 ms
4,372 KB
testcase_53 AC 2 ms
4,372 KB
testcase_54 AC 793 ms
69,116 KB
testcase_55 AC 740 ms
11,772 KB
testcase_56 AC 471 ms
7,676 KB
testcase_57 AC 1,096 ms
19,964 KB
testcase_58 AC 611 ms
7,676 KB
testcase_59 AC 748 ms
11,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<set>
#include<string>
#include<cstdint>
#include<map>

using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int ans = 1e9;
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> a,b;
    for(int i = 0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        pair<int,int> now = make_pair(u,v);
        if(i&1) b.push_back(now);
        else a.push_back(now);
    }
    map<ll,int> memo;
    ll mask = 0;
    for(int i = 0;i<n;i++){
        int c;
        cin>>c;
        if(c) mask |= 1ll << i;
    }

    int use = a.size();
    for(int i = 0;i<1<<use;i++){
        ll now = 0;
        for(int j = 0;j<use;j++){
            if(~i>>j&1) continue;
            now ^= 1ll << a[j].first;
            now ^= 1ll << a[j].second;
        }
        if(memo.find(now)==memo.end()) memo[now] = __builtin_popcountll(i);
        else  memo[now] = min(memo[now],__builtin_popcountll(i));
        if(now==mask) ans = min(ans,__builtin_popcountll(i));
    }
    use = b.size();
    for(int i = 0;i<1<<use;i++){
        ll now = 0;
        for(int j = 0;j<use;j++){
            if(~i>>j&1) continue;
            now ^= 1ll << b[j].first;
            now ^= 1ll << b[j].second;
        }
        ll want = now ^ mask;
        if(want==0) ans = min(ans,__builtin_popcountll(i));
        if(memo.find(want)!=memo.end()) ans = min(ans,__builtin_popcountll(i)+memo[want]);
    }
    if(ans==1e9) ans = -1;
    cout<<ans<<endl;
}
0