結果

問題 No.2488 Mod Sum Maximization
ユーザー 03吳柏翰03吳柏翰
提出日時 2023-10-30 05:33:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,170 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 208,140 KB
実行使用メモリ 199,180 KB
最終ジャッジ日時 2023-10-30 05:33:24
合計ジャッジ時間 16,175 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,626 ms
199,180 KB
testcase_01 AC 1,602 ms
192,140 KB
testcase_02 AC 1,630 ms
192,140 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pb push_back
int n,a[1000005],ans[1000005];
vector<int> v[1000005];
signed main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    int sum=0;
    for(int i=0;i<=1000000;i++) ans[i]=1e18;
    for(int i=1;i<=1000000;i++)
    {
        for(int j=1;j<=1000000/i;j++) v[i*j].pb(i);
    }
    multiset<int> s;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
        ans[a[i]]=0;
    }
    //cout<<a[n-1]<<endl;
    for(int i=1;i<=a[n-1];i++)
    {
        //cout<<i<<endl;
        for(int j=0;j<v[i].size();j++)
        {
            //cout<<v[i-1][j]<<endl;
            if(ans[v[i][j]]<1e17&&v[i][j]!=i)
            {
                s.erase(s.find(ans[v[i][j]]));
                ans[v[i][j]]+=v[i][j];
                s.insert(ans[v[i][j]]);
            }
        }
        //cout<<"rkv"<<endl;
        if(ans[i]==0)
        {
            if(i!=a[0]) ans[i]=(*s.begin());
            ans[i]+=i;
            s.insert(ans[i]);
            //cout<<ans[i]<<endl;
        }
    }
    cout<<sum-ans[a[n-1]]+a[n-1]<<'\n';








}
0