結果

問題 No.8 N言っちゃダメゲーム
ユーザー core123core123
提出日時 2019-04-17 16:50:20
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,377 bytes
コンパイル時間 4,045 ms
コンパイル使用メモリ 79,152 KB
実行使用メモリ 65,352 KB
最終ジャッジ日時 2023-10-22 07:29:30
合計ジャッジ時間 11,640 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,928 KB
testcase_01 AC 130 ms
57,432 KB
testcase_02 AC 132 ms
57,436 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.*;
import static java.lang.Math.*;
public class Main{
	public static void main(String... args){
		Scanner sc=new Scanner(System.in);
		int p=sc.nextInt();
		for(int pp=0;pp<p;pp++){
			int n=sc.nextInt();
			int k=sc.nextInt();
			int[] grundy=new int[n+1];
			grundy[n-1]=0;
			for(int i=n-2;i>=0;i--){
				Set<Integer> set=new HashSet<>();
				for(int j=1;i+j<=n&&j<=k;j++){
					int index=i+j;
					set.add(grundy[index]);
				}
				for(int j=0;j<set.size()+1;j++){
					if(!set.contains(j)){
						grundy[i]=j;
						break;
					}
				}
				
			}
			//put(Arrays.toString(grundy));
			if(grundy[0]>0){
				put("Win");
			}else{
				put("Lose");
			}
			
		}
		
	}
	public static class Pair{
		final int x,y;
		Pair(int x,int y){
			this.x=x;
			this.y=y;
		}
		@Override
		public String toString(){
			return String.format("Pair(%d,%d)",x,y);
		}
	}
	public static void print(Object object){
        System.out.print(object);
    }
    public static void put(Object object) {
        System.out.println(object);
    }
    public static void put(){
        System.out.println();
    }
 
    public static void print(String format,Object... args){
        System.out.print(String.format(format,args));
    }
    public static void put(String format,Object... args) {
        System.out.println(String.format(format,args));
    }
}
0