結果

問題 No.361 門松ゲーム2
ユーザー rn4rurn4ru
提出日時 2016-04-18 00:52:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,046 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 78,832 KB
実行使用メモリ 61,548 KB
最終ジャッジ日時 2024-04-15 03:07:35
合計ジャッジ時間 7,288 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
54,132 KB
testcase_01 AC 111 ms
53,060 KB
testcase_02 AC 120 ms
53,896 KB
testcase_03 AC 123 ms
54,188 KB
testcase_04 AC 121 ms
54,140 KB
testcase_05 AC 121 ms
53,884 KB
testcase_06 WA -
testcase_07 AC 116 ms
54,100 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 112 ms
53,052 KB
testcase_13 WA -
testcase_14 AC 331 ms
60,564 KB
testcase_15 WA -
testcase_16 AC 181 ms
54,960 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 152 ms
56,264 KB
testcase_20 AC 137 ms
54,824 KB
testcase_21 WA -
testcase_22 AC 411 ms
61,548 KB
testcase_23 WA -
testcase_24 AC 162 ms
55,520 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 192 ms
56,640 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 - 2; i++) {
			for (int j = i + 1; j <= l - 1; 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