結果

問題 No.1536 仕切り直し
ユーザー KudeKude
提出日時 2021-06-06 18:47:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 3,742 ms
コンパイル使用メモリ 262,244 KB
実行使用メモリ 25,544 KB
最終ジャッジ日時 2023-08-16 16:59:01
合計ジャッジ時間 4,866 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 8 ms
9,988 KB
testcase_05 AC 17 ms
18,064 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 7 ms
8,920 KB
testcase_09 AC 9 ms
11,188 KB
testcase_10 AC 25 ms
25,544 KB
testcase_11 AC 5 ms
6,532 KB
testcase_12 AC 17 ms
18,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    VL a(n);
    rep(i, n) cin >> a[i];
    constexpr ll INF = 1002003004005006007;
    VVL dp(n + 1, VL(m + 1, -INF));
    dp[0][0] = 0;
    rep(i, n + 1) rep(j, m + 1) {
        if (i) chmax(dp[i][j], dp[i - 1][j] + (j & 1 ? -1 : 1) * a[i - 1]);
        if (j) chmax(dp[i][j], dp[i][j - 1]);
    }
    VI ans;
    int i = n, j = m;
    while(i || j) {
        if (i && dp[i][j] == dp[i - 1][j] + (j & 1 ? -1 : 1) * a[i - 1]) i--;
        else if (j && dp[i][j] == dp[i][j - 1]) j--, ans.push_back(i);
    }
    rrep(i, m) cout << ans[i] << '\n';
    cerr << dp[n][m] << endl;
}
0