結果

問題 No.1036 Make One With GCD 2
ユーザー ngtkanangtkana
提出日時 2020-04-24 21:42:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 3,233 ms
コンパイル使用メモリ 201,684 KB
実行使用メモリ 7,080 KB
最終ジャッジ日時 2023-10-14 19:13:19
合計ジャッジ時間 10,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
7,008 KB
testcase_01 AC 104 ms
6,892 KB
testcase_02 AC 103 ms
6,952 KB
testcase_03 AC 13 ms
4,668 KB
testcase_04 AC 21 ms
5,724 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 37 ms
4,624 KB
testcase_08 AC 32 ms
4,372 KB
testcase_09 AC 159 ms
7,080 KB
testcase_10 AC 142 ms
6,676 KB
testcase_11 AC 159 ms
6,936 KB
testcase_12 AC 151 ms
6,788 KB
testcase_13 AC 256 ms
6,632 KB
testcase_14 AC 261 ms
6,944 KB
testcase_15 AC 238 ms
6,708 KB
testcase_16 AC 247 ms
6,692 KB
testcase_17 AC 249 ms
6,628 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 236 ms
6,664 KB
testcase_23 AC 172 ms
5,652 KB
testcase_24 AC 244 ms
6,740 KB
testcase_25 AC 231 ms
6,432 KB
testcase_26 AC 245 ms
6,380 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 1 ms
4,356 KB
testcase_38 AC 93 ms
6,896 KB
testcase_39 AC 136 ms
6,964 KB
testcase_40 AC 189 ms
5,572 KB
testcase_41 AC 164 ms
7,012 KB
testcase_42 AC 162 ms
6,936 KB
testcase_43 AC 151 ms
6,820 KB
testcase_44 AC 154 ms
6,892 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);
    for(lint&x:a)std::cin>>x;
    lint ans=n*(n+1)/2;
    for(lint l=0,c=0,r=0,g=0;l<n;l++){
        lint h=c==l?0:a.at(l);
        for(;r<n;g=std::gcd(g,a.at(r)),r++){
            lint nhg=std::gcd(std::gcd(h,g),a.at(r));
            if(nhg==1)break;
        }
        ans-=r-l;
        if(l==r){
            assert(g==0);
            c++;
            r++;
        }else if(l==c){
            for(c=r-2;c>=l;c--){
                a.at(c)=std::gcd(a.at(c),a.at(c+1));
            }
            c=r;
            g=0;
        }
    }
    std::cout<<ans<<'\n';
}
0