結果

問題 No.258 回転寿司(2)
コンテスト
ユーザー nasadigital
提出日時 2015-07-31 23:12:55
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.90.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 433µs
コード長 869 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 940 ms
コンパイル使用メモリ 167,500 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-28 01:21:55
合計ジャッジ時間 10,713 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int niza[n];
    for(int ctr1=0;ctr1<n;ctr1++){
        cin>>niza[ctr1];
    }
    int dp[n];
    memset(dp,0,sizeof(dp));
    for(int ctr1=0;ctr1<n;ctr1++){
        if(ctr1>1)
        {
            dp[ctr1]=max(dp[ctr1],dp[ctr1-2]+niza[ctr1]);
        }
        else dp[ctr1]=max(dp[ctr1],niza[ctr1]);
        if(ctr1>0)
        dp[ctr1]=max(dp[ctr1],dp[ctr1-1]);
    }
    cout<<dp[n-1]<<endl;
    vector<int> rez;
    for(int ctr1=n-1;ctr1>=0;ctr1--){
        if(ctr1>0 && dp[ctr1]==dp[ctr1-1])
            continue;
        else{
            rez.push_back(ctr1+1);
            ctr1--;
        }
    }
    reverse(rez.begin(),rez.end());
    for(int ctr1=0;ctr1<rez.size();ctr1++)
        cout<<rez[ctr1]<<" ";
    cout<<endl;
    return 0;
}
0