結果

問題 No.726 Tree Game
ユーザー 37zigen37zigen
提出日時 2018-08-24 22:00:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,197 bytes
コンパイル時間 2,176 ms
コンパイル使用メモリ 79,428 KB
実行使用メモリ 64,856 KB
最終ジャッジ日時 2023-09-05 11:43:53
合計ジャッジ時間 7,382 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
64,232 KB
testcase_01 AC 158 ms
64,812 KB
testcase_02 AC 157 ms
64,580 KB
testcase_03 AC 154 ms
64,548 KB
testcase_04 AC 152 ms
64,856 KB
testcase_05 AC 150 ms
64,748 KB
testcase_06 AC 159 ms
64,264 KB
testcase_07 AC 146 ms
64,796 KB
testcase_08 AC 155 ms
64,452 KB
testcase_09 AC 146 ms
64,456 KB
testcase_10 AC 148 ms
64,748 KB
testcase_11 AC 157 ms
64,388 KB
testcase_12 AC 154 ms
64,448 KB
testcase_13 AC 145 ms
64,748 KB
testcase_14 AC 152 ms
64,760 KB
testcase_15 AC 158 ms
64,232 KB
testcase_16 AC 147 ms
64,548 KB
testcase_17 AC 160 ms
64,552 KB
testcase_18 AC 154 ms
64,752 KB
testcase_19 AC 165 ms
64,780 KB
testcase_20 AC 157 ms
64,508 KB
testcase_21 AC 158 ms
62,572 KB
testcase_22 AC 182 ms
64,592 KB
testcase_23 AC 162 ms
64,456 KB
testcase_24 AC 171 ms
64,612 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) == 1 && dfs(dx, dy + 1, cnt) == 1) {
			return memo[cnt][dx][dy] = 0;
		} else {
			return memo[cnt][dx][dy] = 1;
		}
	}

	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