結果

問題 No.983 Convolution
ユーザー LayCurseLayCurse
提出日時 2020-02-11 13:54:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,482 bytes
コンパイル時間 2,560 ms
コンパイル使用メモリ 214,732 KB
実行使用メモリ 9,732 KB
最終ジャッジ日時 2024-04-08 14:48:25
合計ジャッジ時間 4,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,752 KB
testcase_01 AC 2 ms
7,752 KB
testcase_02 AC 3 ms
7,752 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 21 ms
9,732 KB
testcase_13 AC 8 ms
8,152 KB
testcase_14 AC 9 ms
8,252 KB
testcase_15 AC 16 ms
9,048 KB
testcase_16 AC 13 ms
8,632 KB
testcase_17 AC 19 ms
9,360 KB
testcase_18 AC 5 ms
7,852 KB
testcase_19 AC 13 ms
8,596 KB
testcase_20 AC 22 ms
9,712 KB
testcase_21 AC 16 ms
9,004 KB
testcase_22 AC 5 ms
7,900 KB
testcase_23 AC 13 ms
9,012 KB
testcase_24 AC 5 ms
7,888 KB
testcase_25 AC 4 ms
7,848 KB
testcase_26 AC 10 ms
8,540 KB
testcase_27 AC 8 ms
8,264 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 3 ms
7,752 KB
testcase_34 AC 3 ms
7,752 KB
testcase_35 AC 3 ms
7,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
// }
0