結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-04-24 22:50:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 253 ms / 2,000 ms |
| コード長 | 906 bytes |
| コンパイル時間 | 2,501 ms |
| コンパイル使用メモリ | 195,412 KB |
| 最終ジャッジ日時 | 2025-01-10 00:21:45 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
lint n;std::cin>>n;
std::vector<lint>a(n),g(n+1);
for(lint&x:a)std::cin>>x;
lint ans=n*(n+1)/2;
for(lint l=0,c=0,r=0;l<n;l++){
lint h=c==l?0:a[l];
for(;r<n;r++){
g[r+1]=std::gcd(g[r],a[r]);
lint hg=std::gcd(h,g[r+1]);
if(hg==1)break;
}
ans-=r-l;
if(l==r){
c++;
r++;
g[r]=0;
}else if(l==c){
for(c=r-2;c>=l;c--){
a[c]=std::gcd(a[c],a[c+1]);
}
c=r;
g[r]=0;
}
}
std::cout<<ans<<'\n';
}
ngtkana