結果

問題 No.2157 崖
ユーザー dyktr_06dyktr_06
提出日時 2022-12-09 22:20:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,981 bytes
コンパイル時間 2,551 ms
コンパイル使用メモリ 204,948 KB
実行使用メモリ 19,328 KB
最終ジャッジ日時 2024-04-22 22:30:35
合計ジャッジ時間 52,037 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 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 4,690 ms
18,048 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 4,058 ms
15,744 KB
testcase_18 AC 4,011 ms
15,360 KB
testcase_19 WA -
testcase_20 TLE -
testcase_21 AC 5,819 ms
19,200 KB
testcase_22 AC 3,748 ms
14,848 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 6 ms
5,376 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;
    rep(i, m){
        ll ok = 1e10, ng = -1;
        while(abs(ok - ng) > 1){
            ll mid = (ok + ng) / 2;
            ll l = d[0][i], r = d[0][i];
            ll check = 1;
            for(int j = 1; j < n; j++){
                auto k1 = lower_bound(ALL(d[j]), l);
                auto k2 = upper_bound(ALL(d[j]), r + mid);
                vll v;
                if(k1 != d[j].end()){
                    if(clamp(*k1, l, r + mid) == *k1){
                        v.push_back(*k1);
                    }
                }
                if(k2 != d[j].begin()){
                    k2--;
                    if(clamp(*k2, l, r + mid) == *k2){
                        v.push_back(*k2);
                    }
                }
                if(v.size() == 0){
                    check = 0;
                    break;
                }else{
                    l = INF, r = -INF;
                    for(auto x : v){
                        chmin(l, x);
                        chmax(r, x);
                    }
                }
            }
            if(check) ok = mid;
            else ng = mid;
        }
        chmin(ans, ok);
    }
    if(ans == 1e10) out(-1);
    else out(ans);
}

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