結果

問題 No.2236 Lights Out On Simple Graph
ユーザー RubikunRubikun
提出日時 2023-03-03 21:46:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,233 ms / 4,000 ms
コード長 1,570 bytes
コンパイル時間 3,195 ms
コンパイル使用メモリ 212,856 KB
実行使用メモリ 69,160 KB
最終ジャッジ日時 2023-10-18 01:43:50
合計ジャッジ時間 28,264 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 AC 751 ms
69,160 KB
testcase_04 AC 356 ms
36,392 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 569 ms
69,160 KB
testcase_07 AC 472 ms
20,008 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 175 ms
20,008 KB
testcase_11 AC 61 ms
4,348 KB
testcase_12 AC 211 ms
20,008 KB
testcase_13 AC 19 ms
5,672 KB
testcase_14 AC 413 ms
36,392 KB
testcase_15 AC 11 ms
4,588 KB
testcase_16 AC 21 ms
5,672 KB
testcase_17 AC 98 ms
11,756 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 44 ms
7,660 KB
testcase_20 AC 347 ms
36,392 KB
testcase_21 AC 47 ms
7,720 KB
testcase_22 AC 710 ms
69,160 KB
testcase_23 AC 849 ms
69,160 KB
testcase_24 AC 475 ms
36,392 KB
testcase_25 AC 89 ms
11,816 KB
testcase_26 AC 687 ms
69,160 KB
testcase_27 AC 377 ms
36,332 KB
testcase_28 AC 420 ms
36,392 KB
testcase_29 AC 45 ms
7,720 KB
testcase_30 AC 722 ms
69,160 KB
testcase_31 AC 778 ms
69,160 KB
testcase_32 AC 607 ms
69,160 KB
testcase_33 AC 752 ms
69,160 KB
testcase_34 AC 731 ms
69,160 KB
testcase_35 AC 913 ms
69,100 KB
testcase_36 AC 1,233 ms
69,100 KB
testcase_37 AC 876 ms
69,100 KB
testcase_38 AC 960 ms
19,948 KB
testcase_39 AC 560 ms
4,588 KB
testcase_40 AC 350 ms
20,008 KB
testcase_41 AC 44 ms
7,720 KB
testcase_42 AC 167 ms
11,816 KB
testcase_43 AC 15 ms
4,588 KB
testcase_44 AC 789 ms
36,332 KB
testcase_45 AC 699 ms
36,332 KB
testcase_46 AC 504 ms
36,392 KB
testcase_47 AC 565 ms
36,332 KB
testcase_48 AC 742 ms
69,160 KB
testcase_49 AC 467 ms
20,008 KB
testcase_50 AC 12 ms
4,348 KB
testcase_51 AC 120 ms
7,660 KB
testcase_52 AC 13 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 381 ms
19,948 KB
testcase_55 AC 676 ms
11,756 KB
testcase_56 AC 467 ms
7,660 KB
testcase_57 AC 792 ms
11,756 KB
testcase_58 AC 492 ms
7,660 KB
testcase_59 AC 546 ms
7,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    vector<pair<int,int>> E(M);
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;a--;b--;
        E[i]=mp(a,b);
    }
    
    ll tar=0;
    int ans=INF;
    
    for(int i=0;i<N;i++){
        int c;cin>>c;
        if(c) tar|=(1LL<<i);
    }
    
    map<ll,int> MA;
    int K=M/2;
    for(int bi=0;bi<(1<<K);bi++){
        ll now=0;
        for(int i=0;i<K;i++){
            if(bi&(1<<i)){
                now^=(1LL<<E[i].fi);
                now^=(1LL<<E[i].se);
            }
        }
        if(!MA.count(now)) MA[now]=__builtin_popcount(bi);
        else chmin(MA[now],__builtin_popcount(bi));
    }
    
    for(int bi=0;bi<(1<<(M-K));bi++){
        ll now=tar;
        for(int i=0;i<M-K;i++){
            if(bi&(1<<i)){
                now^=(1LL<<E[K+i].fi);
                now^=(1LL<<E[K+i].se);
            }
        }
        if(MA.count(now)) chmin(ans,MA[now]+__builtin_popcount(bi));
        
    }
    
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
}
0