結果

問題 No.2855 Move on Grid
ユーザー t98slider
提出日時 2024-08-25 13:58:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,485 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 202,844 KB
最終ジャッジ日時 2025-02-24 01:02:03
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    if(k > h + w){
        cout << 1'000'000'000 << '\n';
        return 0;
    }
    k = min(k, h + w);
    vector dp(h, vector(w, vector<ll>(k + 1, -1'000'000'003)));
    vector A(h, vector<ll>(w));
    cin >> A;
    dp[0][0][0] = A[0][0];
    if(k >= 1) dp[0][0][1] = 1'000'000'000;
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            for(int i = 0; i <= k; i++){
                if(y + 1 < h){
                    dp[y + 1][x][i] = max(dp[y + 1][x][i], min(dp[y][x][i], A[y + 1][x]));
                    if(i + 1 <= k) dp[y + 1][x][i + 1] = max(dp[y + 1][x][i + 1], dp[y][x][i]);
                }
                if(x + 1 < w){
                    dp[y][x + 1][i] = max(dp[y][x + 1][i], min(dp[y][x][i], A[y][x + 1]));
                    if(i + 1 <= k) dp[y][x + 1][i + 1] = max(dp[y][x + 1][i + 1], dp[y][x][i]);
                }
            }
        }
    }
    cout << *max_element(dp[h - 1][w - 1].begin(), dp[h - 1][w - 1].end()) << '\n';
}
0