結果

問題 No.165 四角で囲え!
ユーザー scachescache
提出日時 2015-05-27 11:50:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 610 ms / 5,000 ms
コード長 1,829 bytes
コンパイル時間 3,971 ms
コンパイル使用メモリ 76,416 KB
実行使用メモリ 60,188 KB
最終ジャッジ日時 2023-08-26 23:44:21
合計ジャッジ時間 14,243 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
59,332 KB
testcase_01 AC 131 ms
55,716 KB
testcase_02 AC 130 ms
56,088 KB
testcase_03 AC 129 ms
55,552 KB
testcase_04 AC 134 ms
55,944 KB
testcase_05 AC 519 ms
59,380 KB
testcase_06 AC 279 ms
57,080 KB
testcase_07 AC 128 ms
55,700 KB
testcase_08 AC 128 ms
55,940 KB
testcase_09 AC 127 ms
55,684 KB
testcase_10 AC 127 ms
55,576 KB
testcase_11 AC 433 ms
57,584 KB
testcase_12 AC 488 ms
58,992 KB
testcase_13 AC 508 ms
59,388 KB
testcase_14 AC 596 ms
58,880 KB
testcase_15 AC 610 ms
59,572 KB
testcase_16 AC 527 ms
59,656 KB
testcase_17 AC 498 ms
60,056 KB
testcase_18 AC 598 ms
59,756 KB
testcase_19 AC 497 ms
59,308 KB
testcase_20 AC 489 ms
59,076 KB
testcase_21 AC 542 ms
59,648 KB
testcase_22 AC 555 ms
60,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeSet;

public class Main0264 {

	public static void main(String[] args) {
		new Main0264();
	}

	public Main0264() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int b = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] p = new int[n];
		for(int i=0;i<n;i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			p[i] = sc.nextInt();
		}
		solve(n, b, x, y, p);
	}

	private void solve(int n, int b, int[] x, int[] y, int[] p) {
		int[] cx = compress(x);
		int[] cy = compress(y);

		int M = n+1;
		int[][] point = new int[M][M];
		int[][] count = new int[M][M];
		
		
		for(int i=0;i<n;i++){
			point[cy[i]+1][cx[i]+1] += p[i];
			count[cy[i]+1][cx[i]+1]++;
		}
		
		for(int i=0;i<M;i++){
			for(int j=1;j<M;j++){
				point[i][j] += point[i][j-1];
				count[i][j] += count[i][j-1];
			}
		}
		
		for(int i=1;i<M;i++){
			for(int j=0;j<M;j++){
				point[i][j] += point[i-1][j];
				count[i][j] += count[i-1][j];
			}
		}
		
		int res = 0;
		for(int i=1;i<M;i++){
			for(int j=1;j<M;j++){
				int ey = i;
				for(int k=M-1;k>=j;k--){
					while(ey<M){
						int cp = point[ey][k] + point[i-1][j-1] 
								- point[i-1][k] - point[ey][j-1];
						if(cp<=b){
							int cc = count[ey][k] + count[i-1][j-1] 
									- count[i-1][k] - count[ey][j-1];
							res = Math.max(res, cc);
							ey++;
						}else{
							break;
						}
					}
				}
			}
		}
				
		System.out.println(res);
	}
	
	private int[] compress(int[] x){
		TreeSet<Integer> set = new TreeSet<>();
		
		for(int v: x)
			set.add(v);
		
		Integer[] ia = new Integer[set.size()];
		set.toArray(ia);
		int[] cx = new int[x.length];
		for(int i=0;i<cx.length;i++)
			cx[i] = Arrays.binarySearch(ia, x[i]);
		
		return cx;
	}
}
0