結果

問題 No.2488 Mod Sum Maximization
ユーザー 03吳柏翰03吳柏翰
提出日時 2023-10-30 06:01:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 898 ms / 2,000 ms
コード長 1,477 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 172,440 KB
実行使用メモリ 97,036 KB
最終ジャッジ日時 2023-10-30 06:02:14
合計ジャッジ時間 16,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
30,164 KB
testcase_01 AC 12 ms
30,164 KB
testcase_02 AC 13 ms
34,296 KB
testcase_03 AC 665 ms
74,872 KB
testcase_04 AC 665 ms
74,752 KB
testcase_05 AC 649 ms
74,884 KB
testcase_06 AC 627 ms
73,056 KB
testcase_07 AC 410 ms
65,792 KB
testcase_08 AC 621 ms
73,888 KB
testcase_09 AC 459 ms
67,456 KB
testcase_10 AC 321 ms
62,104 KB
testcase_11 AC 24 ms
45,836 KB
testcase_12 AC 295 ms
60,872 KB
testcase_13 AC 255 ms
58,256 KB
testcase_14 AC 52 ms
47,624 KB
testcase_15 AC 347 ms
63,388 KB
testcase_16 AC 27 ms
45,988 KB
testcase_17 AC 94 ms
49,940 KB
testcase_18 AC 35 ms
46,540 KB
testcase_19 AC 527 ms
69,252 KB
testcase_20 AC 546 ms
71,204 KB
testcase_21 AC 529 ms
70,488 KB
testcase_22 AC 627 ms
73,372 KB
testcase_23 AC 642 ms
74,240 KB
testcase_24 AC 203 ms
54,796 KB
testcase_25 AC 23 ms
45,664 KB
testcase_26 AC 33 ms
46,576 KB
testcase_27 AC 460 ms
76,500 KB
testcase_28 AC 508 ms
78,864 KB
testcase_29 AC 417 ms
69,768 KB
testcase_30 AC 269 ms
63,296 KB
testcase_31 AC 50 ms
47,816 KB
testcase_32 AC 797 ms
97,036 KB
testcase_33 AC 18 ms
45,356 KB
testcase_34 AC 898 ms
89,196 KB
testcase_35 AC 222 ms
58,244 KB
testcase_36 AC 12 ms
32,212 KB
testcase_37 AC 13 ms
34,268 KB
testcase_38 AC 12 ms
34,268 KB
testcase_39 AC 13 ms
34,264 KB
testcase_40 AC 13 ms
34,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define F first
#define S second
#define pb push_back
int n,a[1000005],ans[1000005];
vector<int> v[1000005];
int mn,cnt[2000005];
signed main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n;
    //n=300000;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        //a[i]=i+1;
        sum+=a[i];
    }
    mn=a[0];
    for(int i=0;i<n;i++)
    {
        int now=a[i];
        while(now<=a[n-1])
        {
            int l=0,r=n-1;
            while(l<r)
            {
                int mid=(l+r)>>1;
                if(a[mid]>=now) r=mid;
                else l=mid+1;
            }
            v[l].pb(i);
            now+=a[i];
        }

    }
    //return 0;
    for(int i=0;i<n;i++)
    {
        //cout<<i<<endl;
        for(int j=0;j<v[i].size();j++)
        {
            //cout<<v[i][j]<<endl;
            if(ans[v[i][j]]<1e17&&v[i][j]!=i)
            {
                cnt[ans[v[i][j]]]--;
                ans[v[i][j]]+=a[v[i][j]];
                cnt[ans[v[i][j]]]++;
                while(cnt[mn]==0) mn++;
            }
        }
        //cout<<"rkv"<<endl;
        if(i!=0) ans[i]=mn;
        ans[i]+=a[i];
        cnt[ans[i]]++;
        //cout<<ans[i]<<endl;

    }
    cout<<sum-ans[n-1]+a[n-1]<<'\n';








}
0