結果
問題 | No.165 四角で囲え! |
ユーザー | tenten |
提出日時 | 2021-11-10 12:57:50 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,778 bytes |
コンパイル時間 | 3,132 ms |
コンパイル使用メモリ | 79,876 KB |
実行使用メモリ | 81,168 KB |
最終ジャッジ日時 | 2024-11-20 23:19:32 |
合計ジャッジ時間 | 81,247 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 70 ms
77,744 KB |
testcase_02 | AC | 70 ms
42,592 KB |
testcase_03 | AC | 55 ms
78,240 KB |
testcase_04 | AC | 55 ms
78,144 KB |
testcase_05 | TLE | - |
testcase_06 | AC | 1,766 ms
81,168 KB |
testcase_07 | AC | 55 ms
42,500 KB |
testcase_08 | AC | 54 ms
79,404 KB |
testcase_09 | AC | 55 ms
50,460 KB |
testcase_10 | AC | 55 ms
50,412 KB |
testcase_11 | TLE | - |
testcase_12 | AC | 2,971 ms
40,828 KB |
testcase_13 | AC | 2,242 ms
40,068 KB |
testcase_14 | AC | 1,561 ms
40,484 KB |
testcase_15 | AC | 1,956 ms
40,496 KB |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
ソースコード
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(); } }