結果

問題 No.1036 Make One With GCD 2
ユーザー ngtkanangtkana
提出日時 2020-04-24 22:50:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 775 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 200,148 KB
実行使用メモリ 11,064 KB
最終ジャッジ日時 2023-10-14 19:32:11
合計ジャッジ時間 14,232 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 323 ms
10,840 KB
testcase_01 AC 99 ms
11,064 KB
testcase_02 AC 116 ms
10,880 KB
testcase_03 AC 18 ms
6,024 KB
testcase_04 AC 29 ms
8,476 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 35 ms
6,536 KB
testcase_08 AC 30 ms
5,636 KB
testcase_09 AC 244 ms
10,532 KB
testcase_10 AC 217 ms
10,532 KB
testcase_11 AC 239 ms
10,900 KB
testcase_12 AC 221 ms
10,172 KB
testcase_13 AC 395 ms
10,636 KB
testcase_14 AC 409 ms
10,592 KB
testcase_15 AC 390 ms
9,992 KB
testcase_16 AC 391 ms
10,164 KB
testcase_17 AC 403 ms
10,372 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,356 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 385 ms
10,044 KB
testcase_23 AC 281 ms
8,272 KB
testcase_24 AC 389 ms
10,332 KB
testcase_25 AC 358 ms
9,588 KB
testcase_26 AC 372 ms
10,052 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 120 ms
11,036 KB
testcase_39 AC 775 ms
10,952 KB
testcase_40 AC 272 ms
8,108 KB
testcase_41 AC 452 ms
10,784 KB
testcase_42 AC 445 ms
10,884 KB
testcase_43 AC 379 ms
10,896 KB
testcase_44 AC 418 ms
10,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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