結果

問題 No.2236 Lights Out On Simple Graph
ユーザー milanis48663220milanis48663220
提出日時 2023-03-03 22:35:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,217 ms / 4,000 ms
コード長 2,450 bytes
コンパイル時間 2,507 ms
コンパイル使用メモリ 126,192 KB
実行使用メモリ 47,216 KB
最終ジャッジ日時 2023-10-18 02:44:22
合計ジャッジ時間 28,705 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 AC 954 ms
47,216 KB
testcase_04 AC 526 ms
25,160 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 728 ms
47,216 KB
testcase_07 AC 541 ms
14,128 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 178 ms
14,128 KB
testcase_11 AC 27 ms
4,348 KB
testcase_12 AC 256 ms
14,128 KB
testcase_13 AC 13 ms
4,640 KB
testcase_14 AC 584 ms
25,160 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 17 ms
4,640 KB
testcase_17 AC 59 ms
8,676 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 35 ms
5,848 KB
testcase_20 AC 434 ms
25,160 KB
testcase_21 AC 35 ms
5,848 KB
testcase_22 AC 992 ms
47,216 KB
testcase_23 AC 1,010 ms
47,216 KB
testcase_24 AC 609 ms
25,160 KB
testcase_25 AC 101 ms
8,676 KB
testcase_26 AC 1,001 ms
47,216 KB
testcase_27 AC 441 ms
25,160 KB
testcase_28 AC 597 ms
25,160 KB
testcase_29 AC 37 ms
5,848 KB
testcase_30 AC 935 ms
47,216 KB
testcase_31 AC 959 ms
47,216 KB
testcase_32 AC 976 ms
47,216 KB
testcase_33 AC 972 ms
47,216 KB
testcase_34 AC 936 ms
47,216 KB
testcase_35 AC 1,217 ms
47,216 KB
testcase_36 AC 787 ms
47,216 KB
testcase_37 AC 1,068 ms
47,216 KB
testcase_38 AC 367 ms
14,128 KB
testcase_39 AC 217 ms
4,348 KB
testcase_40 AC 265 ms
14,128 KB
testcase_41 AC 36 ms
5,848 KB
testcase_42 AC 137 ms
8,676 KB
testcase_43 AC 10 ms
4,348 KB
testcase_44 AC 737 ms
25,160 KB
testcase_45 AC 724 ms
25,160 KB
testcase_46 AC 694 ms
25,160 KB
testcase_47 AC 622 ms
25,160 KB
testcase_48 AC 971 ms
47,216 KB
testcase_49 AC 488 ms
14,128 KB
testcase_50 AC 6 ms
4,348 KB
testcase_51 AC 72 ms
5,848 KB
testcase_52 AC 7 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 397 ms
14,128 KB
testcase_55 AC 286 ms
8,676 KB
testcase_56 AC 259 ms
5,848 KB
testcase_57 AC 343 ms
8,676 KB
testcase_58 AC 249 ms
5,848 KB
testcase_59 AC 238 ms
5,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<int> a(m), b(m);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i]; a[i]--; b[i]--;
    }
    ll s = 0;
    for(int i = 0; i < n; i++){
        int c; cin >> c;
        if(c == 1) s += 1ll<<i;
    }
    int k = m/2;
    unordered_map<ll, int> mp;
    for(int s = 0; s < (1<<k); s++){
        ll x = 0;
        int cnt = 0;
        for(int i = 0; i < k; i++){
            if(s&(1<<i)){
                x ^= 1ll<<a[i];
                x ^= 1ll<<b[i];
                cnt++;
            }
        }
        if(mp.count(x)) chmin(mp[x], cnt);
        else mp[x] = cnt;
    }
    // for(auto [s, cnt]: mp) cout << s << ':' << cnt << endl;
    int kk = m-k;
    ll target = s;
    int ans = 100000;
    for(int s = 0; s < (1<<kk); s++){
        ll x = 0;
        int cnt = 0;
        for(int i = 0; i < kk; i++){
            if(s&(1<<i)){
                x ^= 1ll<<a[i+k];
                x ^= 1ll<<b[i+k];
                cnt++;
            }
        }
        ll y = x^target;
        if(mp.count(y)){
            chmin(ans, cnt+mp[y]);
        }
    }
    if(ans == 100000) cout << -1 << endl;
    else cout << ans << endl;
}
0