結果

問題 No.726 Tree Game
ユーザー 37zigen37zigen
提出日時 2018-08-24 21:51:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,195 bytes
コンパイル時間 2,402 ms
コンパイル使用メモリ 74,832 KB
実行使用メモリ 66,576 KB
最終ジャッジ日時 2023-09-05 11:30:54
合計ジャッジ時間 8,067 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
66,576 KB
testcase_01 AC 144 ms
64,380 KB
testcase_02 AC 157 ms
64,700 KB
testcase_03 WA -
testcase_04 AC 147 ms
64,520 KB
testcase_05 AC 148 ms
64,508 KB
testcase_06 AC 146 ms
62,532 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 163 ms
62,848 KB
testcase_10 AC 152 ms
64,832 KB
testcase_11 AC 150 ms
64,708 KB
testcase_12 AC 151 ms
64,564 KB
testcase_13 WA -
testcase_14 AC 151 ms
64,344 KB
testcase_15 AC 160 ms
64,504 KB
testcase_16 AC 158 ms
64,672 KB
testcase_17 AC 156 ms
64,340 KB
testcase_18 AC 168 ms
64,804 KB
testcase_19 AC 159 ms
64,840 KB
testcase_20 AC 171 ms
64,480 KB
testcase_21 AC 159 ms
64,328 KB
testcase_22 AC 171 ms
64,636 KB
testcase_23 AC 165 ms
64,576 KB
testcase_24 AC 170 ms
64,284 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, 0) == 1 ? "First" : "Second");
	}

	long X, Y;

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

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

	int[][][] memo = new int[2][1000][1000];
	{
		for (int i = 0; i < memo.length; ++i)
			for (int j = 0; j < memo[i].length; ++j)
				for (int k = 0; k < memo[i][j].length; ++k)
					memo[i][j][k] = -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