結果

問題 No.2157 崖
ユーザー houren
提出日時 2022-12-09 22:04:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,094 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 170,832 KB
実行使用メモリ 25,984 KB
最終ジャッジ日時 2024-10-14 22:01:20
合計ジャッジ時間 16,610 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 TLE * 1 -- * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL <<62);
constexpr int INF = 2e9;
int dp[1500][1500];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(1500, vector<int>(1500));
    rep(i,n){
        rep(j,m){
            cin >> a[i][j];
            dp[i][j] = INF;
        }
    }
    rep(i,m) dp[0][i] = 0;
    rep(i,n-1){
        rep(j,m){
            rep(k,m){
                if(a[i+1][j]<a[i][k]) continue;
                chmin(dp[i+1][j], max(a[i+1][j]-a[i][k], dp[i][k]));
            }
        }
    }
    int ans = INF;
    rep(i,m) chmin(ans, dp[n-1][i]);
    if(ans==INF) ans = -1;
    cout << ans << '\n';
    return 0;
}
0