結果

問題 No.2157 崖
ユーザー ooaiu
提出日時 2025-03-10 04:32:52
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 8,208 ms
コンパイル使用メモリ 264,428 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2025-03-10 04:33:09
合計ジャッジ時間 17,300 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) (void(0))
#endif
void run_case();
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--) run_case();
    return 0;
}
void run_case() {
    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];
        sort(D[i].begin(), D[i].end());
    }
    int ans = 1e9;
    for(int i = 0; i < M; i++) {
        int diff = 0;
        bool ok = true;
        int cur = D[0][i];
        for(int j = 1; j < N; j++) {
            int id = lower_bound(D[j].begin(), D[j].end(), cur) - D[j].begin();
            if(id == M) {
                ok = false;
                break;
            }
            diff = max(diff, D[j][id] - cur);
            cur = D[j][id];
        }
        if(ok) ans = min(ans, diff);
    }
    cout << (ans == (int)1e9 ? -1 : ans) << endl;
}
0