結果
| 問題 | No.165 四角で囲え! |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-05-19 12:38:07 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 546 ms / 5,000 ms |
| コード長 | 2,746 bytes |
| コンパイル時間 | 2,421 ms |
| コンパイル使用メモリ | 79,232 KB |
| 実行使用メモリ | 56,324 KB |
| 最終ジャッジ日時 | 2024-10-09 16:50:04 |
| 合計ジャッジ時間 | 8,777 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int b = sc.nextInt();
TreeMap<Integer, Integer> compX = new TreeMap<>();
TreeMap<Integer, Integer> compY = new TreeMap<>();
Point[] points = new Point[n];
for (int i = 0; i < n; i++) {
points[i] = new Point(sc.nextInt(), sc.nextInt(), sc.nextInt());
compX.put(points[i].x, null);
compY.put(points[i].y, null);
}
int xx = 1;
for (int x : compX.keySet()) {
compX.put(x, xx);
xx++;
}
int yy = 1;
for (int x : compY.keySet()) {
compY.put(x, yy);
yy++;
}
int[][] scores = new int[xx][yy];
int[][] counts = new int[xx][yy];
for (Point p : points) {
scores[compX.get(p.x)][compY.get(p.y)] += p.value;
counts[compX.get(p.x)][compY.get(p.y)] ++;
}
for (int i = 1; i < xx; i++) {
for (int j = 1; j < yy; j++) {
scores[i][j] += scores[i - 1][j] + scores[i][j - 1] - scores[i - 1][j - 1];
counts[i][j] += counts[i - 1][j] + counts[i][j - 1] - counts[i - 1][j - 1];
}
}
int max = 0;
for (int i = 1; i < xx; i++) {
for (int j = i; j < xx; j++) {
int right = 1;
for (int k = 1; k < yy; k++) {
while (right < yy && scores[j][right] - scores[j][k - 1] - scores[i - 1][right] + scores[i - 1][k - 1] <= b) {
max = Math.max(max, counts[j][right] - counts[j][k - 1] - counts[i - 1][right] + counts[i - 1][k - 1]);
right++;
}
}
}
}
System.out.println(max);
}
static class Point {
int x;
int y;
int value;
public Point(int x, int y, int value) {
this.x = x;
this.y = y;
this.value = value;
}
}
}
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 String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten