結果

問題 No.1036 Make One With GCD 2
ユーザー LayCurseLayCurse
提出日時 2020-04-24 21:51:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 2,861 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 209,488 KB
実行使用メモリ 8,656 KB
最終ジャッジ日時 2023-10-14 19:15:44
合計ジャッジ時間 10,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
8,432 KB
testcase_01 AC 48 ms
8,420 KB
testcase_02 AC 38 ms
8,456 KB
testcase_03 AC 4 ms
7,396 KB
testcase_04 AC 5 ms
8,180 KB
testcase_05 AC 1 ms
5,340 KB
testcase_06 AC 2 ms
5,364 KB
testcase_07 AC 11 ms
8,108 KB
testcase_08 AC 9 ms
7,856 KB
testcase_09 AC 218 ms
8,400 KB
testcase_10 AC 204 ms
8,428 KB
testcase_11 AC 221 ms
8,396 KB
testcase_12 AC 206 ms
8,392 KB
testcase_13 AC 395 ms
8,412 KB
testcase_14 AC 400 ms
8,476 KB
testcase_15 AC 374 ms
8,432 KB
testcase_16 AC 379 ms
8,392 KB
testcase_17 AC 388 ms
8,428 KB
testcase_18 AC 2 ms
5,524 KB
testcase_19 AC 2 ms
5,388 KB
testcase_20 AC 2 ms
5,476 KB
testcase_21 AC 2 ms
5,408 KB
testcase_22 AC 371 ms
8,396 KB
testcase_23 AC 273 ms
8,400 KB
testcase_24 AC 384 ms
8,448 KB
testcase_25 AC 350 ms
8,488 KB
testcase_26 AC 365 ms
8,448 KB
testcase_27 AC 2 ms
5,368 KB
testcase_28 AC 2 ms
5,352 KB
testcase_29 AC 2 ms
5,352 KB
testcase_30 AC 2 ms
5,332 KB
testcase_31 AC 2 ms
5,340 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,328 KB
testcase_34 AC 2 ms
5,476 KB
testcase_35 AC 2 ms
5,368 KB
testcase_36 AC 2 ms
5,380 KB
testcase_37 AC 1 ms
5,352 KB
testcase_38 AC 42 ms
8,632 KB
testcase_39 AC 39 ms
8,440 KB
testcase_40 AC 272 ms
8,472 KB
testcase_41 AC 60 ms
8,476 KB
testcase_42 AC 60 ms
8,392 KB
testcase_43 AC 57 ms
8,656 KB
testcase_44 AC 59 ms
8,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_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 = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_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){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_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;
}
int N;
long long A[500000];
int main(){
  int i;
  int j;
  int k;
  long long res = 0;
  long long tmp;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    j = i;
    tmp = A[j];
    while(j+1 < N && tmp > 1){
      tmp =GCD_L(tmp, A[++j]);
    }
    if(tmp > 1){
      break;
    }
    k = j;
    tmp = A[k];
    while(tmp > 1){
      tmp =GCD_L(tmp, A[--k]);
    }
    res += (long long) (k-i+1) * (N-j);
    i = k;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200419-1

// --- original code ---
// int N; ll A[5d5];
// {
//   int i, j, k;
//   ll res = 0, tmp;
//   rd(N,A(N));
// 
//   rep(i,N){
//     j = i;
//     tmp = A[j];
//     while(j+1 < N && tmp > 1) tmp = gcd(tmp, A[++j]);
//     if(tmp > 1) break;
// 
//     k = j;
//     tmp = A[k];
//     while(tmp > 1) tmp = gcd(tmp, A[--k]);
//     res += (ll) (k-i+1) * (N-j);
//     i = k;
//   }
//   wt(res);
// }
0