結果

問題 No.2236 Lights Out On Simple Graph
コンテスト
ユーザー Nzt3
提出日時 2023-03-05 03:03:04
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,235 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,258 ms
コンパイル使用メモリ 206,940 KB
最終ジャッジ日時 2026-06-29 20:20:27
合計ジャッジ時間 2,069 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:76,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:62,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit: In instantiation of 'constexpr int std::__popcount(_Tp) [with _Tp = int]':
main.cpp:32:24:   required from here
   32 |       ans[t]=__popcount(i);
      |              ~~~~~~~~~~^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bit:308:34: error: argument 1 in call to function '__builtin_popcountg' has signed type
  308 |       return __builtin_popcountg(__x);
      |                                  ^~~

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<array<int,2>>E1,E2;
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    if(E1.size()>=20)E2.push_back({a-1,b-1});
    else E1.push_back({a-1,b-1});
  }
  vector<int>C(N);
  for(int &i:C)cin>>i;
  unordered_map<long long,int>ans;
  for(int i=0;i<1<<E1.size();i++){
    vector<int>c2=C;
    for(int j=0;j<E1.size();j++){
      if(i>>j&1){
        c2[E1[j][0]]=1-c2[E1[j][0]];
        c2[E1[j][1]]=1-c2[E1[j][1]];
      }
    }
    long long t=0;
    for(int j=0;j<N;j++){
      if(c2[j])t|=(1ll<<j);
    }
    if(ans.find(t)==ans.end()){
      ans[t]=__popcount(i);
    }else{
      ans[t]=min(ans[t],__builtin_popcount(i));
    }
  }
  int out=1e9;
  if(ans.find(0)!=ans.end())out=ans[0];
  for(int i=0;i<1<<E2.size();i++){
    vector<int>c2(N);
    for(int j=0;j<E2.size();j++){
      if(i>>j&1){
        c2[E2[j][0]]=1-c2[E2[j][0]];
        c2[E2[j][1]]=1-c2[E2[j][1]];
      }
    }
    long long t=0;
    for(int j=0;j<N;j++){
      if(c2[j])t|=(1ll<<j);
    }
    if(ans.find(t)!=ans.end()){
      out=min(out,ans[t]+__builtin_popcount(i));
    }
  }
  cout<<(out==1e9?-1:out)<<'\n';
}
0