結果
問題 | No.165 四角で囲え! |
ユーザー | tenten |
提出日時 | 2021-05-19 12:38:07 |
言語 | Java21 (openjdk 21) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 301 ms
52,804 KB |
testcase_01 | AC | 54 ms
50,068 KB |
testcase_02 | AC | 54 ms
50,380 KB |
testcase_03 | AC | 55 ms
50,176 KB |
testcase_04 | AC | 55 ms
50,392 KB |
testcase_05 | AC | 290 ms
52,740 KB |
testcase_06 | AC | 152 ms
52,500 KB |
testcase_07 | AC | 54 ms
50,448 KB |
testcase_08 | AC | 54 ms
50,292 KB |
testcase_09 | AC | 54 ms
49,684 KB |
testcase_10 | AC | 54 ms
50,388 KB |
testcase_11 | AC | 213 ms
52,724 KB |
testcase_12 | AC | 151 ms
52,632 KB |
testcase_13 | AC | 145 ms
52,628 KB |
testcase_14 | AC | 142 ms
52,824 KB |
testcase_15 | AC | 198 ms
56,324 KB |
testcase_16 | AC | 338 ms
52,848 KB |
testcase_17 | AC | 258 ms
52,628 KB |
testcase_18 | AC | 546 ms
53,656 KB |
testcase_19 | AC | 300 ms
53,004 KB |
testcase_20 | AC | 284 ms
52,924 KB |
testcase_21 | AC | 275 ms
53,368 KB |
testcase_22 | AC | 428 ms
52,700 KB |
ソースコード
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(); } }