結果

問題 No.258 回転寿司(2)
ユーザー PachicobuePachicobue
提出日時 2017-08-30 12:43:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,627 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 169,860 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 11:29:08
合計ジャッジ時間 4,686 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    vector<vector<int>> dp(N + 1, vector<int>(2, 0));  //i枚目まで取ってlastを取ったか

    for (int i = 1; i <= N; i++) {
        dp[i][1] = dp[i - 1][0] + v[i - 1];
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    }
    int maxi = max(dp[N][0], dp[N][1]);
    cout << maxi << endl;
    show(dp);
    vector<int> selected;
    bool select = false;
    for (int i = N; i >= 1; i--) {
        select = (select) ? false : (dp[i][0] >= dp[i][1]) ? false : true;
        if (select) {
            selected.push_back(i);
        }
    }
    reverse(selected.begin(), selected.end());
    for (int i = 0; i < selected.size(); i++) {
        if (i != 0) {
            cout << " ";
        }
        cout << selected[i];
    }
    cout << endl;

    return 0;
}
0