結果

問題 No.2236 Lights Out On Simple Graph
ユーザー asaringoasaringo
提出日時 2023-03-04 17:51:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 610 ms / 4,000 ms
コード長 2,274 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 215,808 KB
実行使用メモリ 102,044 KB
最終ジャッジ日時 2023-10-18 04:37:00
合計ジャッジ時間 21,042 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
85,592 KB
testcase_01 AC 33 ms
85,588 KB
testcase_02 AC 34 ms
85,592 KB
testcase_03 AC 435 ms
102,044 KB
testcase_04 AC 322 ms
93,852 KB
testcase_05 AC 33 ms
85,592 KB
testcase_06 AC 452 ms
102,044 KB
testcase_07 AC 456 ms
102,044 KB
testcase_08 AC 33 ms
85,588 KB
testcase_09 AC 33 ms
85,592 KB
testcase_10 AC 134 ms
89,832 KB
testcase_11 AC 93 ms
87,276 KB
testcase_12 AC 179 ms
89,832 KB
testcase_13 AC 45 ms
86,024 KB
testcase_14 AC 334 ms
93,852 KB
testcase_15 AC 42 ms
85,720 KB
testcase_16 AC 50 ms
86,024 KB
testcase_17 AC 84 ms
87,276 KB
testcase_18 AC 34 ms
85,656 KB
testcase_19 AC 67 ms
86,228 KB
testcase_20 AC 227 ms
93,852 KB
testcase_21 AC 67 ms
86,228 KB
testcase_22 AC 448 ms
102,044 KB
testcase_23 AC 432 ms
102,044 KB
testcase_24 AC 329 ms
93,852 KB
testcase_25 AC 104 ms
87,276 KB
testcase_26 AC 432 ms
102,044 KB
testcase_27 AC 224 ms
93,852 KB
testcase_28 AC 332 ms
93,852 KB
testcase_29 AC 66 ms
86,228 KB
testcase_30 AC 428 ms
102,044 KB
testcase_31 AC 432 ms
102,044 KB
testcase_32 AC 442 ms
102,044 KB
testcase_33 AC 437 ms
102,044 KB
testcase_34 AC 457 ms
102,044 KB
testcase_35 AC 422 ms
102,044 KB
testcase_36 AC 479 ms
102,044 KB
testcase_37 AC 436 ms
102,044 KB
testcase_38 AC 595 ms
102,044 KB
testcase_39 AC 610 ms
102,044 KB
testcase_40 AC 234 ms
93,852 KB
testcase_41 AC 68 ms
86,228 KB
testcase_42 AC 173 ms
89,832 KB
testcase_43 AC 44 ms
86,024 KB
testcase_44 AC 493 ms
102,044 KB
testcase_45 AC 427 ms
102,044 KB
testcase_46 AC 469 ms
102,044 KB
testcase_47 AC 478 ms
102,044 KB
testcase_48 AC 451 ms
102,044 KB
testcase_49 AC 447 ms
102,044 KB
testcase_50 AC 42 ms
85,720 KB
testcase_51 AC 136 ms
89,832 KB
testcase_52 AC 42 ms
85,720 KB
testcase_53 AC 33 ms
85,592 KB
testcase_54 AC 344 ms
93,852 KB
testcase_55 AC 542 ms
102,044 KB
testcase_56 AC 516 ms
102,044 KB
testcase_57 AC 533 ms
102,044 KB
testcase_58 AC 466 ms
102,044 KB
testcase_59 AC 485 ms
102,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
#define fast_input_output ios::sync_with_stdio(false); cin.tie(nullptr);
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define repi(it,S) for(auto it = S.begin() ; it != S.end() ; it++)
#define pt(a) cout << a << endl
#define DEBUG(...) ; cout << #__VA_ARGS__ << endl ; for(auto x : {__VA_ARGS__}) cout << x << "  " ; cout << endl ;
#define DEBUG_LIST(...) cout << #__VA_ARGS__ << endl ; DEBUG_REP(__VA_ARGS__) ;
#define DEBUG_REP(V) cout << "{ " ; repi(itr,V) cout << *itr << ", " ; cout << "}" << endl ;
#define debug(a) cout << #a << " " << a << endl
#define all(a) a.begin(), a.end()
#define endl "\n"

int n, m;

vector<int> A, B, C;
vector<bool> X[1<<20];
vector<bool> Y[1<<20];

int main(){
    fast_input_output
    cin >> n >> m;
    A.resize(m);
    B.resize(m);
    C.resize(n);
    rep(i,m) cin >> A[i] >> B[i], A[i]--, B[i]--;
    rep(i,n) cin >> C[i];
    vector<pair<ll,int>> vec;
    rep(S,1<<m/2){
        vector<int> U(n,0);
        rep(i,m/2){
            if(S >> i & 1) {
                U[A[i]] ^= 1;
                U[B[i]] ^= 1;
            }
        }
        ll res = 0;
        rep(i,n) {
            res *= 2;
            res += (U[i] ^ C[i]);
        }
        vec.push_back({res,bit_count(S)});
    }
    sort(all(vec));
    int ans = 1e8;
    rep(S,1<<(m-m/2)){
        vector<int> U(n,0);
        rep(i,m-m/2){
            if(S >> i & 1) {
                U[A[i+m/2]] ^= 1;
                U[B[i+m/2]] ^= 1;
            }
        }
        ll res = 0;
        rep(i,n) {
            res *= 2;
            res += U[i];
        }
        auto it = lower_bound(all(vec),pair<ll,int>(res,-1));
        if((*it).first == res) chmin(ans,(*it).second + bit_count(S));
    }
    if(ans == 1e8) ans = -1;
    cout << ans << endl;
}
0