結果
問題 | No.2907 Business Revealing Dora Tiles |
ユーザー | 👑 獅子座じゃない人 |
提出日時 | 2024-06-02 19:49:05 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 9,211 bytes |
コンパイル時間 | 12,567 ms |
コンパイル使用メモリ | 284,668 KB |
実行使用メモリ | 45,824 KB |
最終ジャッジ日時 | 2024-09-23 11:25:07 |
合計ジャッジ時間 | 40,153 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | WA | - |
testcase_04 | AC | 3 ms
6,944 KB |
testcase_05 | WA | - |
testcase_06 | AC | 3 ms
6,940 KB |
testcase_07 | AC | 28 ms
6,940 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | WA | - |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 3 ms
6,944 KB |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | WA | - |
testcase_22 | AC | 5 ms
6,944 KB |
testcase_23 | AC | 59 ms
6,944 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | AC | 409 ms
9,600 KB |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | AC | 58 ms
6,944 KB |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> using namespace atcoder; using mint=modint998244353; vector nim_prod_table(256, vector<unsigned long long>(256)); vector<unsigned long long> nim_inv_table(256); void nim_prod_precalc() { nim_prod_table[0][0]=0; nim_prod_table[0][1]=0; nim_prod_table[1][0]=0; nim_prod_table[1][1]=1; for(int d=0;d<3;++d){ int p=1<<d; for(int a=0;a<(1<<(2*p));++a){ for(int b=(1<<p);b<(1<<(2*p));++b){ unsigned long long a_h=a>>p; unsigned long long a_l=a-(a_h<<p); unsigned long long b_h=b>>p; unsigned long long b_l=b-(b_h<<p); unsigned long long al_bl=nim_prod_table[a_l][b_l]; unsigned long long ahl_bhl=nim_prod_table[a_h^a_l][b_h^b_l]; unsigned long long ah_bh=nim_prod_table[a_h][b_h]; unsigned long long ah_bh_h=nim_prod_table[ah_bh][1ULL<<(p-1)]; nim_prod_table[a][b]=nim_prod_table[b][a]=((al_bl^ahl_bhl)<<p)^(al_bl^ah_bh_h); } } } } unsigned long long nim_product(unsigned long long a, unsigned long long b, int p=64) { if(p==64){ if(a<(1ULL<<8) && b<(1ULL<<8)){ p=8; } else if(a<(1ULL<<16) && b<(1ULL<<16)){ p=16; } else if(a<(1ULL<<32) && b<(1ULL<<32)){ p=32; } } if(p==8){ return nim_prod_table[a][b]; } p/=2; unsigned long long a_h=a>>p; unsigned long long a_l=a-(a_h<<p); unsigned long long b_h=b>>p; unsigned long long b_l=b-(b_h<<p); unsigned long long al_bl=nim_product(a_l, b_l, p); unsigned long long ahl_bhl=nim_product(a_h^a_l, b_h^b_l, p); unsigned long long ah_bh=nim_product(a_h, b_h, p); unsigned long long ah_bh_h=nim_product(ah_bh, 1ULL<<(p-1), p); return ((al_bl^ahl_bhl)<<p)^(al_bl^ah_bh_h); } void nim_inv_precalc() { for(int i=0;i<256;++i){ for(int j=i;j<256;++j){ if(nim_prod_table[i][j]==1){ nim_inv_table[i]=j; nim_inv_table[j]=i; break; } } } } unsigned long long nim_inv(unsigned long long a, int p=64) { if(p==64){ if(a<(1ULL<<8)){ p=8; } else if(a<(1ULL<<16)){ p=16; } else if(a<(1ULL<<32)){ p=32; } } if(p==8){ return nim_inv_table[a]; } p/=2; unsigned long long a_h=a>>p; unsigned long long a_l=a-(a_h<<p); unsigned long long half_inv=nim_inv(nim_product(a_h^a_l, a_l)^nim_product(nim_product(a_h, a_h), 1ULL<<(p-1)), p); return (nim_product(half_inv, a_h)<<p)^nim_product(half_inv, a_h^a_l); } tuple<int,vector<int>,vector<int>> gauss_jordan(int r, int c, vector<vector<unsigned long long>> & m) { vector<int> sets; vector<int> not_sets; int rank=0; for(int i=0;i<c;++i){ int pivot=-1; for(int j=rank;j<r;++j){ if(m[j][i]>0){ pivot=j; break; } } if(pivot==-1){ not_sets.emplace_back(i); continue; } sets.emplace_back(i); swap(m[pivot], m[rank]); auto inv=nim_inv(m[rank][i]); m[rank][i]=1; for(int k=rank+1;k<c;++k){ m[rank][k]=nim_product(m[rank][k], inv); } for(int j=0;j<r;++j){ if(j==rank){ continue; } auto factor=m[j][i]; m[j][i]=0; for(int k=rank+1;k<c;++k){ m[j][k]^=nim_product(m[rank][k], factor); } } ++rank; if(rank==r){ for(int j=i+1;j<c;++j){ not_sets.emplace_back(j); } break; } } return tuple{rank,sets,not_sets}; } void clean_column(int rank, vector<vector<unsigned long long>> & d, vector<vector<unsigned long long>> & u, int row, int col) { vector<unsigned long long> v(rank); unsigned long long inv=nim_inv(d[row][col]); for(int i=0;i<rank;++i){ if(i==row){ v[i]=inv^1; } else { v[i]=nim_product(d[i][col], inv); } } auto new_d=d; auto new_u=u; for(int i=0;i<rank;++i){ for(int j=0;j<rank;++j){ new_d[i][j]^=nim_product(v[i], d[row][j]); new_u[i][j]^=nim_product(v[i], u[row][j]); } } swap(d, new_d); } bool dynamic_matrix_rank(int rank, int a_col, int m_col, vector<vector<unsigned long long>> & u, vector<vector<unsigned long long>> & a, vector<vector<unsigned long long>> & m){ vector<unsigned long long> v(rank); for(int i=0;i<rank;++i){ v[i]=a[i][a_col]^m[i][m_col]; } vector<unsigned long long> new_v(rank); for(int i=0;i<rank;++i){ for(int j=0;j<rank;++j){ new_v[i]^=nim_product(u[i][j], v[j]); } } vector d(rank, vector<unsigned long long>(rank)); int leading_entry_row=rank; for(int i=0;i<rank;++i){ d[i][i]=1; } for(int i=0;i<rank;++i){ d[i][a_col]^=new_v[i]; if(i>=a_col && leading_entry_row==rank && d[i][a_col]>0){ leading_entry_row=i; } } if(leading_entry_row<rank){ clean_column(rank, d, u, leading_entry_row, a_col); } int leading_entry_col=rank; for(int i=0;i<a_col;++i){ if(d[a_col][i]>0){ leading_entry_col=i; break; } } if(leading_entry_col<rank){ clean_column(rank, d, u, a_col, leading_entry_col); } for(int i=0;i<rank;++i){ bool ok=false; for(int j=i;j<rank;++j){ if(d[j][i]>0){ if(i!=j){ swap(d[i], d[j]); swap(u[i], u[j]); } ok=true; break; } } if(!ok){ return false; } } return true; } int main(void) { nim_prod_precalc(); nim_inv_precalc(); int n,t; cin >> n >> t; vector h(t, vector<unsigned long long>(n)); for(int i=0;i<t;++i){ for(int j=0;j<n;++j){ cin >> h[i][j]; --h[i][j]; } } auto m=h; auto [rank,sets,not_sets]=gauss_jordan(t, n, m); int s=0; for(int i: sets){ s+=1<<i; } vector<bool> seen(1<<n); vector<int> ranks(1<<n); stack<tuple<int,vector<int>,vector<int>,vector<vector<unsigned long long>>,vector<vector<unsigned long long>>>> st; seen[s]=true; ranks[s]=rank; vector e(rank, vector<unsigned long long>(rank)); for(int i=0;i<rank;++i){ e[i][i]=1; } st.emplace(tuple{s,sets,not_sets,e,e}); while(!st.empty()){ auto [s,sets,not_sets,u,a]=st.top(); st.pop(); for(int i=0;i<(int)sets.size();++i){ for(int j=0;j<(int)not_sets.size();++j){ int new_s=s-(1<<sets[i])+(1<<not_sets[j]); if(seen[new_s]){ continue; } seen[new_s]=true; auto new_u=u; auto new_a=a; if(dynamic_matrix_rank(rank, i, not_sets[j], new_u, new_a, m)){ auto new_sets=sets; auto new_not_sets=not_sets; swap(new_sets[i], new_not_sets[j]); ranks[new_s]=rank; st.emplace(tuple{new_s,new_sets,new_not_sets,new_u,new_a}); } } } } for(int r=rank-1;r>=0;--r){ vector<bool> st(n); for(int i=n-r;i<n;++i){ st[i]=true; } do { int s=0; for(int i=0;i<n;++i){ if(st[i]){ s+=1<<i; } } for(int i=0;i<n;++i){ if(st[i]){ continue; } if(ranks[s+(1<<i)]>0){ ranks[s]=r; break; } } } while(next_permutation(st.begin(), st.end())); } for(int r=0;r<n;++r){ vector<bool> st(n); for(int i=n-r;i<n;++i){ st[i]=true; } do { int s=0; for(int i=0;i<n;++i){ if(st[i]){ s+=1<<i; } } for(int i=0;i<n;++i){ if(st[i]){ continue; } ranks[s+(1<<i)]=max(ranks[s], ranks[s+(1<<i)]); } } while(next_permutation(st.begin(), st.end())); } mint ans=0; mint p=932051910; for(unsigned int s=0;s<(1U<<n);++s){ int count=popcount(s); if(n%2>0){ if(count%2>0){ ans+=p.pow(count-ranks[s]); } else { ans-=p.pow(count-ranks[s]); } } else { if(count%2>0){ ans-=p.pow(count-ranks[s]); } else { ans+=p.pow(count-ranks[s]); } } } cout << ans.val() << endl; return 0; }