結果

問題 No.1036 Make One With GCD 2
ユーザー ngtkanangtkana
提出日時 2020-04-24 22:47:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 936 bytes
コンパイル時間 2,499 ms
コンパイル使用メモリ 202,368 KB
実行使用メモリ 10,936 KB
最終ジャッジ日時 2023-10-14 19:30:21
合計ジャッジ時間 10,382 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
10,832 KB
testcase_01 AC 112 ms
10,844 KB
testcase_02 AC 107 ms
10,860 KB
testcase_03 AC 14 ms
5,900 KB
testcase_04 AC 23 ms
8,288 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 40 ms
6,544 KB
testcase_08 AC 32 ms
5,624 KB
testcase_09 AC 154 ms
10,620 KB
testcase_10 AC 142 ms
10,088 KB
testcase_11 AC 156 ms
10,936 KB
testcase_12 AC 144 ms
10,056 KB
testcase_13 AC 254 ms
10,508 KB
testcase_14 AC 256 ms
10,532 KB
testcase_15 AC 241 ms
10,004 KB
testcase_16 AC 243 ms
10,148 KB
testcase_17 AC 250 ms
10,264 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,352 KB
testcase_22 AC 238 ms
10,332 KB
testcase_23 AC 176 ms
8,292 KB
testcase_24 AC 248 ms
10,316 KB
testcase_25 AC 226 ms
9,676 KB
testcase_26 AC 234 ms
9,784 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,356 KB
testcase_29 AC 1 ms
4,352 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 105 ms
10,904 KB
testcase_39 AC 148 ms
10,876 KB
testcase_40 AC 175 ms
8,256 KB
testcase_41 AC 181 ms
10,904 KB
testcase_42 AC 185 ms
10,800 KB
testcase_43 AC 168 ms
10,900 KB
testcase_44 AC 175 ms
10,828 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.at(l);
        for(;r<n;r++){
            g.at(r+1)=std::gcd(g.at(r),a.at(r));
            lint hg=std::gcd(h,g.at(r+1));
            if(hg==1)break;
        }
        ans-=r-l;
        if(l==r){
            c++;
            r++;
            g.at(r)=0;
        }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.at(r)=0;
        }
    }
    std::cout<<ans<<'\n';
}
0