結果

問題 No.2236 Lights Out On Simple Graph
ユーザー lddlinan
提出日時 2023-03-04 02:00:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,410 ms / 4,000 ms
コード長 1,766 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 94,448 KB
最終ジャッジ日時 2025-02-11 05:01:00
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 57
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:29:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         scanf("%d %d", &as[i], &bs[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:32:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |     for (i=0; i<n; i++) scanf("%d", &cs[i]);
      |                         ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;



int as[64], bs[64], cs[64];
int main() {
    int n, i, a, b, d, m, hm, nm;
    int j, c, r;
    LL v, one=1, nv, mm, xm;
    scanf("%d %d", &n, &m);
    for (i=0; i<m; i++) {
        scanf("%d %d", &as[i], &bs[i]);
        as[i]--; bs[i]--;
    }
    for (i=0; i<n; i++) scanf("%d", &cs[i]);
    hm = m/2;
    map<LL, int> dd1;
    map<LL, int> dd2;
    mm = 1<<hm;
    for (i=0; i<mm; i++) {
        xm = 0; c=0;
        for (j=0; j<hm; j++) {
            if (((1<<j)&i)==0) continue;
            c++;
            a=as[j]; b=bs[j];
            xm^=(one<<a);
            xm^=(one<<b);
        }
        if (dd1.count(xm)) dd1[xm]=min(dd1[xm], c);
        else dd1[xm]=c;
    }
    nm = m-hm;
    mm  =1<<nm;
    for (i=0; i<mm; i++) {
        xm = 0; c=0;
        for (j=0; j<nm; j++) {
            if (((1<<j)&i)==0) continue;
            c++;
            a=as[j+hm]; b=bs[j+hm];
            xm^=(one<<a);
            xm^=(one<<b);
        }
        if (dd2.count(xm)) dd2[xm]=min(dd2[xm], c);
        else dd2[xm]=c;
    }
    r=-1;
    xm=0; for (i=0; i<n; i++) if (cs[i]) xm|=(one<<i);
    if (dd1.count(xm)) r=dd1[xm];
    if (dd2.count(xm)) {
        if (r==-1||r>dd2[xm]) r=dd2[xm];
    }
    for (auto x : dd1) {
        mm = x.first; c=x.second;
        mm^=xm;
        if (dd2.count(mm)==0) continue;
        c+=dd2[mm];
        if (r==-1||r>c) r=c;
    }
    printf("%d\n", r);
            
    return 0;
}
0