結果

問題 No.361 門松ゲーム2
ユーザー threepipes_sthreepipes_s
提出日時 2016-04-17 23:17:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 2,838 bytes
コンパイル時間 2,506 ms
コンパイル使用メモリ 81,016 KB
実行使用メモリ 41,200 KB
最終ジャッジ日時 2024-10-04 10:53:40
合計ジャッジ時間 5,520 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,988 KB
testcase_01 AC 52 ms
36,988 KB
testcase_02 AC 52 ms
36,988 KB
testcase_03 AC 51 ms
37,216 KB
testcase_04 AC 52 ms
37,124 KB
testcase_05 AC 52 ms
36,660 KB
testcase_06 AC 52 ms
37,272 KB
testcase_07 AC 51 ms
36,668 KB
testcase_08 AC 56 ms
37,268 KB
testcase_09 AC 57 ms
37,168 KB
testcase_10 AC 54 ms
37,044 KB
testcase_11 AC 53 ms
36,884 KB
testcase_12 AC 56 ms
36,788 KB
testcase_13 AC 56 ms
37,120 KB
testcase_14 AC 173 ms
39,996 KB
testcase_15 AC 76 ms
37,792 KB
testcase_16 AC 147 ms
40,400 KB
testcase_17 AC 126 ms
40,132 KB
testcase_18 AC 94 ms
39,088 KB
testcase_19 AC 114 ms
39,936 KB
testcase_20 AC 77 ms
38,328 KB
testcase_21 AC 150 ms
40,424 KB
testcase_22 AC 204 ms
41,200 KB
testcase_23 AC 79 ms
38,152 KB
testcase_24 AC 85 ms
38,524 KB
testcase_25 AC 97 ms
39,756 KB
testcase_26 AC 144 ms
40,108 KB
testcase_27 AC 141 ms
40,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
 
public class Main{
	public static void main(String[] args){
		try {(new Solve()).solve();}
		catch (NumberFormatException | IOException e) {e.printStackTrace();}
	}
}
 
class Solve{
	void solve() throws NumberFormatException, IOException{
		final ContestScanner in = new ContestScanner();
		ContestWriter out = new ContestWriter();
		int l = in.nextInt();
		int d = in.nextInt();
		dp = new int[l+1];
		Arrays.fill(dp, -1);
		System.out.println(dfs(l, d)==0?"matsu":"kado");
	}
	
	int[] dp;
	int dfs(int l, int d){
		if(l<6) return 0;
		if(dp[l]>=0) return dp[l];
		BitSet bs = new BitSet();
		for(int i=1; i<l; i++){
			int g1 = dfs(i, d);
			for(int j=i+2; j<=i+d; j++){
				int m = l-i-j;
				if(m<=i || m>=j) continue;
				int grundy = g1^dfs(j,d)^dfs(m, d);
				bs.set(grundy);
			}
		}
		return dp[l] = bs.nextClearBit(0);
	}
}

class MultiSet<T> extends HashMap<T, Integer>{
	@Override
	public Integer get(Object key){return containsKey(key)?super.get(key):0;}
	public void add(T key,int v){put(key,get(key)+v);}
	public void add(T key){put(key,get(key)+1);}
}
 
class ContestWriter{
	private PrintWriter out;
	public ContestWriter(String filename) throws IOException
	{out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));}
	public ContestWriter() throws IOException{out = new PrintWriter(System.out);}
	public void println(String str){out.println(str);}
	public void println(Object str){out.println(str);}
	public void print(String str){out.print(str);}
	public void close(){out.close();}
}
 
class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;
	public ContestScanner()throws FileNotFoundException 
	{reader=new BufferedReader(new InputStreamReader(System.in));}
	public ContestScanner(String filename)throws FileNotFoundException
	{reader=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
	public String nextToken()throws IOException{if(line==null||line.length<=idx){
	line=reader.readLine().trim().split(" ");idx=0;}return line[idx++];}
	public String readLine()throws IOException{return reader.readLine();}
	public long nextLong()throws IOException,NumberFormatException{return Long.parseLong(nextToken());}
	public int nextInt()throws NumberFormatException,IOException{return(int)nextLong();}
	public double nextDouble()throws NumberFormatException,IOException 
	{return Double.parseDouble(nextToken());}
}
0