結果

問題 No.2157 崖
ユーザー lddlinanlddlinan
提出日時 2023-03-19 13:20:59
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 1,843 ms / 6,000 ms
コード長 1,609 bytes
コンパイル時間 676 ms
使用メモリ 13,908 KB
最終ジャッジ日時 2023-03-19 13:21:14
合計ジャッジ時間 13,662 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
9,700 KB
testcase_01 AC 2 ms
7,652 KB
testcase_02 AC 2 ms
7,576 KB
testcase_03 AC 2 ms
7,596 KB
testcase_04 AC 2 ms
9,756 KB
testcase_05 AC 2 ms
7,572 KB
testcase_06 AC 2 ms
7,600 KB
testcase_07 AC 2 ms
7,688 KB
testcase_08 AC 2 ms
7,656 KB
testcase_09 AC 2 ms
7,584 KB
testcase_10 AC 2 ms
9,636 KB
testcase_11 AC 2 ms
7,656 KB
testcase_12 AC 2 ms
7,564 KB
testcase_13 AC 1,395 ms
11,280 KB
testcase_14 AC 335 ms
13,856 KB
testcase_15 AC 1,392 ms
13,508 KB
testcase_16 AC 1,478 ms
13,496 KB
testcase_17 AC 281 ms
13,800 KB
testcase_18 AC 276 ms
13,808 KB
testcase_19 AC 1,843 ms
13,464 KB
testcase_20 AC 383 ms
13,908 KB
testcase_21 AC 377 ms
13,864 KB
testcase_22 AC 269 ms
13,668 KB
testcase_23 AC 2 ms
7,600 KB
testcase_24 AC 5 ms
13,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};

int gn, gm;
char dp[1504][1504];
int as[1504][1504];
char check(int d) {
    int i, j, s, e, c;
    for (i=0; i<gn; i++) for (j=0; j<gm; j++) dp[i][j]=0;
    for (j=0; j<gm; j++) dp[gn-1][j]=1;
    for (i=gn-2; i>=0; i--) {
        s=e=0; c=0;
        for (j=0; j<gm; j++) {
            dp[i][j]=0;
            while(e<gm&&as[i+1][e]<=as[i][j]+d) {
                c+=dp[i+1][e];
                e++;
            }
            while(s<e&&as[i+1][s]<as[i][j]) {
                c-=dp[i+1][s];
                s++;
            }
            if (c) dp[i][j]=1;
        }
    }
    for (j=0; j<gm; j++) if(dp[0][j]) return 1;
    return 0;
}

int main() {
    int n, i, mx, r, d, nr, j, m;
    scanf("%d %d", &n, &m); gn=n; gm=m;
    for (i=0; i<n; i++) {
        for (j=0; j<m; j++) scanf("%d", &as[i][j]);
        sort(as[i], as[i]+m);
    }
    mx = 1000000000;
    if (check(mx)) {
        r=mx; d=mx;
        while(d) {
            while(1) {
                nr=r-d; if (nr<0) break;
                if (check(nr)==0) break;
                r=nr;
            }
            d>>=1;
        }
        printf("%d\n", r);
    } else printf("-1\n");
    return 0;
}
0