結果

問題 No.258 回転寿司(2)
ユーザー maimai
提出日時 2016-05-29 11:12:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,127 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 170,852 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 15:24:24
合計ジャッジ時間 4,943 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 WA -
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 WA -
testcase_15 AC 2 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 2 ms
6,940 KB
testcase_21 WA -
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 WA -
testcase_39 AC 1 ms
6,940 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 1 ms
6,944 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 2 ms
6,944 KB
testcase_47 WA -
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 WA -
testcase_51 AC 3 ms
6,944 KB
testcase_52 WA -
testcase_53 AC 2 ms
6,944 KB
testcase_54 AC 3 ms
6,940 KB
testcase_55 WA -
testcase_56 AC 3 ms
6,940 KB
testcase_57 AC 2 ms
6,944 KB
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 AC 1 ms
6,944 KB
testcase_63 WA -
testcase_64 AC 2 ms
6,944 KB
testcase_65 WA -
testcase_66 AC 2 ms
6,940 KB
testcase_67 WA -
testcase_68 WA -
testcase_69 AC 2 ms
6,944 KB
testcase_70 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;

int val[1001];
int dp[1001];
vector<int> history[1001];

int calc(int n){
    switch(n){
        case 0:
            return val[0];
        case 1:
            return max(val[0],val[1]);
        default:
            if (!dp[n]){
                int a=calc(n-1),b=val[n]+calc(n-2);
                if (a>=b){
                    history[n]=history[n-1];
                    dp[n]=a;
                }else{
                    history[n]=history[n-2];
                    history[n].push_back(n);
                    dp[n]=b;
                }
            }
            return dp[n];
    }
}

int main(){
    int i,j,k,l,m,n,h,x,y,w;
    // int i,j,k;
    
    cin >> n;
    
    if (n==1){
        cin>>i;
        cout<<i<<endl;
        cout<<1<<endl;
        return 0;
    }
    
    for (i=0;i<n;i++){
        scanf("%d",val+i);
    }
    
    history[0].push_back(1);
    history[1].push_back(val[0]>=val[1] ? 0 : 1);
    
    cout << calc(n-1) <<endl;
    for (int e:history[n-1]){
        printf("%d ",e+1);
    }
    cout<<endl;
    
    return 0;
}
0