結果

問題 No.2488 Mod Sum Maximization
ユーザー pockynypockyny
提出日時 2023-10-29 22:36:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,865 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 108,344 KB
実行使用メモリ 20,652 KB
最終ジャッジ日時 2024-05-14 23:06:44
合計ジャッジ時間 29,782 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 852 ms
19,320 KB
testcase_01 AC 313 ms
19,428 KB
testcase_02 AC 11 ms
19,384 KB
testcase_03 AC 1,061 ms
20,652 KB
testcase_04 AC 1,056 ms
20,604 KB
testcase_05 AC 1,053 ms
20,616 KB
testcase_06 AC 987 ms
20,508 KB
testcase_07 AC 740 ms
20,220 KB
testcase_08 AC 1,026 ms
20,548 KB
testcase_09 AC 784 ms
20,340 KB
testcase_10 AC 592 ms
20,072 KB
testcase_11 AC 40 ms
19,428 KB
testcase_12 AC 544 ms
20,028 KB
testcase_13 AC 449 ms
19,940 KB
testcase_14 AC 114 ms
19,560 KB
testcase_15 AC 640 ms
20,096 KB
testcase_16 AC 47 ms
19,476 KB
testcase_17 AC 211 ms
19,568 KB
testcase_18 AC 70 ms
19,408 KB
testcase_19 AC 843 ms
20,340 KB
testcase_20 AC 922 ms
20,432 KB
testcase_21 AC 896 ms
20,388 KB
testcase_22 AC 996 ms
20,532 KB
testcase_23 AC 1,037 ms
20,532 KB
testcase_24 AC 394 ms
19,832 KB
testcase_25 AC 33 ms
19,468 KB
testcase_26 AC 69 ms
19,520 KB
testcase_27 AC 1,127 ms
19,852 KB
testcase_28 AC 1,213 ms
19,984 KB
testcase_29 AC 884 ms
19,932 KB
testcase_30 AC 717 ms
19,780 KB
testcase_31 AC 123 ms
19,544 KB
testcase_32 AC 1,865 ms
20,252 KB
testcase_33 AC 19 ms
19,400 KB
testcase_34 AC 1,617 ms
20,488 KB
testcase_35 AC 531 ms
19,792 KB
testcase_36 AC 12 ms
19,376 KB
testcase_37 AC 12 ms
19,432 KB
testcase_38 AC 12 ms
19,464 KB
testcase_39 AC 11 ms
19,496 KB
testcase_40 AC 12 ms
19,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <atcoder/lazysegtree>

using namespace std;
using namespace atcoder;
typedef int ll;

//range chmin range min
ll inf = 1000000000;
struct S{ll x;};
struct F{ll x;};
S op(S l,S r){return S{min(l.x,r.x)};}
S e(){return S{inf};}
S mapping(F l,S r){return S{min(l.x,r.x)};}
F compo(F l,F r){return F{min(l.x,r.x)};}
F id(){return F{inf};}

ll a[300010];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    const int mx = 1000000;
    vector<S> v(mx + 1);
    for(i=0;i<=mx;i++) v[i] = e(); 
    lazy_segtree<S,op,e,F,mapping,compo,id> seg(v);
    long long ans = 0;
    for(i=0;i<n;i++) ans += a[i];
    seg.set(a[0],S{0});
    for(i=0;i<n;i++){
        // cout << i << endl;
        ll x = a[i];
        ll c = a[i];
        for(j=x;j<=mx;j+=x){
            // cout << j << endl;
            seg.apply(j,min((ll)mx + 1,j + x),F{seg.get(a[i]).x + c});
            c += a[i];
        }
    }
    cout << ans - seg.get(a[n - 1]).x << endl;
}
0