結果

問題 No.2236 Lights Out On Simple Graph
ユーザー hiro71687khiro71687k
提出日時 2023-03-06 00:44:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,796 ms / 4,000 ms
コード長 1,987 bytes
コンパイル時間 4,427 ms
コンパイル使用メモリ 270,752 KB
実行使用メモリ 200,372 KB
最終ジャッジ日時 2023-10-18 05:06:29
合計ジャッジ時間 52,348 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1,670 ms
200,372 KB
testcase_04 AC 830 ms
134,836 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1,220 ms
200,372 KB
testcase_07 AC 1,168 ms
102,060 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 361 ms
44,660 KB
testcase_11 AC 77 ms
4,348 KB
testcase_12 AC 502 ms
52,908 KB
testcase_13 AC 39 ms
9,900 KB
testcase_14 AC 1,067 ms
102,004 KB
testcase_15 AC 27 ms
7,856 KB
testcase_16 AC 55 ms
11,956 KB
testcase_17 AC 172 ms
23,220 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 122 ms
20,144 KB
testcase_20 AC 792 ms
102,068 KB
testcase_21 AC 117 ms
20,148 KB
testcase_22 AC 1,580 ms
200,372 KB
testcase_23 AC 1,740 ms
200,340 KB
testcase_24 AC 1,056 ms
102,052 KB
testcase_25 AC 227 ms
36,532 KB
testcase_26 AC 1,587 ms
200,372 KB
testcase_27 AC 823 ms
102,036 KB
testcase_28 AC 1,165 ms
134,836 KB
testcase_29 AC 116 ms
20,148 KB
testcase_30 AC 1,604 ms
200,372 KB
testcase_31 AC 1,698 ms
200,372 KB
testcase_32 AC 1,560 ms
200,372 KB
testcase_33 AC 1,683 ms
200,372 KB
testcase_34 AC 1,529 ms
200,372 KB
testcase_35 AC 1,677 ms
167,092 KB
testcase_36 AC 1,499 ms
136,884 KB
testcase_37 AC 1,796 ms
200,244 KB
testcase_38 AC 974 ms
36,532 KB
testcase_39 AC 696 ms
5,812 KB
testcase_40 AC 572 ms
44,724 KB
testcase_41 AC 117 ms
16,052 KB
testcase_42 AC 474 ms
52,900 KB
testcase_43 AC 30 ms
6,804 KB
testcase_44 AC 1,306 ms
84,660 KB
testcase_45 AC 1,495 ms
134,828 KB
testcase_46 AC 1,139 ms
102,068 KB
testcase_47 AC 1,348 ms
134,832 KB
testcase_48 AC 1,554 ms
151,220 KB
testcase_49 AC 1,173 ms
102,068 KB
testcase_50 AC 14 ms
4,348 KB
testcase_51 AC 285 ms
28,340 KB
testcase_52 AC 20 ms
5,028 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 860 ms
52,660 KB
testcase_55 AC 971 ms
23,220 KB
testcase_56 AC 846 ms
15,540 KB
testcase_57 AC 1,019 ms
26,292 KB
testcase_58 AC 746 ms
12,852 KB
testcase_59 AC 799 ms
12,724 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==0)
        {
            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