結果

問題 No.165 四角で囲え!
ユーザー tentententen
提出日時 2021-11-10 12:57:50
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,778 bytes
コンパイル時間 2,543 ms
コンパイル使用メモリ 79,364 KB
実行使用メモリ 60,196 KB
最終ジャッジ日時 2024-05-01 00:27:25
合計ジャッジ時間 15,189 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int bb = sc.nextInt();
        int[] xs = new int[n];
        int[] ys = new int[n];
        int[] ps = new int[n];
        TreeMap<Integer, Integer> compX = new TreeMap<>();
        TreeMap<Integer, Integer> compY = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
            ys[i] = sc.nextInt();
            ps[i] = sc.nextInt();
            compX.put(xs[i], null);
            compY.put(ys[i], null);
        }
        int xIdx = 1;
        for (int x : compX.keySet()) {
            compX.put(x, xIdx);
            xIdx++;
        }
        int yIdx = 1;
        for (int x : compY.keySet()) {
            compY.put(x, yIdx);
            yIdx++;
        }
        int[][] field = new int[xIdx][yIdx];
        int[][] counts = new int[xIdx][yIdx];
        for (int i = 0; i < n; i++) {
            field[compX.get(xs[i])][compY.get(ys[i])] = ps[i];
            counts[compX.get(xs[i])][compY.get(ys[i])] = 1;
        }
        for (int i = 1; i < xIdx; i++) {
            for (int j = 1; j < yIdx; j++) {
                field[i][j] += field[i - 1][j] + field[i][j - 1] - field[i - 1][j - 1];
                counts[i][j] += counts[i - 1][j] + counts[i][j - 1] - counts[i - 1][j - 1];
            }
        }
        int ans = 0;
        for (int a = 0; a < xIdx - 1; a++) {
            for (int b = a + 1; b < xIdx; b++) {
                for (int c = 0; c < yIdx - 1; c++) {
                    for (int d = c + 1; d < yIdx; d++) {
                        if (field[b][d] - field[a][d] - field[b][c] + field[a][c] <= bb) {
                            ans = Math.max(ans, counts[b][d] - counts[a][d] - counts[b][c] + counts[a][c]);
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }
}
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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0