結果
| 問題 |
No.165 四角で囲え!
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-10 12:57:50 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,778 bytes |
| コンパイル時間 | 3,132 ms |
| コンパイル使用メモリ | 79,876 KB |
| 実行使用メモリ | 81,168 KB |
| 最終ジャッジ日時 | 2024-11-20 23:19:32 |
| 合計ジャッジ時間 | 81,247 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 9 TLE * 10 |
ソースコード
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int bb = sc.nextInt();
int[] xs = new int[n];
int[] ys = new int[n];
int[] ps = new int[n];
TreeMap<Integer, Integer> compX = new TreeMap<>();
TreeMap<Integer, Integer> compY = new TreeMap<>();
for (int i = 0; i < n; i++) {
xs[i] = sc.nextInt();
ys[i] = sc.nextInt();
ps[i] = sc.nextInt();
compX.put(xs[i], null);
compY.put(ys[i], null);
}
int xIdx = 1;
for (int x : compX.keySet()) {
compX.put(x, xIdx);
xIdx++;
}
int yIdx = 1;
for (int x : compY.keySet()) {
compY.put(x, yIdx);
yIdx++;
}
int[][] field = new int[xIdx][yIdx];
int[][] counts = new int[xIdx][yIdx];
for (int i = 0; i < n; i++) {
field[compX.get(xs[i])][compY.get(ys[i])] = ps[i];
counts[compX.get(xs[i])][compY.get(ys[i])] = 1;
}
for (int i = 1; i < xIdx; i++) {
for (int j = 1; j < yIdx; j++) {
field[i][j] += field[i - 1][j] + field[i][j - 1] - field[i - 1][j - 1];
counts[i][j] += counts[i - 1][j] + counts[i][j - 1] - counts[i - 1][j - 1];
}
}
int ans = 0;
for (int a = 0; a < xIdx - 1; a++) {
for (int b = a + 1; b < xIdx; b++) {
for (int c = 0; c < yIdx - 1; c++) {
for (int d = c + 1; d < yIdx; d++) {
if (field[b][d] - field[a][d] - field[b][c] + field[a][c] <= bb) {
ans = Math.max(ans, counts[b][d] - counts[a][d] - counts[b][c] + counts[a][c]);
}
}
}
}
}
System.out.println(ans);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
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 String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten