結果

問題 No.1536 仕切り直し
ユーザー 629e^-b629e^-b
提出日時 2021-06-14 21:24:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 4,476 ms
コンパイル使用メモリ 266,624 KB
実行使用メモリ 58,076 KB
最終ジャッジ日時 2023-08-26 06:48:16
合計ジャッジ時間 5,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 6 ms
6,992 KB
testcase_04 AC 24 ms
19,348 KB
testcase_05 AC 52 ms
38,200 KB
testcase_06 AC 18 ms
15,056 KB
testcase_07 AC 13 ms
11,944 KB
testcase_08 AC 40 ms
29,368 KB
testcase_09 AC 46 ms
33,156 KB
testcase_10 AC 84 ms
58,076 KB
testcase_11 AC 25 ms
19,460 KB
testcase_12 AC 69 ms
47,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

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

    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    vector<vector<ll>> dp(N + M + 1, vector<ll>(N + 1, -1e18));
    vector<vector<bool>> rec(N + M + 1, vector<bool>(N + 1, false));
    dp[0][0] = 0;
    for (int i = 0; i < N + M; ++i) {
        for (int j = 0; j <= N; ++j) {
            if (dp[i + 1][j] < dp[i][j]) {
                dp[i + 1][j] = dp[i][j];
                rec[i + 1][j] = false;
            }
            if (j < N) {
                ll tmp = dp[i][j] + ((i - j) & 1 ? -A[j] : A[j]);
                if (dp[i + 1][j + 1] < tmp) {
                    dp[i + 1][j + 1] = tmp;
                    rec[i + 1][j + 1] = true;
                }
            }
        }
    }

    vector<int> ans;
    int now = N;
    for (int i = N + M; i >= 1; --i) {
        if (!rec[i][now]) {
            ans.emplace_back(now);
        }
        now -= rec[i][now];
    }

    reverse(ans.begin(), ans.end());
    for (auto i : ans) {
        cout << i << "\n";
    }

    return 0;
}
0