結果
問題 | No.361 門松ゲーム2 |
ユーザー |
![]() |
提出日時 | 2016-04-17 23:37:29 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 357 ms / 2,000 ms |
コード長 | 903 bytes |
コンパイル時間 | 1,873 ms |
コンパイル使用メモリ | 78,176 KB |
実行使用メモリ | 58,064 KB |
最終ジャッジ日時 | 2024-10-04 11:03:22 |
合計ジャッジ時間 | 7,518 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
package no361;import java.util.HashSet;import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int l = sc.nextInt();int d = sc.nextInt();System.out.println(kadoWins(l, d) ? "kado" : "matsu");}public static boolean kadoWins(int l,int d) {int[] grundy = new int[l+1];for(int i=1;i<=l;i++) {// System.out.println(i + ":");HashSet<Integer> hs = new HashSet<>();for(int l1=1;l1<=i;l1++) {for(int l2=l1+1;l2<=i;l2++) {int l3 = i - l1 - l2;if (l3 <= l2 || l3 - l1 > d) {continue;}// System.out.println(l1 + "," + l2 + "," + l3);hs.add(grundy[l1] ^ grundy[l2] ^ grundy[l3]);}}for(int g=0;;g++) {if (!hs.contains(g)) {grundy[i] = g;break;}}}// System.out.println(Arrays.toString(grundy));return grundy[l] != 0;}}