結果
| 問題 |
No.2236 Lights Out On Simple Graph
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-10-24 15:43:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,047 ms / 4,000 ms |
| コード長 | 1,566 bytes |
| コンパイル時間 | 1,349 ms |
| コンパイル使用メモリ | 116,704 KB |
| 実行使用メモリ | 68,992 KB |
| 最終ジャッジ日時 | 2024-09-23 08:09:12 |
| 合計ジャッジ時間 | 27,789 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
ソースコード
#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<set>
#include<string>
#include<cstdint>
#include<map>
using namespace std;
using ll = long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int ans = 1e9;
int n,m;
cin>>n>>m;
vector<pair<int,int>> a,b;
for(int i = 0;i<m;i++){
int u,v;
cin>>u>>v;
u--;v--;
pair<int,int> now = make_pair(u,v);
if(i&1) b.push_back(now);
else a.push_back(now);
}
map<ll,int> memo;
ll mask = 0;
for(int i = 0;i<n;i++){
int c;
cin>>c;
if(c) mask |= 1ll << i;
}
int use = a.size();
for(int i = 0;i<1<<use;i++){
ll now = 0;
for(int j = 0;j<use;j++){
if(~i>>j&1) continue;
now ^= 1ll << a[j].first;
now ^= 1ll << a[j].second;
}
if(memo.find(now)==memo.end()) memo[now] = __builtin_popcountll(i);
else memo[now] = min(memo[now],__builtin_popcountll(i));
if(now==mask) ans = min(ans,__builtin_popcountll(i));
}
use = b.size();
for(int i = 0;i<1<<use;i++){
ll now = 0;
for(int j = 0;j<use;j++){
if(~i>>j&1) continue;
now ^= 1ll << b[j].first;
now ^= 1ll << b[j].second;
}
ll want = now ^ mask;
if(want==0) ans = min(ans,__builtin_popcountll(i));
if(memo.find(want)!=memo.end()) ans = min(ans,__builtin_popcountll(i)+memo[want]);
}
if(ans==1e9) ans = -1;
cout<<ans<<endl;
}
momoyuu