結果
問題 |
No.983 Convolution
|
ユーザー |
![]() |
提出日時 | 2020-02-11 13:54:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,482 bytes |
コンパイル時間 | 3,120 ms |
コンパイル使用メモリ | 212,464 KB |
最終ジャッジ日時 | 2025-01-08 23:33:05 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 14 |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } template<class T, class U> inline T GCD_L(T a, U b){ T r; while(b){ r=a; a=b; b=r%a; } return a; } template<class T, class S> void ZetaTransform_L(int N, T A[], S res[] = NULL){ int i; int j; if(res==NULL){ for(i=0;(1<<i)<N;i++){ for(j=(0);j<(N);j++){ if(j&1<<i){ A[j] += A[j^(1<<i)]; } } } } else{ for(j=(0);j<(N);j++){ res[j] = A[j]; } for(i=0;(1<<i)<N;i++){ for(j=(0);j<(N);j++){ if(j&1<<i){ res[j] += res[j^(1<<i)]; } } } } } template<class T> void MoebiusTransform(int N, T A[], T res[] = NULL){ int i; int j; if(res==NULL){ for(i=0;(1<<i)<N;i++){ for(j=(0);j<(N);j++){ if(j&1<<i){ A[j] -= A[j^(1<<i)]; } } } } else{ for(j=(0);j<(N);j++){ res[j] = A[j]; } for(i=0;(1<<i)<N;i++){ for(j=(0);j<(N);j++){ if(j&1<<i){ res[j] -= res[j^(1<<i)]; } } } } } int N; long long A[200000]; long long b[200000]; long long b2[200000]; int c[200000]; int c2[200000]; int main(){ int i; long long g; rd(N); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } for(i=(0);i<(N);i++){ if(A[i]==-1){ c[i]++; } else{ b[i] = A[i]; } } ZetaTransform_L(N,b,b2); ZetaTransform_L(N,c,c2); for(i=(0);i<(N);i++){ b2[i] *= b2[i]; } for(i=(0);i<(N);i++){ c2[i] *= c2[i]; } MoebiusTransform(N,b2,b); MoebiusTransform(N,c2,c); for(i=(0);i<(N);i++){ if(c[i]){ b[i] = 0; } } { int ao_dF3pO; long long tU__gIr_; if(N==0){ tU__gIr_ = 0; } else{ tU__gIr_ = b[0]; for(ao_dF3pO=(1);ao_dF3pO<(N);ao_dF3pO++){ tU__gIr_ = GCD_L(tU__gIr_, b[ao_dF3pO]); } } g =tU__gIr_; } if(g==0){ g = -1; } wt_L(g); wt_L('\n'); return 0; } // cLay varsion 20200119-1 // --- original code --- // int N; ll A[2d5]; // // ll b[2d5], b2[2d5]; int c[2d5], c2[2d5]; // { // ll g; // // rd(N,A(N)); // rep(i,N) if[A[i]==-1, c[i]++, b[i] = A[i]]; // // ZetaTransform(N,b,b2); // ZetaTransform(N,c,c2); // rep(i,N) b2[i] *= b2[i]; // rep(i,N) c2[i] *= c2[i]; // MoebiusTransform(N,b2,b); // MoebiusTransform(N,c2,c); // // rep(i,N) if(c[i]) b[i] = 0; // g = gcd(b(N)); // if(g==0) g = -1; // wt(g); // }