結果
問題 | No.1421 国勢調査 (Hard) |
ユーザー |
👑 ![]() |
提出日時 | 2021-03-05 21:44:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 884 bytes |
コンパイル時間 | 1,897 ms |
コンパイル使用メモリ | 199,036 KB |
最終ジャッジ日時 | 2025-01-19 10:50:26 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d%d",&N,&M); | ~~~~~^~~~~~~~~~~~~~ main.cpp:15:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | int a; scanf("%d",&a); | ~~~~~^~~~~~~~~ main.cpp:16:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 16 | G[i].first=0; rep(j,a){ int b; scanf("%d",&b); b--; G[i].first|=(1ull<<b); } | ~~~~~^~~~~~~~~ main.cpp:17:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | scanf("%d",&G[i].second); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>using namespace std;using ll=long long;using ull=unsigned long long;#define rep(i,n) for(int i=0; i<(n); i++)int N,M;vector<pair<ull,int>> G;vector<int> ans;int main(){scanf("%d%d",&N,&M);G.resize(M);rep(i,M){int a; scanf("%d",&a);G[i].first=0; rep(j,a){ int b; scanf("%d",&b); b--; G[i].first|=(1ull<<b); }scanf("%d",&G[i].second);}ans.resize(N);int p=0;rep(i,N){if(p>=M) continue;for(int j=p+1; j<M; j++) if((G[j].first>>i)&1) swap(G[j],G[p]);if((G[p].first>>i)&1){for(int j=0; j<M; j++) if(j!=p) if((G[j].first>>i)&1){ G[j].first^=G[p].first; G[j].second^=G[p].second; }p++;}}for(int j=p; j<M; j++) if(G[j].second!=0){ printf("-1\n"); return 0; }rep(i,p){ rep(d,N) if((G[i].first>>d)&1){ ans[d]=G[i].second; break; } }rep(i,N) printf("%d\n",ans[i]);return 0;}