結果

問題 No.2236 Lights Out On Simple Graph
ユーザー 👑 NachiaNachia
提出日時 2023-03-03 21:51:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,131 ms / 4,000 ms
コード長 1,378 bytes
コンパイル時間 1,973 ms
コンパイル使用メモリ 92,500 KB
実行使用メモリ 69,152 KB
最終ジャッジ日時 2023-10-18 01:50:23
合計ジャッジ時間 38,071 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
4,348 KB
testcase_01 AC 149 ms
4,348 KB
testcase_02 AC 176 ms
4,348 KB
testcase_03 AC 692 ms
69,152 KB
testcase_04 AC 547 ms
69,152 KB
testcase_05 AC 198 ms
4,348 KB
testcase_06 AC 546 ms
69,152 KB
testcase_07 AC 362 ms
20,000 KB
testcase_08 AC 149 ms
4,348 KB
testcase_09 AC 175 ms
4,348 KB
testcase_10 AC 750 ms
69,152 KB
testcase_11 AC 301 ms
4,348 KB
testcase_12 AC 762 ms
69,152 KB
testcase_13 AC 834 ms
69,152 KB
testcase_14 AC 714 ms
69,152 KB
testcase_15 AC 675 ms
69,124 KB
testcase_16 AC 658 ms
69,152 KB
testcase_17 AC 800 ms
36,356 KB
testcase_18 AC 693 ms
69,124 KB
testcase_19 AC 690 ms
69,124 KB
testcase_20 AC 725 ms
69,152 KB
testcase_21 AC 758 ms
69,152 KB
testcase_22 AC 679 ms
69,152 KB
testcase_23 AC 803 ms
69,152 KB
testcase_24 AC 830 ms
69,152 KB
testcase_25 AC 673 ms
69,152 KB
testcase_26 AC 696 ms
69,152 KB
testcase_27 AC 790 ms
69,124 KB
testcase_28 AC 735 ms
69,152 KB
testcase_29 AC 809 ms
69,152 KB
testcase_30 AC 690 ms
69,152 KB
testcase_31 AC 729 ms
69,152 KB
testcase_32 AC 597 ms
69,152 KB
testcase_33 AC 705 ms
69,152 KB
testcase_34 AC 689 ms
69,152 KB
testcase_35 AC 829 ms
69,124 KB
testcase_36 AC 1,131 ms
69,124 KB
testcase_37 AC 824 ms
69,124 KB
testcase_38 AC 705 ms
19,972 KB
testcase_39 AC 350 ms
4,612 KB
testcase_40 AC 602 ms
36,384 KB
testcase_41 AC 460 ms
20,000 KB
testcase_42 AC 509 ms
36,384 KB
testcase_43 AC 365 ms
11,780 KB
testcase_44 AC 637 ms
36,356 KB
testcase_45 AC 570 ms
36,356 KB
testcase_46 AC 440 ms
36,384 KB
testcase_47 AC 474 ms
36,356 KB
testcase_48 AC 721 ms
69,152 KB
testcase_49 AC 355 ms
20,000 KB
testcase_50 AC 256 ms
4,348 KB
testcase_51 AC 423 ms
19,972 KB
testcase_52 AC 495 ms
11,780 KB
testcase_53 AC 226 ms
4,348 KB
testcase_54 AC 602 ms
36,356 KB
testcase_55 AC 486 ms
11,780 KB
testcase_56 AC 317 ms
7,684 KB
testcase_57 AC 620 ms
11,780 KB
testcase_58 AC 346 ms
7,684 KB
testcase_59 AC 383 ms
7,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

i64 GCD(i64 a, i64 b){ return b ? GCD(b,a%b) : a; }

using Modint = atcoder::static_modint<998244353>;


int main(){
    int N, M; cin >> N >> M;
    map<i64, int> Q0;
    vector<i64> E(40, 0);
    rep(i,M){
        int u, v; cin >> u >> v; u--; v--;
        E[i] = (1ll << u) ^ (1ll << v);
    }
    i64 C = 0;
    rep(i,N){ int a; cin >> a; C |= (i64)a << i; }
    rep(i,1<<20){
        i64 q = 0;
        rep(j,20) if(i&(1<<j)) q ^= E[j];
        int f = __builtin_popcount(i);
        auto I = Q0.find(q);
        if(I == Q0.end()) I = Q0.emplace(q, 1001001).first;
        I->second = min(I->second, f);
    }
    int ans = 1001001;
    rep(i,1<<20){
        i64 q = 0;
        rep(j,20) if(i&(1<<j)) q ^= E[20+j];
        auto I = Q0.find(C ^ q);
        if(I != Q0.end()) ans = min(ans, __builtin_popcount(i) + I->second);
    }
    if(ans >= 10000) ans = -1;
    cout << ans << endl;
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0