結果
| 問題 |
No.165 四角で囲え!
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-01-26 17:41:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 489 ms / 5,000 ms |
| コード長 | 3,472 bytes |
| コンパイル時間 | 2,499 ms |
| コンパイル使用メモリ | 96,320 KB |
| 実行使用メモリ | 55,060 KB |
| 最終ジャッジ日時 | 2024-06-27 10:30:54 |
| 合計ジャッジ時間 | 8,710 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int b = sc.nextInt();
int[] xArr = new int[n];
int[] yArr = new int[n];
int[] pArr = new int[n];
TreeMap<Integer, Integer> xCompress = new TreeMap<>();
TreeMap<Integer, Integer> yCompress = new TreeMap<>();
for (int i = 0; i < n; i++) {
xArr[i] = sc.nextInt();
yArr[i] = sc.nextInt();
pArr[i] = sc.nextInt();
xCompress.put(xArr[i], null);
yCompress.put(yArr[i], null);
}
int w = 1;
for (int x : xCompress.keySet()) {
xCompress.put(x, w++);
}
int h = 1;
for (int x : yCompress.keySet()) {
yCompress.put(x, h++);
}
int[][] points = new int[h][w];
int[][] counts = new int[h][w];
for (int i = 0; i < n; i++) {
int c = xCompress.get(xArr[i]);
int r = yCompress.get(yArr[i]);
points[r][c] += pArr[i];
counts[r][c]++;
}
for (int i = 1; i < h; i++) {
for (int j = 1; j < w; j++) {
points[i][j] += points[i - 1][j] + points[i][j - 1] - points[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 left = 0; left < w - 1; left++) {
for (int right = left + 1; right < w; right++) {
int up = 0;
for (int j = 0; j < h; j++) {
while (up < h) {
int score = points[up][right] - points[up][left] - points[j][right] + points[j][left];
if (score > b) {
break;
}
int sum = counts[up][right] - counts[up][left] - counts[j][right] + counts[j][left];
ans = Math.max(ans, sum);
up++;
}
}
}
}
System.out.println(ans);
}
}
class Utilities {
static String arrayToLineString(Object[] arr) {
return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
}
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