結果
問題 | No.983 Convolution |
ユーザー |
![]() |
提出日時 | 2020-02-11 14:03:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,286 bytes |
コンパイル時間 | 2,775 ms |
コンパイル使用メモリ | 213,752 KB |
最終ジャッジ日時 | 2025-01-08 23:34:41 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 WA * 1 |
ソースコード
#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(int x){ int s=0; int m=0; char f[10]; 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'); } } 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)]; } } } } } inline void wt_L(__int128_t x){ int s=0; int m=0; char f[40]; 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'); } } int N; long long A[200000]; __int128_t b[200000]; __int128_t b2[200000]; int c[200000]; int c2[200000]; int main(){ int i; __int128_t g; rd(N); { int cTE1_r3A; for(cTE1_r3A=(0);cTE1_r3A<(N);cTE1_r3A++){ rd(A[cTE1_r3A]); } } 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 V9aVTaxx; __int128_t APIVbQlN; if(N==0){ APIVbQlN = 0; } else{ APIVbQlN = b[0]; for(V9aVTaxx=(1);V9aVTaxx<(N);V9aVTaxx++){ APIVbQlN = GCD_L(APIVbQlN, b[V9aVTaxx]); } } g =APIVbQlN; } if(g==0){ g = -1; } wt_L(g); wt_L('\n'); return 0; } // cLay varsion 20200119-1 // --- original code --- // inline void wt_L(__int128_t x){ // int s=0, m=0; // char f[40]; // 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'); // } // // // int N; ll A[2d5]; // // __int128_t b[2d5]; // __int128_t b2[2d5]; // int c[2d5], c2[2d5]; // { // __int128_t 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); // }