結果
| 問題 |
No.361 門松ゲーム2
|
| コンテスト | |
| ユーザー |
threepipes_s
|
| 提出日時 | 2016-04-17 23:17:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
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());}
}
threepipes_s