結果

問題 No.2236 Lights Out On Simple Graph
ユーザー hiro71687khiro71687k
提出日時 2023-03-06 00:35:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,989 bytes
コンパイル時間 4,688 ms
コンパイル使用メモリ 270,876 KB
実行使用メモリ 200,280 KB
最終ジャッジ日時 2023-10-18 05:04:10
合計ジャッジ時間 51,989 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1,695 ms
200,280 KB
testcase_04 AC 804 ms
134,744 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1,200 ms
200,280 KB
testcase_07 AC 1,159 ms
101,968 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 367 ms
44,568 KB
testcase_11 AC 77 ms
4,348 KB
testcase_12 AC 520 ms
52,816 KB
testcase_13 AC 44 ms
9,808 KB
testcase_14 AC 1,038 ms
101,912 KB
testcase_15 AC 27 ms
7,764 KB
testcase_16 AC 54 ms
11,864 KB
testcase_17 AC 171 ms
23,128 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 119 ms
20,052 KB
testcase_20 AC 761 ms
101,976 KB
testcase_21 AC 117 ms
20,056 KB
testcase_22 AC 1,584 ms
200,280 KB
testcase_23 AC 1,735 ms
200,248 KB
testcase_24 AC 1,012 ms
101,960 KB
testcase_25 AC 220 ms
36,440 KB
testcase_26 AC 1,570 ms
200,280 KB
testcase_27 AC 807 ms
101,944 KB
testcase_28 AC 1,127 ms
134,744 KB
testcase_29 AC 114 ms
20,056 KB
testcase_30 AC 1,567 ms
200,280 KB
testcase_31 AC 1,680 ms
200,280 KB
testcase_32 AC 1,555 ms
200,280 KB
testcase_33 AC 1,691 ms
200,280 KB
testcase_34 AC 1,506 ms
200,280 KB
testcase_35 AC 1,665 ms
167,000 KB
testcase_36 AC 1,477 ms
136,792 KB
testcase_37 AC 1,782 ms
200,152 KB
testcase_38 AC 973 ms
36,440 KB
testcase_39 AC 687 ms
5,720 KB
testcase_40 AC 553 ms
44,632 KB
testcase_41 AC 117 ms
15,960 KB
testcase_42 AC 459 ms
52,808 KB
testcase_43 AC 29 ms
6,712 KB
testcase_44 AC 1,309 ms
84,568 KB
testcase_45 AC 1,478 ms
134,736 KB
testcase_46 AC 1,110 ms
101,976 KB
testcase_47 AC 1,347 ms
134,740 KB
testcase_48 AC 1,514 ms
151,128 KB
testcase_49 AC 1,154 ms
101,976 KB
testcase_50 AC 14 ms
4,348 KB
testcase_51 AC 280 ms
28,248 KB
testcase_52 AC 19 ms
4,936 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 849 ms
52,568 KB
testcase_55 AC 965 ms
23,128 KB
testcase_56 AC 839 ms
15,448 KB
testcase_57 AC 1,040 ms
26,200 KB
testcase_58 WA -
testcase_59 AC 792 ms
12,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=10010010010010010;
ll mod=998244353;
int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll>a(m),b(m);
    for (ll i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
    }
    vector<ll>c(n);
    vector<ll>two(50,1);
    for (ll i = 1; i < 50; i++)
    {
        two[i]=two[i-1]*2;
    }
    ll now=0;
    for (ll i = 0; i < n; i++)
    {
        cin >> c[i];
        now+=two[i]*c[i];
    }
    map<ll,ll>dp1,dp2;
    ll x=m/2;
    for (ll i = 0; i < two[x]; i++)
    {
        ll y=now;
        ll kai=0;
        for (ll j = 0; j < x; j++)
        {
            if (i&two[j])
            {
                y^=two[a[j]];
                y^=two[b[j]];
                kai+=1;
            }
        }
        if (y==now)
        {
            dp1[y]=0;
        }else{
            if (dp1[y]==0)
            {
                dp1[y]=kai;
            }else{
                dp1[y]=min(dp1[y],kai);
            }
        }
    }
    x=m-x;
    for (ll i = 0; i < two[x]; i++)
    {
        ll y=0;
        ll kai=0;
        for (ll j = m/2; j < m; j++)
        {
            if (i&two[j-m/2])
            {
                y^=two[a[j]];
                y^=two[b[j]];
                kai+=1;
            }
        }
        if (y==now)
        {
            dp2[y]=0;
        }else{
            if (dp2[y]==0)
            {
                dp2[y]=kai;
            }else{
                dp2[y]=min(dp2[y],kai);
            }
        }
    }
    ll ans=inf;
    for(auto v:dp1){
        if (v.first==0)
        {
            ans=min(ans,v.second);
        }else{
            if (dp2[v.first]!=0)
            {
                ans=min(ans,v.second+dp2[v.first]);
            }
        }
    }
    if (ans==inf)
    {
        cout << -1 << endl;
        return 0;
    }
    
    cout << ans <<endl;
}
0