結果

問題 No.361 門松ゲーム2
ユーザー rn4rurn4ru
提出日時 2016-04-18 00:59:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,032 bytes
コンパイル時間 2,400 ms
コンパイル使用メモリ 79,408 KB
実行使用メモリ 65,484 KB
最終ジャッジ日時 2024-04-15 03:11:39
合計ジャッジ時間 8,383 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
54,080 KB
testcase_01 AC 125 ms
54,088 KB
testcase_02 AC 109 ms
53,008 KB
testcase_03 AC 119 ms
54,176 KB
testcase_04 AC 122 ms
54,180 KB
testcase_05 AC 125 ms
54,240 KB
testcase_06 WA -
testcase_07 AC 126 ms
54,120 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 148 ms
54,308 KB
testcase_13 WA -
testcase_14 AC 402 ms
62,088 KB
testcase_15 WA -
testcase_16 AC 299 ms
58,164 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 180 ms
55,916 KB
testcase_20 AC 157 ms
55,756 KB
testcase_21 WA -
testcase_22 AC 586 ms
65,484 KB
testcase_23 WA -
testcase_24 AC 174 ms
56,384 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 420 ms
60,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int L = scanner.nextInt();
		int D = scanner.nextInt();
		System.out.println(new Solver().solve(L, D));
	}
}

class Solver {

	public String solve(int l, int d) {
		if (win(l, d)) {
			return "kado";
		}
		return "matsu";
	}

	Map<Integer, Boolean> map = new HashMap<>();

	private boolean win(int l, final int d) {
		if (map.containsKey(l))
			return map.get(l);
		if (l <= 5) {
			map.put(l, false);
			return false;
		}

		for (int i = 1; i <= l; i++) {
			for (int j = 1; j <= l; j++) {
				int k = l - i - j;
				if (i <= 0 || j <= 0 || k <= 0)
					continue;
				if (i == j || i == k || j == k)
					continue;
				if (Math.max(i, Math.max(j, k)) - Math.min(i, Math.min(j, k)) > d)
					continue;

				if (!win(i, d) & !win(j, d) & !win(k, d)) {
					map.put(l, true);
					return true;
				}
			}
		}
		map.put(l, false);
		return false;
	}

}
0