結果
問題 | No.165 四角で囲え! |
ユーザー | kenkoooo |
提出日時 | 2015-03-14 02:56:23 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 621 ms / 5,000 ms |
コード長 | 2,360 bytes |
コンパイル時間 | 3,240 ms |
コンパイル使用メモリ | 79,200 KB |
実行使用メモリ | 41,700 KB |
最終ジャッジ日時 | 2024-06-07 19:01:42 |
合計ジャッジ時間 | 8,467 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 239 ms
39,712 KB |
testcase_01 | AC | 46 ms
36,208 KB |
testcase_02 | AC | 46 ms
36,756 KB |
testcase_03 | AC | 46 ms
36,560 KB |
testcase_04 | AC | 47 ms
36,224 KB |
testcase_05 | AC | 336 ms
41,176 KB |
testcase_06 | AC | 143 ms
39,220 KB |
testcase_07 | AC | 46 ms
36,572 KB |
testcase_08 | AC | 48 ms
36,640 KB |
testcase_09 | AC | 47 ms
36,888 KB |
testcase_10 | AC | 46 ms
36,580 KB |
testcase_11 | AC | 166 ms
39,420 KB |
testcase_12 | AC | 115 ms
38,948 KB |
testcase_13 | AC | 120 ms
38,912 KB |
testcase_14 | AC | 105 ms
39,068 KB |
testcase_15 | AC | 117 ms
39,488 KB |
testcase_16 | AC | 433 ms
41,700 KB |
testcase_17 | AC | 314 ms
40,804 KB |
testcase_18 | AC | 621 ms
39,736 KB |
testcase_19 | AC | 359 ms
40,076 KB |
testcase_20 | AC | 315 ms
40,556 KB |
testcase_21 | AC | 329 ms
41,152 KB |
testcase_22 | AC | 317 ms
40,936 KB |
ソースコード
import static java.util.Arrays.binarySearch; import java.io.IOException; import java.util.TreeSet; public class Main { public static void main(String[] args) { int N = nextInt(); int B = nextInt(); int[] xs = new int[N]; int[] ys = new int[N]; int[] point = new int[N]; for (int i = 0; i < N; i++) { xs[i] = nextInt(); ys[i] = nextInt(); point[i] = nextInt(); } TreeSet<Integer> xTreeSet = new TreeSet<Integer>(); TreeSet<Integer> yTreeSet = new TreeSet<Integer>(); for (int i = 0; i < N; i++) { xTreeSet.add(xs[i]); yTreeSet.add(ys[i]); } xTreeSet.add((int) Integer.MAX_VALUE); xTreeSet.add((int) Integer.MIN_VALUE); yTreeSet.add((int) Integer.MAX_VALUE); yTreeSet.add((int) Integer.MIN_VALUE); Integer[] xIntegers = xTreeSet.toArray(new Integer[0]); Integer[] yIntegers = yTreeSet.toArray(new Integer[0]); int w = xIntegers.length; int h = yIntegers.length; int[][] treasures = new int[h + 1][w + 1]; int[][] tPoints = new int[h + 1][w + 1]; for (int i = 0; i < N; i++) { int x = binarySearch(xIntegers, xs[i]); int y = binarySearch(yIntegers, ys[i]); treasures[y + 1][x + 1]++; tPoints[y + 1][x + 1] += point[i]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { treasures[i + 1][j + 1] += treasures[i + 1][j] + treasures[i][j + 1] - treasures[i][j]; tPoints[i + 1][j + 1] += tPoints[i + 1][j] + tPoints[i][j + 1] - tPoints[i][j]; } } int tMax = 0; for (int x1 = 0; x1 < w; x1++) { for (int x2 = x1 + 1; x2 < w + 1; x2++) { int y1 = 0; int y2 = 1; while (y2 < h + 1) { int tNum = treasures[y2][x2] - treasures[y1][x2] - treasures[y2][x1] + treasures[y1][x1]; int pointNum = tPoints[y2][x2] - tPoints[y1][x2] - tPoints[y2][x1] + tPoints[y1][x1]; if (pointNum <= B) { tMax = Math.max(tMax, tNum); y2++; } else { y1++; } } } } System.out.println(tMax); } static int nextInt() { int c; try { c = System.in.read(); while (c != '-' && (c < '0' || c > '9')) c = System.in.read(); if (c == '-') return -nextInt(); int res = 0; while (c >= '0' && c <= '9') { res = res * 10 + c - '0'; c = System.in.read(); } return res; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return -1; } }