結果

問題 No.258 回転寿司(2)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-05-25 00:36:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,838 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 148,272 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-02 17:52:52
合計ジャッジ時間 6,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.25 00:36:25
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector< int > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (n == 1) {
        cout << a[0] << endl;
        cout << 1 << endl;
        return 0;
    } else if (n == 2) {
        if (a[0] > a[1]) {
            cout << a[0] << endl;
            cout << 1 << endl;
        } else {
            cout << a[1] << endl;
            cout << 2 << endl;
        }
    }
    vector< int > dp(n, 0);
    dp[0] = a[0];
    dp[1] = a[1];
    dp[2] = a[0] + a[2];
    for (int i = 3; i < n; i++) {
        dp[i] = max(a[i] + dp[i - 2], a[i] + dp[i - 3]);
    }
    vector< int > ans;
    if (dp[n - 1] > dp[n - 2]) {
        cout << dp[n - 1] << endl;
        ans.push_back(n - 1);
        int t = n - 1;
        while (t >= 3) {
            if (dp[t - 2] + a[t] == dp[t]) {
                ans.push_back(t - 2);
                t = t - 2;
            } else if (dp[t - 3] + a[t] == dp[t]) {
                ans.push_back(t - 3);
                t = t - 3;
            }
        }
        for (int i = ans.size() - 1; i >= 0; i--) {
            cout << ans[i] + 1 << " ";
        }
        cout << endl;
    } else {
        cout << dp[n - 2] << endl;
        ans.push_back(n - 2);
        int t = n - 2;
        while (t >= 3) {
            if (dp[t - 2] + a[t] == dp[t]) {
                ans.push_back(t - 2);
                t = t - 2;
            } else if (dp[t - 3] + a[t] == dp[t]) {
                ans.push_back(t - 3);
                t = t - 3;
            }
        }
        for (int i = ans.size() - 1; i >= 0; i--) {
            cout << ans[i] + 1 << " ";
        }
        cout << endl;
    }
    return 0;
}
0