結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 778 ms
19,456 KB
testcase_01 AC 275 ms
19,456 KB
testcase_02 AC 10 ms
19,436 KB
testcase_03 AC 856 ms
20,644 KB
testcase_04 AC 870 ms
20,608 KB
testcase_05 AC 860 ms
20,608 KB
testcase_06 AC 815 ms
20,608 KB
testcase_07 AC 586 ms
20,224 KB
testcase_08 AC 838 ms
20,608 KB
testcase_09 AC 633 ms
20,312 KB
testcase_10 AC 473 ms
20,088 KB
testcase_11 AC 33 ms
19,456 KB
testcase_12 AC 436 ms
20,020 KB
testcase_13 AC 356 ms
19,968 KB
testcase_14 AC 91 ms
19,456 KB
testcase_15 AC 519 ms
20,216 KB
testcase_16 AC 39 ms
19,456 KB
testcase_17 AC 167 ms
19,584 KB
testcase_18 AC 55 ms
19,328 KB
testcase_19 AC 685 ms
20,352 KB
testcase_20 AC 732 ms
20,448 KB
testcase_21 AC 730 ms
20,480 KB
testcase_22 AC 811 ms
20,528 KB
testcase_23 AC 832 ms
20,620 KB
testcase_24 AC 319 ms
19,840 KB
testcase_25 AC 27 ms
19,456 KB
testcase_26 AC 53 ms
19,472 KB
testcase_27 AC 923 ms
19,968 KB
testcase_28 AC 997 ms
20,000 KB
testcase_29 AC 711 ms
19,936 KB
testcase_30 AC 600 ms
19,840 KB
testcase_31 AC 97 ms
19,428 KB
testcase_32 AC 1,575 ms
20,248 KB
testcase_33 AC 16 ms
19,420 KB
testcase_34 AC 1,327 ms
20,604 KB
testcase_35 AC 427 ms
19,832 KB
testcase_36 AC 9 ms
19,428 KB
testcase_37 AC 8 ms
19,356 KB
testcase_38 AC 9 ms
19,456 KB
testcase_39 AC 8 ms
19,456 KB
testcase_40 AC 8 ms
19,456 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