結果

問題 No.2236 Lights Out On Simple Graph
ユーザー prism17prism17
提出日時 2023-03-24 13:24:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,789 bytes
コンパイル時間 3,601 ms
コンパイル使用メモリ 179,700 KB
実行使用メモリ 52,708 KB
最終ジャッジ日時 2023-10-18 20:22:46
合計ジャッジ時間 27,971 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 567 ms
28,132 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 159 ms
15,844 KB
testcase_11 AC 67 ms
4,348 KB
testcase_12 AC 191 ms
15,844 KB
testcase_13 AC 17 ms
5,092 KB
testcase_14 AC 356 ms
28,132 KB
testcase_15 AC 10 ms
4,368 KB
testcase_16 AC 20 ms
5,092 KB
testcase_17 AC 86 ms
9,700 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 40 ms
6,628 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 715 ms
52,708 KB
testcase_24 AC 405 ms
28,132 KB
testcase_25 WA -
testcase_26 AC 591 ms
52,708 KB
testcase_27 AC 329 ms
28,132 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 852 ms
52,708 KB
testcase_36 AC 1,124 ms
52,708 KB
testcase_37 AC 791 ms
52,708 KB
testcase_38 AC 915 ms
15,844 KB
testcase_39 AC 598 ms
4,368 KB
testcase_40 AC 327 ms
15,844 KB
testcase_41 AC 39 ms
6,628 KB
testcase_42 AC 159 ms
9,700 KB
testcase_43 AC 15 ms
4,368 KB
testcase_44 AC 707 ms
28,132 KB
testcase_45 WA -
testcase_46 AC 502 ms
15,844 KB
testcase_47 AC 539 ms
28,132 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 12 ms
4,348 KB
testcase_51 WA -
testcase_52 AC 12 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 355 ms
15,844 KB
testcase_55 AC 678 ms
9,700 KB
testcase_56 AC 499 ms
6,628 KB
testcase_57 AC 791 ms
9,700 KB
testcase_58 AC 548 ms
6,628 KB
testcase_59 AC 579 ms
6,628 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;
int 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++) {
    int x;
    cin >> x;
    st |= x << i;
  }
  int nn = m / 2;
  map<int, int> vis;
  for (int j = 0; j < (1 << nn); j++) {
    int state = 0;
    for (int k = 0; k < nn; k++) {
      if (j & (1 << k)) {
        int x = edges[k].x, y = edges[k].y;
        state ^= (1 << x);
        state ^= (1 << 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 (int j = 0; j < (1 << rest); j++) {
    int state = 0;
    for (int k = 0; k < rest; k++) {
      if (j & (1 << k)) {
        int x = edges[nn + k].x, y = edges[nn + k].y;
        state ^= (1 << x);
        state ^= (1 << 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