結果
| 問題 |
No.2157 崖
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-12-26 12:54:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,615 bytes |
| コンパイル時間 | 6,150 ms |
| コンパイル使用メモリ | 82,372 KB |
| 実行使用メモリ | 94,008 KB |
| 最終ジャッジ日時 | 2024-11-20 21:42:14 |
| 合計ジャッジ時間 | 78,504 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 10 |
ソースコード
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();
}
}
tenten