結果

問題 No.361 門松ゲーム2
ユーザー threepipes_sthreepipes_s
提出日時 2016-04-17 23:17:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 2,838 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 80,388 KB
実行使用メモリ 54,288 KB
最終ジャッジ日時 2024-04-15 02:26:42
合計ジャッジ時間 5,388 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
50,296 KB
testcase_01 AC 51 ms
50,400 KB
testcase_02 AC 51 ms
50,588 KB
testcase_03 AC 51 ms
50,592 KB
testcase_04 AC 53 ms
50,540 KB
testcase_05 AC 51 ms
50,520 KB
testcase_06 AC 51 ms
50,484 KB
testcase_07 AC 51 ms
50,048 KB
testcase_08 AC 53 ms
50,576 KB
testcase_09 AC 55 ms
50,032 KB
testcase_10 AC 53 ms
50,564 KB
testcase_11 AC 53 ms
50,400 KB
testcase_12 AC 55 ms
50,184 KB
testcase_13 AC 54 ms
50,464 KB
testcase_14 AC 159 ms
53,812 KB
testcase_15 AC 78 ms
51,668 KB
testcase_16 AC 143 ms
53,716 KB
testcase_17 AC 127 ms
53,532 KB
testcase_18 AC 94 ms
53,004 KB
testcase_19 AC 112 ms
53,168 KB
testcase_20 AC 80 ms
51,720 KB
testcase_21 AC 130 ms
53,228 KB
testcase_22 AC 193 ms
54,288 KB
testcase_23 AC 84 ms
51,936 KB
testcase_24 AC 85 ms
52,060 KB
testcase_25 AC 93 ms
53,268 KB
testcase_26 AC 137 ms
53,656 KB
testcase_27 AC 135 ms
53,844 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