結果
問題 | No.165 四角で囲え! |
ユーザー | ぴろず |
提出日時 | 2015-03-12 23:51:15 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 702 ms / 5,000 ms |
コード長 | 1,947 bytes |
コンパイル時間 | 2,608 ms |
コンパイル使用メモリ | 78,140 KB |
実行使用メモリ | 61,020 KB |
最終ジャッジ日時 | 2023-08-26 23:31:12 |
合計ジャッジ時間 | 12,346 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 400 ms
58,960 KB |
testcase_01 | AC | 126 ms
56,264 KB |
testcase_02 | AC | 126 ms
55,984 KB |
testcase_03 | AC | 127 ms
55,416 KB |
testcase_04 | AC | 132 ms
56,348 KB |
testcase_05 | AC | 479 ms
58,916 KB |
testcase_06 | AC | 293 ms
57,280 KB |
testcase_07 | AC | 126 ms
55,720 KB |
testcase_08 | AC | 128 ms
55,768 KB |
testcase_09 | AC | 125 ms
53,660 KB |
testcase_10 | AC | 126 ms
56,068 KB |
testcase_11 | AC | 334 ms
59,164 KB |
testcase_12 | AC | 282 ms
59,088 KB |
testcase_13 | AC | 272 ms
58,768 KB |
testcase_14 | AC | 247 ms
58,952 KB |
testcase_15 | AC | 257 ms
59,104 KB |
testcase_16 | AC | 576 ms
59,224 KB |
testcase_17 | AC | 554 ms
59,012 KB |
testcase_18 | AC | 702 ms
61,020 KB |
testcase_19 | AC | 685 ms
59,016 KB |
testcase_20 | AC | 555 ms
59,808 KB |
testcase_21 | AC | 534 ms
59,784 KB |
testcase_22 | AC | 550 ms
59,504 KB |
ソースコード
package no165; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int b = sc.nextInt(); Point[] p = new Point[n]; for(int i=0;i<n;i++) { p[i] = new Point(sc.nextInt(),sc.nextInt(),sc.nextInt(),i); } Arrays.sort(p, (x,y) -> Integer.compare(x.x, y.x)); for(int i=1;i<n;i++) { p[i].xr = p[i-1].xr + ((p[i].x == p[i-1].x) ? 0 : 1); } int w = p[n-1].xr + 1; Arrays.sort(p, (x,y) -> Integer.compare(x.y, y.y)); for(int i=1;i<n;i++) { p[i].yr = p[i-1].yr + ((p[i].y == p[i-1].y) ? 0 : 1); } int h = p[n-1].yr + 1; int[][] count = new int[h+1][w+1]; int[][] point = new int[h+1][w+1]; for(int i=0;i<n;i++) { // System.out.println(p[i].xr + "," + p[i].yr); count[p[i].yr + 1][p[i].xr + 1]++; point[p[i].yr + 1][p[i].xr + 1] += p[i].p; } // System.out.println(Arrays.deepToString(point)); for(int i=1;i<=h;i++) { for(int j=0;j<=w;j++) { point[i][j] += point[i-1][j]; count[i][j] += count[i-1][j]; } } // System.out.println(Arrays.deepToString(point)); // for(int i=0;i<=h;i++) { // for(int j=1;j<w;j++) { // point[i][j] += point[i][j-1]; // count[i][j] += count[i][j-1]; // } // } int ans = 0; for(int i1=1;i1<=h;i1++) { for(int i2=i1;i2<=h;i2++) { int sump = 0; int sumc = 0; int j2 = 1; for(int j1=1;j1<=w;j1++) { while(j2 <= w && sump + point[i2][j2] - point[i1-1][j2] <= b) { sump += point[i2][j2] - point[i1-1][j2]; sumc += count[i2][j2] - count[i1-1][j2]; j2++; } ans = Math.max(ans, sumc); sump -= point[i2][j1] - point[i1-1][j1]; sumc -= count[i2][j1] - count[i1-1][j1]; } } } System.out.println(ans); } static class Point { int x,y,p,xr,yr,i; public Point(int x,int y,int p,int i) { this.x = x; this.y = y; this.p = p; this.i = i; } } }