結果

問題 No.2157 崖
ユーザー tentententen
提出日時 2022-12-26 12:54:55
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,615 bytes
コンパイル時間 5,220 ms
コンパイル使用メモリ 80,776 KB
実行使用メモリ 38,260 KB
最終ジャッジ日時 2023-08-13 05:02:00
合計ジャッジ時間 18,494 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
38,260 KB
testcase_01 AC 39 ms
33,408 KB
testcase_02 AC 40 ms
33,400 KB
testcase_03 AC 41 ms
33,408 KB
testcase_04 AC 40 ms
33,352 KB
testcase_05 AC 42 ms
33,624 KB
testcase_06 AC 40 ms
33,772 KB
testcase_07 AC 43 ms
33,396 KB
testcase_08 AC 40 ms
33,464 KB
testcase_09 AC 41 ms
33,476 KB
testcase_10 AC 40 ms
33,404 KB
testcase_11 AC 42 ms
33,784 KB
testcase_12 AC 40 ms
33,424 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static int[][] matrix;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        matrix = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                matrix[i][j] = sc.nextInt();
            }
            Arrays.sort(matrix[i]);
        }
        int left = -1;
        int right = Integer.MAX_VALUE / 2;
        while (right - left > 1) {
            int mm = (left + right) / 2;
            if (check(mm, n - 1)) {
                right = mm;
            } else {
                left = mm;
            }
        }
        if (right >= 1000000000) {
            System.out.println(-1);
        } else {
            System.out.println(right);
        }
    }
    
    static boolean check(int x, int idx) {
        boolean ans = false;
        for (int y : matrix[idx]) {
            if (check(idx - 1, y, x)) {
                return true;
            }
        }
        return false;
    }
    
    static boolean check(int idx, int x, int diff) {
        if (idx < 0) {
            return true;
        }
        for (int y : matrix[idx]) {
            if (y > x) {
                return false;
            }
            if (y + diff >= x) {
                if (check(idx -1, y, diff)) {
                    return true;
                }
            }
        }
        return false;
    }
}
class Utilities {
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0