結果

問題 No.2236 Lights Out On Simple Graph
ユーザー umimel
提出日時 2023-03-05 15:18:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 725 ms / 4,000 ms
コード長 1,586 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 180,544 KB
実行使用メモリ 68,992 KB
最終ジャッジ日時 2024-09-18 01:35:46
合計ジャッジ時間 23,068 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll MAX_N = 2e5;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n, m; cin >> n >> m;
vector<ll> a(m), b(m);
rep(i, m){
cin >> a[i] >> b[i];
a[i]--; b[i]--;
}
vector<ll> c(n); rep(i, n) cin >> c[i];
ll m1 = m/2, m2 = m - m1;
map<ll, ll> dp2;
rep(bit, (1LL<<m2)){
ll bit2 = 0;
ll cnt = 0;
rep(i, m2){
if((bit>>i)&1){
bit2 = bit2 ^ (1LL<<a[m1+i]);
bit2 = bit2 ^ (1LL<<b[m1+i]);
cnt++;
}
}
if(dp2.find(bit2)!=dp2.end()){
dp2[bit2] = min(dp2[bit2], cnt);
}else{
dp2[bit2] = cnt;
}
}
ll T = 0;
for(ll i=n-1; i>=0; i--) T = 2*T + c[i];
ll ans = INF;
rep(bit, (1LL<<m1)){
ll bit1 = 0;
ll cnt = 0;
rep(i, m1){
if((bit>>i)&1){
bit1 = bit1 ^ (1LL<<a[i]);
bit1 = bit1 ^ (1LL<<b[i]);
cnt++;
}
}
if(dp2.find(bit1 ^ T) != dp2.end()){
ans = min(ans, cnt+dp2[bit1 ^ T]);
}
}
if(ans == INF) cout << -1 << endl;
else cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0