結果

問題 No.726 Tree Game
ユーザー 37zigen37zigen
提出日時 2018-08-24 21:41:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,026 bytes
コンパイル時間 2,713 ms
コンパイル使用メモリ 74,280 KB
実行使用メモリ 62,216 KB
最終ジャッジ日時 2023-09-05 11:16:13
合計ジャッジ時間 6,966 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
60,256 KB
testcase_01 AC 144 ms
60,420 KB
testcase_02 AC 144 ms
59,968 KB
testcase_03 WA -
testcase_04 AC 153 ms
60,196 KB
testcase_05 AC 148 ms
60,708 KB
testcase_06 AC 149 ms
60,208 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 147 ms
60,676 KB
testcase_11 AC 150 ms
59,988 KB
testcase_12 AC 152 ms
60,240 KB
testcase_13 WA -
testcase_14 AC 148 ms
60,204 KB
testcase_15 AC 150 ms
60,276 KB
testcase_16 AC 146 ms
60,320 KB
testcase_17 AC 155 ms
60,440 KB
testcase_18 WA -
testcase_19 AC 157 ms
60,200 KB
testcase_20 AC 158 ms
60,144 KB
testcase_21 AC 157 ms
60,276 KB
testcase_22 AC 167 ms
60,300 KB
testcase_23 AC 162 ms
58,576 KB
testcase_24 AC 155 ms
60,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		X = sc.nextLong();
		Y = sc.nextLong();
		System.out.println(dfs(0, 0) == 1 ? "First" : "Second");
	}

	long X, Y;

	// memo[i][j]=1 勝ち
	// memo[i][j]=0 負け

	int dfs(int dx, int dy) {
		if (memo[dx][dy] != -1)
			return memo[dx][dy];
		if (isPrime(X + dx) || isPrime(Y + dy))
			return memo[dx][dy] = 1;
		if (dfs(dx + 1, dy) == 0 || dfs(dx, dy + 1) == 0) {
			return memo[dx][dy] = 1;
		} else {
			return memo[dx][dy] = 0;
		}
	}

	int[][] memo = new int[1000][1000];
	{
		for (int i = 0; i < memo.length; ++i)
			for (int j = 0; j < memo[i].length; ++j)
				memo[i][j] = -1;
	}

	boolean isPrime(long a) {
		if (a == 1)
			return false;
		for (long i = 2; i * i <= a; ++i) {
			if (a % i == 0)
				return false;
		}
		return true;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0