結果

問題 No.2375 watasou and hibit's baseball
ユーザー ks2mks2m
提出日時 2023-07-07 22:14:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,570 bytes
コンパイル時間 4,759 ms
コンパイル使用メモリ 74,188 KB
実行使用メモリ 66,668 KB
最終ジャッジ日時 2023-09-28 23:37:27
合計ジャッジ時間 13,131 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,152 KB
testcase_01 AC 128 ms
55,664 KB
testcase_02 AC 126 ms
55,704 KB
testcase_03 AC 195 ms
60,484 KB
testcase_04 AC 127 ms
55,912 KB
testcase_05 AC 126 ms
56,220 KB
testcase_06 AC 276 ms
65,216 KB
testcase_07 AC 125 ms
56,120 KB
testcase_08 AC 156 ms
57,792 KB
testcase_09 AC 121 ms
55,756 KB
testcase_10 AC 126 ms
55,920 KB
testcase_11 AC 148 ms
55,816 KB
testcase_12 AC 210 ms
64,932 KB
testcase_13 AC 172 ms
60,212 KB
testcase_14 AC 123 ms
55,740 KB
testcase_15 AC 172 ms
56,416 KB
testcase_16 AC 159 ms
56,032 KB
testcase_17 AC 223 ms
64,328 KB
testcase_18 AC 125 ms
56,160 KB
testcase_19 AC 124 ms
56,200 KB
testcase_20 AC 147 ms
55,896 KB
testcase_21 AC 214 ms
64,480 KB
testcase_22 AC 125 ms
56,564 KB
testcase_23 AC 182 ms
64,596 KB
testcase_24 AC 196 ms
64,324 KB
testcase_25 AC 122 ms
55,732 KB
testcase_26 AC 200 ms
64,736 KB
testcase_27 AC 209 ms
64,444 KB
testcase_28 AC 220 ms
65,008 KB
testcase_29 AC 210 ms
64,560 KB
testcase_30 AC 219 ms
64,804 KB
testcase_31 AC 215 ms
64,512 KB
testcase_32 AC 226 ms
66,668 KB
testcase_33 AC 213 ms
64,624 KB
testcase_34 AC 204 ms
64,748 KB
testcase_35 AC 219 ms
64,896 KB
testcase_36 AC 220 ms
65,000 KB
testcase_37 AC 223 ms
64,524 KB
testcase_38 AC 203 ms
64,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0