結果

問題 No.2236 Lights Out On Simple Graph
ユーザー hiro71687khiro71687k
提出日時 2023-03-06 00:41:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,551 bytes
コンパイル時間 7,396 ms
コンパイル使用メモリ 271,200 KB
実行使用メモリ 200,280 KB
最終ジャッジ日時 2023-10-18 05:05:16
合計ジャッジ時間 51,839 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 1,712 ms
200,280 KB
testcase_04 AC 810 ms
134,744 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1,202 ms
200,280 KB
testcase_07 AC 1,163 ms
101,968 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 WA -
testcase_10 AC 357 ms
44,568 KB
testcase_11 AC 78 ms
4,348 KB
testcase_12 AC 504 ms
52,816 KB
testcase_13 AC 42 ms
9,808 KB
testcase_14 AC 1,038 ms
101,912 KB
testcase_15 AC 27 ms
7,764 KB
testcase_16 AC 53 ms
11,864 KB
testcase_17 AC 168 ms
23,128 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 118 ms
20,052 KB
testcase_20 AC 761 ms
101,976 KB
testcase_21 AC 115 ms
20,056 KB
testcase_22 AC 1,564 ms
200,280 KB
testcase_23 AC 1,701 ms
200,248 KB
testcase_24 AC 1,023 ms
101,960 KB
testcase_25 AC 217 ms
36,440 KB
testcase_26 AC 1,568 ms
200,280 KB
testcase_27 AC 797 ms
101,944 KB
testcase_28 AC 1,132 ms
134,744 KB
testcase_29 AC 112 ms
20,056 KB
testcase_30 AC 1,563 ms
200,280 KB
testcase_31 AC 1,678 ms
200,280 KB
testcase_32 AC 1,541 ms
200,280 KB
testcase_33 AC 1,683 ms
200,280 KB
testcase_34 AC 1,522 ms
200,280 KB
testcase_35 AC 1,687 ms
167,000 KB
testcase_36 AC 1,490 ms
136,792 KB
testcase_37 AC 1,798 ms
200,152 KB
testcase_38 AC 979 ms
36,440 KB
testcase_39 AC 698 ms
5,720 KB
testcase_40 AC 564 ms
44,632 KB
testcase_41 AC 117 ms
15,960 KB
testcase_42 AC 463 ms
52,808 KB
testcase_43 AC 29 ms
6,712 KB
testcase_44 AC 1,327 ms
84,568 KB
testcase_45 AC 1,470 ms
134,736 KB
testcase_46 AC 1,140 ms
101,976 KB
testcase_47 AC 1,367 ms
134,740 KB
testcase_48 AC 1,498 ms
151,128 KB
testcase_49 AC 1,164 ms
101,976 KB
testcase_50 AC 14 ms
4,348 KB
testcase_51 AC 282 ms
28,248 KB
testcase_52 AC 20 ms
4,936 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 843 ms
52,568 KB
testcase_55 AC 970 ms
23,128 KB
testcase_56 AC 846 ms
15,448 KB
testcase_57 AC 1,021 ms
26,200 KB
testcase_58 WA -
testcase_59 AC 801 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];
    }
    if (m==1)
    {
        bool ok=true;
        ll ans=0;
        for (ll i = 0; i < n; i++)
        {
            if (c[i]==1)
            {
                if ((a[0]==c[i]||b[0]==c[i])&&c[a[0]]==1&&c[b[0]]==1)
                {
                    c[a[0]]=0;
                    c[b[0]]=0;
                    ans+=1;
                }else{
                    ok=false;
                }
            }
        }
        if (ok)
        {
            cout << ans << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    
    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