結果

問題 No.1536 仕切り直し
ユーザー KKT89KKT89
提出日時 2021-06-06 19:07:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 3,180 ms
コンパイル使用メモリ 215,356 KB
実行使用メモリ 51,516 KB
最終ジャッジ日時 2023-08-16 17:00:01
合計ジャッジ時間 3,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
51,208 KB
testcase_01 AC 16 ms
51,208 KB
testcase_02 AC 16 ms
51,280 KB
testcase_03 AC 17 ms
51,236 KB
testcase_04 AC 20 ms
51,516 KB
testcase_05 AC 24 ms
51,264 KB
testcase_06 AC 17 ms
51,312 KB
testcase_07 AC 17 ms
51,236 KB
testcase_08 AC 20 ms
51,324 KB
testcase_09 AC 20 ms
51,288 KB
testcase_10 AC 28 ms
51,288 KB
testcase_11 AC 18 ms
51,240 KB
testcase_12 AC 25 ms
51,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

const int N=2021;
ll dp[N][N];
int re[N][N];

bool chmax(ll &x,ll y){
    if(x<=y){
        x=y;
        return true;
    }
    return false;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    a.push_back(0);
    n++;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            dp[i][j]=-1e18;
            re[i][j]=-1;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=m;j++){
            if(dp[i][j]==-1e18)continue;
            if(j+1<=m){
                if(chmax(dp[i][j+1],dp[i][j])){
                    re[i][j+1]=i;
                }
            }
            if(chmax(dp[i+1][j],dp[i][j]+(ll)(j%2==0?1:-1)*a[i])){
                re[i+1][j]=re[i][j];
            }
        }
    }
    vector<int> v;
    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=m;j++){
    //         cout << i << "," << j << endl;
    //         cout << dp[i][j] << " " << re[i][j] << endl;
    //     }
    // }
    for(int i=m;i>0;i--){
        v.push_back(re[n][i]);
        n=re[n][i];
    }
    for(int i:v){
        cout << i << "\n";
    }
}
0