結果

問題 No.2157 崖
ユーザー otoshigootoshigo
提出日時 2022-12-09 23:05:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,568 ms / 6,000 ms
コード長 1,448 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 208,776 KB
実行使用メモリ 11,292 KB
最終ジャッジ日時 2023-08-05 00:57:48
合計ジャッジ時間 17,081 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1,252 ms
8,396 KB
testcase_14 AC 1,260 ms
10,372 KB
testcase_15 AC 1,215 ms
8,384 KB
testcase_16 AC 1,254 ms
8,268 KB
testcase_17 AC 1,069 ms
9,388 KB
testcase_18 AC 1,038 ms
9,060 KB
testcase_19 AC 1,568 ms
9,592 KB
testcase_20 AC 1,380 ms
11,176 KB
testcase_21 AC 1,368 ms
11,292 KB
testcase_22 AC 997 ms
8,920 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int n,m;
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cin>>n>>m;
    vector<vector<int>>d(n,vector<int>(m));
    rep(i,n){
        rep(j,m)cin>>d[i][j];
        sort(all(d[i]));
    }
    int ok=1<<30,ng=-1;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        vector<int>dp(m,1);
        rep(i,n-1){
            int l=0,r=0,s=0;
            bool f=true;
            vector<int>dp2(m);
            rep(j,m){
                while(r<m&&d[i+1][j]>=d[i][r]){
                    if(dp[r]==1)s++;
                    r++;
                }
                while(l<m&&d[i+1][j]>d[i][l]+mid){
                    if(dp[l]==1)s--;
                    l++;
                }
                if(s>0)dp2[j]=1;
            }
            rep(j,m)swap(dp[j],dp2[j]);
        }
        bool flag=false;
        rep(i,m)flag=flag||(dp[i]>0);
        if(flag)ok=mid;
        else ng=mid;
    }
    if(ok==1<<30)cout<<-1<<"\n";
    else cout<<ok<<"\n";
}
0