結果

問題 No.2157 崖
ユーザー dyktr_06dyktr_06
提出日時 2022-12-09 23:14:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,085 ms / 6,000 ms
コード長 2,642 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 205,992 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-22 23:02:45
合計ジャッジ時間 19,169 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 924 ms
13,696 KB
testcase_14 AC 1,659 ms
18,048 KB
testcase_15 AC 1,305 ms
13,568 KB
testcase_16 AC 1,333 ms
13,568 KB
testcase_17 AC 1,406 ms
15,872 KB
testcase_18 AC 1,420 ms
15,488 KB
testcase_19 AC 1,258 ms
16,256 KB
testcase_20 AC 2,085 ms
19,584 KB
testcase_21 AC 2,022 ms
19,328 KB
testcase_22 AC 1,443 ms
15,104 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())

typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef pair<long long, long long> P;

const long long INF = 0x1fffffffffffffff;
const long long MOD = 998244353;
const long double PI = acos(-1);
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
template<class... T> void in(T&... a){ (cin >> ... >> a); }
void out(){ cout << '\n'; }
template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T, class U> void inGraph(vector<vector<T>>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } }

ll n, m;
vector<vector<ll>> d;

void input(){
    in(n, m);
    d = vector<vector<ll>>(n, vector<ll>(m));
    rep(i, n) rep(j, m) in(d[i][j]);
}
 
void solve(){
    rep(i, n) Sort(d[i]);
    ll ans = INF;

    ll ok = 1e9, ng = -1;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        
        vll v;
        ll check = 1;
        rep(j, m){
            v.push_back(d[0][j]);
        }
        for(int i = 1; i < n; i++){
            vll v2;
            ll cnt = 0;
            rep(j, m){
                auto k1 = upper_bound(ALL(v), d[i][j]);
                if(k1 != v.begin()){
                    k1--;
                    if(clamp(d[i][j], *k1, *k1 + mid) == d[i][j]){
                        cnt++;
                        v2.push_back(d[i][j]);
                    }
                }
            }
            if(cnt == 0){
                check = 0;
                break;
            }
            v = v2;
        }
        if(check) ok = mid;
        else ng = mid;
    }
    chmin(ans, ok);

    if(ans >= 1e9) out(-1);
    else out(ans);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    input();
    solve();
}
0