結果

問題 No.2236 Lights Out On Simple Graph
ユーザー umimelumimel
提出日時 2023-03-05 15:18:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 845 ms / 4,000 ms
コード長 1,586 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 179,640 KB
実行使用メモリ 69,164 KB
最終ジャッジ日時 2023-10-18 04:54:44
合計ジャッジ時間 26,872 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 689 ms
69,164 KB
testcase_04 AC 477 ms
69,164 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 505 ms
69,164 KB
testcase_07 AC 749 ms
69,164 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 152 ms
11,820 KB
testcase_11 AC 65 ms
4,348 KB
testcase_12 AC 283 ms
20,012 KB
testcase_13 AC 19 ms
5,676 KB
testcase_14 AC 639 ms
36,396 KB
testcase_15 AC 16 ms
5,676 KB
testcase_16 AC 31 ms
7,724 KB
testcase_17 AC 85 ms
7,724 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 72 ms
11,820 KB
testcase_20 AC 335 ms
36,396 KB
testcase_21 AC 68 ms
11,820 KB
testcase_22 AC 630 ms
69,164 KB
testcase_23 AC 845 ms
69,164 KB
testcase_24 AC 586 ms
36,396 KB
testcase_25 AC 131 ms
20,012 KB
testcase_26 AC 717 ms
69,164 KB
testcase_27 AC 370 ms
36,396 KB
testcase_28 AC 714 ms
69,164 KB
testcase_29 AC 62 ms
11,820 KB
testcase_30 AC 656 ms
69,164 KB
testcase_31 AC 632 ms
69,164 KB
testcase_32 AC 689 ms
69,164 KB
testcase_33 AC 694 ms
69,164 KB
testcase_34 AC 573 ms
69,164 KB
testcase_35 AC 817 ms
36,396 KB
testcase_36 AC 556 ms
7,724 KB
testcase_37 AC 764 ms
69,164 KB
testcase_38 AC 676 ms
7,724 KB
testcase_39 AC 494 ms
4,348 KB
testcase_40 AC 306 ms
11,820 KB
testcase_41 AC 68 ms
7,724 KB
testcase_42 AC 316 ms
36,396 KB
testcase_43 AC 16 ms
4,652 KB
testcase_44 AC 649 ms
20,012 KB
testcase_45 AC 737 ms
69,164 KB
testcase_46 AC 615 ms
36,396 KB
testcase_47 AC 763 ms
69,164 KB
testcase_48 AC 574 ms
20,012 KB
testcase_49 AC 759 ms
69,164 KB
testcase_50 AC 12 ms
4,348 KB
testcase_51 AC 167 ms
20,012 KB
testcase_52 AC 13 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 543 ms
20,012 KB
testcase_55 AC 564 ms
7,724 KB
testcase_56 AC 578 ms
7,724 KB
testcase_57 AC 767 ms
11,820 KB
testcase_58 AC 435 ms
4,652 KB
testcase_59 AC 471 ms
4,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, m; cin >> n >> m;
    vector<ll> a(m), b(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    vector<ll> c(n); rep(i, n) cin >> c[i];

    ll m1 = m/2, m2 = m - m1;
    map<ll, ll> dp2;
    rep(bit, (1LL<<m2)){
        ll bit2 = 0;
        ll cnt = 0;
        rep(i, m2){
            if((bit>>i)&1){
                bit2 = bit2 ^ (1LL<<a[m1+i]);
                bit2 = bit2 ^ (1LL<<b[m1+i]);
                cnt++;
            }
        }

        if(dp2.find(bit2)!=dp2.end()){
            dp2[bit2] = min(dp2[bit2], cnt);
        }else{
            dp2[bit2] = cnt;
        }
    }

    ll T = 0;
    for(ll i=n-1; i>=0; i--) T = 2*T + c[i];

    ll ans = INF;
    rep(bit, (1LL<<m1)){
        ll bit1 = 0;
        ll cnt = 0;
        rep(i, m1){
            if((bit>>i)&1){
                bit1 = bit1 ^ (1LL<<a[i]);
                bit1 = bit1 ^ (1LL<<b[i]);
                cnt++;
            }
        }

        if(dp2.find(bit1 ^ T) != dp2.end()){
            ans = min(ans, cnt+dp2[bit1 ^ T]);
        }
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}
0