結果
問題 | No.2236 Lights Out On Simple Graph |
ユーザー | 👑 emthrm |
提出日時 | 2023-03-03 21:55:13 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,080 ms / 4,000 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 3,599 ms |
コンパイル使用メモリ | 253,484 KB |
実行使用メモリ | 69,152 KB |
最終ジャッジ日時 | 2023-10-18 01:55:38 |
合計ジャッジ時間 | 25,845 ms |
ジャッジサーバーID (参考情報) |
judge12 / 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 | 728 ms
69,152 KB |
testcase_04 | AC | 308 ms
36,384 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 505 ms
69,152 KB |
testcase_07 | AC | 376 ms
20,000 KB |
testcase_08 | AC | 2 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 170 ms
20,000 KB |
testcase_11 | AC | 41 ms
4,348 KB |
testcase_12 | AC | 200 ms
20,000 KB |
testcase_13 | AC | 19 ms
5,664 KB |
testcase_14 | AC | 394 ms
36,384 KB |
testcase_15 | AC | 11 ms
4,640 KB |
testcase_16 | AC | 19 ms
5,664 KB |
testcase_17 | AC | 91 ms
11,808 KB |
testcase_18 | AC | 3 ms
4,348 KB |
testcase_19 | AC | 40 ms
7,712 KB |
testcase_20 | AC | 331 ms
36,384 KB |
testcase_21 | AC | 45 ms
7,712 KB |
testcase_22 | AC | 685 ms
69,152 KB |
testcase_23 | AC | 794 ms
69,152 KB |
testcase_24 | AC | 451 ms
36,384 KB |
testcase_25 | AC | 81 ms
11,808 KB |
testcase_26 | AC | 654 ms
69,152 KB |
testcase_27 | AC | 359 ms
36,384 KB |
testcase_28 | AC | 394 ms
36,384 KB |
testcase_29 | AC | 41 ms
7,712 KB |
testcase_30 | AC | 652 ms
69,152 KB |
testcase_31 | AC | 722 ms
69,152 KB |
testcase_32 | AC | 594 ms
69,152 KB |
testcase_33 | AC | 715 ms
69,152 KB |
testcase_34 | AC | 671 ms
69,152 KB |
testcase_35 | AC | 818 ms
69,152 KB |
testcase_36 | AC | 1,080 ms
69,152 KB |
testcase_37 | AC | 829 ms
69,152 KB |
testcase_38 | AC | 695 ms
20,000 KB |
testcase_39 | AC | 365 ms
4,640 KB |
testcase_40 | AC | 301 ms
20,000 KB |
testcase_41 | AC | 41 ms
7,712 KB |
testcase_42 | AC | 142 ms
11,808 KB |
testcase_43 | AC | 13 ms
4,640 KB |
testcase_44 | AC | 643 ms
36,384 KB |
testcase_45 | AC | 587 ms
36,384 KB |
testcase_46 | AC | 422 ms
36,384 KB |
testcase_47 | AC | 460 ms
36,384 KB |
testcase_48 | AC | 718 ms
69,152 KB |
testcase_49 | AC | 356 ms
20,000 KB |
testcase_50 | AC | 8 ms
4,348 KB |
testcase_51 | AC | 97 ms
7,712 KB |
testcase_52 | AC | 11 ms
4,348 KB |
testcase_53 | AC | 2 ms
4,348 KB |
testcase_54 | AC | 328 ms
20,000 KB |
testcase_55 | AC | 492 ms
11,808 KB |
testcase_56 | AC | 328 ms
7,712 KB |
testcase_57 | AC | 580 ms
11,808 KB |
testcase_58 | AC | 357 ms
7,712 KB |
testcase_59 | AC | 390 ms
7,712 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int n, m; cin >> n >> m; vector<int> a(m), b(m); REP(i, m) cin >> a[i] >> b[i], --a[i], --b[i]; ll c = 0; REP(i, n) { ll c_i; cin >> c_i; c |= c_i << i; } map<ll, int> dp; REP(bit, 1 << (m / 2)) { ll color = c; REP(i, m / 2) { if (bit >> i & 1) { color ^= 1LL << a[i]; color ^= 1LL << b[i]; } } auto it = dp.find(color); if (it == dp.end()) it = dp.emplace(color, INF).first; chmin(it->second, popcount(static_cast<unsigned long long>(bit))); } ll ans = LINF; REP(bit, 1 << ((m + 1) / 2)) { ll color = 0; REP(i, (m + 1) / 2) { if (bit >> i & 1) { color ^= 1LL << a[m / 2 + i]; color ^= 1LL << b[m / 2 + i]; } } auto it = dp.find(color); if (it != dp.end()) { chmin(ans, it->second + popcount(static_cast<unsigned long long>(bit))); } } cout << (ans == LINF ? -1 : ans) << '\n'; return 0; }