結果

問題 No.165 四角で囲え!
ユーザー scachescache
提出日時 2015-05-27 11:34:06
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,827 bytes
コンパイル時間 3,808 ms
コンパイル使用メモリ 76,324 KB
実行使用メモリ 60,220 KB
最終ジャッジ日時 2023-09-20 15:33:53
合計ジャッジ時間 14,176 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 379 ms
57,684 KB
testcase_01 AC 124 ms
55,676 KB
testcase_02 AC 126 ms
56,036 KB
testcase_03 AC 129 ms
56,228 KB
testcase_04 AC 133 ms
55,820 KB
testcase_05 AC 437 ms
59,704 KB
testcase_06 AC 275 ms
57,248 KB
testcase_07 AC 126 ms
55,764 KB
testcase_08 WA -
testcase_09 AC 126 ms
55,720 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 499 ms
59,460 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 569 ms
59,508 KB
testcase_19 AC 607 ms
59,448 KB
testcase_20 AC 461 ms
57,680 KB
testcase_21 AC 553 ms
60,220 KB
testcase_22 AC 482 ms
59,336 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<ia.length;i++)
			cx[i] = Arrays.binarySearch(ia, x[i]);
		
		return cx;
	}
}
0