結果

問題 No.2157 崖
ユーザー ぷらぷら
提出日時 2022-12-09 21:35:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,339 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 200,120 KB
実行使用メモリ 20,208 KB
最終ジャッジ日時 2024-04-22 21:07:37
合計ジャッジ時間 27,674 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 5 ms
9,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dp[1515][1515];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vector<vector<int>>D(N,vector<int>(M));
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            cin >> D[i][j];
        }
    }
    int l = -1,r = 1001001001;
    while(l+1 < r) {
        int mid = (l+r)/2;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < M; j++) {
                dp[i][j] = 0;
                if(i == 0) dp[i][j] = 1;
            }
        }
        for(int i = 0; i+1 < N; i++) {
            for(int j = 0; j < M; j++) {
                if(dp[i][j] != 0) {
                    int it1 = lower_bound(D[i+1].begin(),D[i+1].end(),D[i][j])-D[i+1].begin();
                    int it2 = upper_bound(D[i+1].begin(),D[i+1].end(),D[i][j]+mid)-D[i+1].begin();
                    dp[i+1][it1]++;
                    dp[i+1][it2]--;
                }
            }
            for(int j = 0; j < M; j++) {
                dp[i+1][j+1] += dp[i+1][j];
            }
        }
        bool f = false;
        for(int i = 0; i < M; i++) {
            if(dp[N-1][i]) {
                f = true;
            }
        }
        if(f) r = mid;
        else l = mid;
    }
    cout << ((r == 1001001001)?-1:r) << endl;
}
0