結果
問題 | No.2375 watasou and hibit's baseball |
ユーザー |
![]() |
提出日時 | 2023-07-07 22:14:46 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 285 ms / 2,000 ms |
コード長 | 1,570 bytes |
コンパイル時間 | 2,356 ms |
コンパイル使用メモリ | 77,296 KB |
実行使用メモリ | 52,608 KB |
最終ジャッジ日時 | 2024-07-21 18:20:28 |
合計ジャッジ時間 | 10,909 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
import java.util.Scanner;public class Main {public static void main(String[] args) throws Exception {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int a = sc.nextInt();int b = sc.nextInt();int[] x = new int[n];int[] y = new int[n];int[] k = new int[n];for (int i = 0; i < n; i++) {x[i] = sc.nextInt();y[i] = sc.nextInt();k[i] = sc.nextInt();}sc.close();int[][] d = new int[n][n];for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {d[i][j] = Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j]);d[j][i] = d[i][j];}}int n2 = 1 << n;boolean[][][] dp = new boolean[n2][n][n];for (int j = 0; j < n; j++) {for (int j2 = 0; j2 < n; j2++) {if (j == j2) {continue;}if (a <= d[j][j2] || b <= Math.abs(k[j] - k[j2])) {dp[(1 << j) | 1 << j2][j][j2] = true;}}}for (int i = 1; i < n2; i++) {for (int j = 0; j < n; j++) {for (int j2 = 0; j2 < n; j2++) {if (dp[i][j][j2]) {for (int j3 = 0; j3 < n; j3++) {if ((i >> j3 & 1) == 0) {int ni = i | (1 << j3);if (b <= Math.abs(k[j3] - k[j2])) {dp[ni][j2][j3] = true;}if (a <= d[j3][j2] + d[j3][j]) {dp[ni][j2][j3] = true;}}}}}}}int ans = 1;for (int i = 0; i < n2; i++) {for (int j = 0; j < n; j++) {for (int j2 = 0; j2 < n; j2++) {if (dp[i][j][j2]) {ans = Math.max(ans, Integer.bitCount(i));}}}}System.out.println(ans);}}