結果

問題 No.2236 Lights Out On Simple Graph
ユーザー Nzt3Nzt3
提出日時 2023-03-05 03:03:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,577 ms / 4,000 ms
コード長 1,235 bytes
コンパイル時間 3,110 ms
コンパイル使用メモリ 216,508 KB
実行使用メモリ 47,220 KB
最終ジャッジ日時 2023-10-18 04:47:19
合計ジャッジ時間 53,327 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1,444 ms
47,220 KB
testcase_04 AC 791 ms
47,220 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1,082 ms
47,220 KB
testcase_07 AC 937 ms
14,132 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 873 ms
47,220 KB
testcase_11 AC 238 ms
4,348 KB
testcase_12 AC 886 ms
47,220 KB
testcase_13 AC 811 ms
47,220 KB
testcase_14 AC 1,037 ms
47,220 KB
testcase_15 AC 818 ms
47,220 KB
testcase_16 AC 789 ms
47,220 KB
testcase_17 AC 485 ms
25,164 KB
testcase_18 AC 649 ms
47,220 KB
testcase_19 AC 752 ms
47,220 KB
testcase_20 AC 944 ms
47,220 KB
testcase_21 AC 810 ms
47,220 KB
testcase_22 AC 1,443 ms
47,220 KB
testcase_23 AC 1,437 ms
47,220 KB
testcase_24 AC 1,098 ms
47,220 KB
testcase_25 AC 800 ms
47,220 KB
testcase_26 AC 1,406 ms
47,220 KB
testcase_27 AC 906 ms
47,220 KB
testcase_28 AC 1,128 ms
47,220 KB
testcase_29 AC 810 ms
47,220 KB
testcase_30 AC 1,413 ms
47,220 KB
testcase_31 AC 1,428 ms
47,220 KB
testcase_32 AC 1,427 ms
47,220 KB
testcase_33 AC 1,438 ms
47,220 KB
testcase_34 AC 1,432 ms
47,220 KB
testcase_35 AC 1,577 ms
47,220 KB
testcase_36 AC 1,103 ms
47,220 KB
testcase_37 AC 1,406 ms
47,220 KB
testcase_38 AC 785 ms
14,132 KB
testcase_39 AC 458 ms
4,348 KB
testcase_40 AC 661 ms
25,164 KB
testcase_41 AC 480 ms
14,132 KB
testcase_42 AC 514 ms
25,164 KB
testcase_43 AC 325 ms
8,680 KB
testcase_44 AC 1,181 ms
25,164 KB
testcase_45 AC 1,156 ms
25,164 KB
testcase_46 AC 1,168 ms
25,164 KB
testcase_47 AC 1,067 ms
25,164 KB
testcase_48 AC 1,400 ms
47,220 KB
testcase_49 AC 944 ms
14,132 KB
testcase_50 AC 225 ms
4,348 KB
testcase_51 AC 424 ms
14,132 KB
testcase_52 AC 267 ms
8,680 KB
testcase_53 AC 3 ms
4,348 KB
testcase_54 AC 725 ms
25,164 KB
testcase_55 AC 655 ms
8,680 KB
testcase_56 AC 614 ms
5,856 KB
testcase_57 AC 723 ms
8,680 KB
testcase_58 AC 534 ms
5,856 KB
testcase_59 AC 538 ms
5,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<array<int,2>>E1,E2;
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    if(E1.size()>=20)E2.push_back({a-1,b-1});
    else E1.push_back({a-1,b-1});
  }
  vector<int>C(N);
  for(int &i:C)cin>>i;
  unordered_map<long long,int>ans;
  for(int i=0;i<1<<E1.size();i++){
    vector<int>c2=C;
    for(int j=0;j<E1.size();j++){
      if(i>>j&1){
        c2[E1[j][0]]=1-c2[E1[j][0]];
        c2[E1[j][1]]=1-c2[E1[j][1]];
      }
    }
    long long t=0;
    for(int j=0;j<N;j++){
      if(c2[j])t|=(1ll<<j);
    }
    if(ans.find(t)==ans.end()){
      ans[t]=__popcount(i);
    }else{
      ans[t]=min(ans[t],__builtin_popcount(i));
    }
  }
  int out=1e9;
  if(ans.find(0)!=ans.end())out=ans[0];
  for(int i=0;i<1<<E2.size();i++){
    vector<int>c2(N);
    for(int j=0;j<E2.size();j++){
      if(i>>j&1){
        c2[E2[j][0]]=1-c2[E2[j][0]];
        c2[E2[j][1]]=1-c2[E2[j][1]];
      }
    }
    long long t=0;
    for(int j=0;j<N;j++){
      if(c2[j])t|=(1ll<<j);
    }
    if(ans.find(t)!=ans.end()){
      out=min(out,ans[t]+__builtin_popcount(i));
    }
  }
  cout<<(out==1e9?-1:out)<<'\n';
}
0