結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
10,784 KB
testcase_01 AC 114 ms
10,796 KB
testcase_02 AC 108 ms
10,832 KB
testcase_03 AC 15 ms
5,912 KB
testcase_04 AC 24 ms
8,068 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 40 ms
6,412 KB
testcase_08 AC 33 ms
5,688 KB
testcase_09 AC 152 ms
10,744 KB
testcase_10 AC 142 ms
10,112 KB
testcase_11 AC 155 ms
10,864 KB
testcase_12 AC 143 ms
9,972 KB
testcase_13 AC 254 ms
10,640 KB
testcase_14 AC 255 ms
10,712 KB
testcase_15 AC 238 ms
10,180 KB
testcase_16 AC 241 ms
10,068 KB
testcase_17 AC 248 ms
10,212 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 236 ms
10,000 KB
testcase_23 AC 173 ms
8,192 KB
testcase_24 AC 245 ms
10,376 KB
testcase_25 AC 223 ms
9,804 KB
testcase_26 AC 232 ms
9,636 KB
testcase_27 AC 2 ms
4,356 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 104 ms
10,788 KB
testcase_39 AC 149 ms
11,000 KB
testcase_40 AC 174 ms
8,136 KB
testcase_41 AC 183 ms
10,904 KB
testcase_42 AC 181 ms
10,696 KB
testcase_43 AC 169 ms
11,072 KB
testcase_44 AC 176 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