結果

問題 No.2236 Lights Out On Simple Graph
ユーザー prism17prism17
提出日時 2023-03-24 13:30:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,178 ms / 4,000 ms
コード長 1,798 bytes
コンパイル時間 3,261 ms
コンパイル使用メモリ 179,912 KB
実行使用メモリ 69,132 KB
最終ジャッジ日時 2023-10-18 20:24:29
合計ジャッジ時間 28,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 723 ms
69,132 KB
testcase_04 AC 342 ms
36,364 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 561 ms
69,132 KB
testcase_07 AC 521 ms
19,980 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 172 ms
19,980 KB
testcase_11 AC 68 ms
4,348 KB
testcase_12 AC 215 ms
19,980 KB
testcase_13 AC 19 ms
5,644 KB
testcase_14 AC 409 ms
36,364 KB
testcase_15 AC 11 ms
4,620 KB
testcase_16 AC 20 ms
5,644 KB
testcase_17 AC 97 ms
11,788 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 42 ms
7,692 KB
testcase_20 AC 346 ms
36,364 KB
testcase_21 AC 46 ms
7,692 KB
testcase_22 AC 685 ms
69,132 KB
testcase_23 AC 817 ms
69,132 KB
testcase_24 AC 468 ms
36,364 KB
testcase_25 AC 90 ms
11,788 KB
testcase_26 AC 701 ms
69,132 KB
testcase_27 AC 364 ms
36,364 KB
testcase_28 AC 414 ms
36,364 KB
testcase_29 AC 44 ms
7,692 KB
testcase_30 AC 711 ms
69,132 KB
testcase_31 AC 740 ms
69,132 KB
testcase_32 AC 609 ms
69,132 KB
testcase_33 AC 720 ms
69,132 KB
testcase_34 AC 708 ms
69,132 KB
testcase_35 AC 864 ms
69,132 KB
testcase_36 AC 1,178 ms
69,132 KB
testcase_37 AC 843 ms
69,132 KB
testcase_38 AC 994 ms
19,980 KB
testcase_39 AC 626 ms
4,620 KB
testcase_40 AC 366 ms
19,980 KB
testcase_41 AC 42 ms
7,692 KB
testcase_42 AC 175 ms
11,788 KB
testcase_43 AC 16 ms
4,620 KB
testcase_44 AC 798 ms
36,364 KB
testcase_45 AC 704 ms
36,364 KB
testcase_46 AC 541 ms
36,364 KB
testcase_47 AC 602 ms
36,364 KB
testcase_48 AC 735 ms
69,132 KB
testcase_49 AC 503 ms
19,980 KB
testcase_50 AC 12 ms
4,348 KB
testcase_51 AC 136 ms
7,692 KB
testcase_52 AC 13 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 400 ms
19,980 KB
testcase_55 AC 744 ms
11,788 KB
testcase_56 AC 536 ms
7,692 KB
testcase_57 AC 886 ms
11,788 KB
testcase_58 AC 556 ms
7,692 KB
testcase_59 AC 617 ms
7,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2236 Lights Out On Simple GraphNo.2236 熄灯简图
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2236
// Memory Limit: 512 MB
// Time Limit: 4000 ms

#include <bits/stdc++.h>

#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define dbg(x) cout << #x << " = " << (x) << "\n";
#define popcount(x) __builtin_popcountll((x))
#define all(v) (v).begin(), (v).end()
#define pb emplace_back
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m;
ll st;

void solve() {
  cin >> n >> m;
  vector<pll> edges(m);
  for (auto &e : edges) {
    cin >> e.x >> e.y;
    e.x--, e.y--;
  }
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    st |= x << i;
  }
  int nn = m / 2;
  map<ll, int> vis;
  for (ll j = 0; j < (1ll << nn); j++) {
    ll state = 0;
    for (int k = 0; k < nn; k++) {
      if (j & (1ll << k)) {
        int x = edges[k].x, y = edges[k].y;
        state ^= (1ll << x);
        state ^= (1ll << y);
      }
    }
    if (vis.count(state))
      vis[state] = min(vis[state], popcount(j));
    else
      vis[state] = popcount(j);
  }
  int rest = m - nn;
  int ans = -1;
  for (ll j = 0; j < (1ll << rest); j++) {
    ll state = 0;
    for (int k = 0; k < rest; k++) {
      if (j & (1ll << k)) {
        int x = edges[nn + k].x, y = edges[nn + k].y;
        state ^= (1ll << x);
        state ^= (1ll << y);
      }
    }
    if (vis.count(state ^ st)) {
      if (ans == -1)
        ans = vis[state ^ st] + popcount(j);
      else
        ans = min(vis[state ^ st] + popcount(j), ans);
    }
  }
  cout << ans << "\n";
}

int main() {
  fastio;
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
0