結果

問題 No.2236 Lights Out On Simple Graph
ユーザー pointNpointN
提出日時 2023-03-03 22:45:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,219 ms / 4,000 ms
コード長 1,658 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 143,604 KB
実行使用メモリ 69,232 KB
最終ジャッジ日時 2023-10-18 02:57:46
合計ジャッジ時間 26,719 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 750 ms
69,232 KB
testcase_04 AC 335 ms
36,464 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 558 ms
69,232 KB
testcase_07 AC 477 ms
20,080 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 170 ms
20,080 KB
testcase_11 AC 59 ms
4,348 KB
testcase_12 AC 227 ms
20,080 KB
testcase_13 AC 19 ms
5,744 KB
testcase_14 AC 384 ms
36,464 KB
testcase_15 AC 11 ms
4,720 KB
testcase_16 AC 20 ms
5,744 KB
testcase_17 AC 96 ms
11,888 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 42 ms
7,792 KB
testcase_20 AC 349 ms
36,464 KB
testcase_21 AC 46 ms
7,792 KB
testcase_22 AC 697 ms
69,232 KB
testcase_23 AC 810 ms
69,232 KB
testcase_24 AC 456 ms
36,464 KB
testcase_25 AC 83 ms
11,888 KB
testcase_26 AC 691 ms
69,232 KB
testcase_27 AC 373 ms
36,464 KB
testcase_28 AC 403 ms
36,464 KB
testcase_29 AC 46 ms
7,792 KB
testcase_30 AC 706 ms
69,232 KB
testcase_31 AC 766 ms
69,232 KB
testcase_32 AC 588 ms
69,232 KB
testcase_33 AC 752 ms
69,232 KB
testcase_34 AC 720 ms
69,232 KB
testcase_35 AC 891 ms
69,232 KB
testcase_36 AC 1,219 ms
69,232 KB
testcase_37 AC 863 ms
69,232 KB
testcase_38 AC 952 ms
20,080 KB
testcase_39 AC 545 ms
4,720 KB
testcase_40 AC 347 ms
20,080 KB
testcase_41 AC 44 ms
7,792 KB
testcase_42 AC 159 ms
11,888 KB
testcase_43 AC 14 ms
4,720 KB
testcase_44 AC 770 ms
36,464 KB
testcase_45 AC 697 ms
36,464 KB
testcase_46 AC 504 ms
36,464 KB
testcase_47 AC 550 ms
36,464 KB
testcase_48 AC 746 ms
69,232 KB
testcase_49 AC 463 ms
20,080 KB
testcase_50 AC 11 ms
4,348 KB
testcase_51 AC 121 ms
7,792 KB
testcase_52 AC 11 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 371 ms
20,080 KB
testcase_55 AC 675 ms
11,888 KB
testcase_56 AC 454 ms
7,792 KB
testcase_57 AC 813 ms
11,888 KB
testcase_58 AC 473 ms
7,792 KB
testcase_59 AC 525 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N,M; cin >> N >> M;
  vector<pair<int,int>> E(M);
  rep(i,M){
    int a,b; cin >> a >> b; a--; b--;
    E[i] = {a,b};
  }
  int m1 = M/2;
  int m2 = M-m1;
  vector<int> C(N);
  rep(i,N) cin >> C[i];
  ll x = 0;
  rep(i,N) x += (1LL<<i)*C[i];
  map<ll,int> mp1;
  rep(i,1<<m1){
    ll v = 0;
    rep(j,m1){
      if(i&(1<<j)){
        v ^= (1LL<<E[j].first) + (1LL<<E[j].second);
      }
    }
    if(mp1.count(v)){
      chmin(mp1[v],__builtin_popcount(i));
    }
    else mp1[v] = __builtin_popcount(i);
  }
  int ans = 1<<30;
  rep(i,1<<m2){
    ll v = 0;
    rep(j,m2){
      if(i&(1<<j)){
        v ^= (1LL<<E[m1+j].first) + (1LL<<E[m1+j].second);
      }
    }
    if(mp1.count(v^x)){
      chmin(ans,mp1[v^x]+__builtin_popcount(i));
    }
  }
  if(ans==1<<30) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

0