結果

問題 No.2236 Lights Out On Simple Graph
ユーザー umimelumimel
提出日時 2023-03-05 15:01:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,476 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 171,168 KB
実行使用メモリ 814,776 KB
最終ジャッジ日時 2023-10-18 04:53:49
合計ジャッジ時間 5,596 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 RE -
testcase_04 RE -
testcase_05 AC 2 ms
4,348 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 MLE -
testcase_11 AC 19 ms
4,348 KB
testcase_12 RE -
testcase_13 AC 48 ms
134,372 KB
testcase_14 RE -
testcase_15 AC 110 ms
265,312 KB
testcase_16 RE -
testcase_17 AC 26 ms
11,468 KB
testcase_18 AC 8 ms
19,644 KB
testcase_19 MLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
    vector<ll> dp2((1<<n), INF);
    rep(bit, (1<<m2)){
        ll bit2 = 0;
        ll cnt = 0;
        rep(i, m2){
            if((bit>>i)&1){
                bit2 = bit2 ^ (1<<a[m1+i]);
                bit2 = bit2 ^ (1<<b[m1+i]);
                cnt++;
            }
        }

        dp2[bit2] = min(dp2[bit2], cnt);
    }

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

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

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

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