結果
問題 | No.1421 国勢調査 (Hard) |
ユーザー | moririn2528_c |
提出日時 | 2021-03-05 21:47:12 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 2,981 bytes |
コンパイル時間 | 1,010 ms |
コンパイル使用メモリ | 106,548 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-04-16 09:12:42 |
合計ジャッジ時間 | 3,133 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 68 ms
5,760 KB |
testcase_23 | AC | 66 ms
5,760 KB |
testcase_24 | AC | 67 ms
5,760 KB |
testcase_25 | AC | 67 ms
5,632 KB |
testcase_26 | AC | 66 ms
5,632 KB |
testcase_27 | AC | 66 ms
5,760 KB |
testcase_28 | AC | 67 ms
5,760 KB |
testcase_29 | AC | 66 ms
5,632 KB |
testcase_30 | AC | 67 ms
5,632 KB |
testcase_31 | AC | 67 ms
5,632 KB |
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<deque> #include<iomanip> #include<tuple> #include<cassert> #include<set> #include<complex> #include<numeric> #include<functional> #include<unordered_map> #include<unordered_set> using namespace std; typedef long long int LL; typedef pair<int,int> P; typedef pair<LL,int> LP; const int INF=1<<30; const LL MAX=998244353; void array_show(int *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(LL *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } long long int pow_mod(long long int a,long long int n,long long int p=1e9+7){ //a^n mod p long long int b=1,t=1; for(;b<=n;b<<=1); for(b>>=1;b>0;b>>=1){ t*=t; if(t>=p)t%=p; if(n&b)t*=a; if(t>=p)t%=p; } return t; } namespace sol{ int t[11000][55]; void print(vector<int>& v1){ for(int i=0;i<v1.size();i++){ cout<<v1[i]<<endl; } } void solve(){ int n,m; int i,j,k; int a,b,c; cin>>n>>m; for(i=0;i<m;i++){ cin>>a; for(j=0;j<a;j++){ cin>>b; t[i][b-1]=1; } cin>>b; t[i][n]=b; } for(i=0,a=0;i<m;i++,a++){ for(;a<=n;a++){ for(j=i;j<m;j++){ if(t[j][a])break; } if(j==m)continue; for(k=0;k<=n;k++){ swap(t[i][k],t[j][k]); } break; } if(a==n+1)break; for(j=0;j<m;j++){ if(j==i || !t[j][a])continue; for(k=0;k<=n;k++){ t[j][k]^=t[i][k]; } } } vector<int> vs(n); if(i==0){ print(vs); return; } a=i; for(i=0;i<n;i++){ if(t[a-1][i])break; } if(i==n && t[a-1][n]){ cout<<-1<<endl; return; } for(i=a-1;i>=0;i--){ b=t[i][n]; for(j=n-1,k=-1;j>=0;j--){ if(t[i][j]){ k=j; b^=vs[j]; } } assert(k!=-1); vs[k]=b; } print(vs); } } int main(){ sol::solve(); }