結果

問題 No.726 Tree Game
ユーザー treeonetreeone
提出日時 2018-03-30 00:07:00
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,329 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 144,332 KB
実行使用メモリ 11,548 KB
最終ジャッジ日時 2023-09-08 06:54:47
合計ジャッジ時間 3,917 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,432 KB
testcase_01 AC 6 ms
11,336 KB
testcase_02 AC 5 ms
11,548 KB
testcase_03 AC 5 ms
11,320 KB
testcase_04 AC 5 ms
11,336 KB
testcase_05 AC 5 ms
11,432 KB
testcase_06 AC 6 ms
11,432 KB
testcase_07 AC 6 ms
11,352 KB
testcase_08 AC 6 ms
11,296 KB
testcase_09 AC 6 ms
11,440 KB
testcase_10 AC 6 ms
11,408 KB
testcase_11 AC 6 ms
11,360 KB
testcase_12 AC 6 ms
11,300 KB
testcase_13 AC 5 ms
11,344 KB
testcase_14 AC 5 ms
11,392 KB
testcase_15 AC 5 ms
11,328 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

const int MAX_N = 1010;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
void sieve(int n){
   int p = 0;
   for(int i = 0; i <= n; i++) is_prime[i] = true;
   is_prime[0] = is_prime[1] = false;
   for(int i = 2; i <= n; i++){
   if(is_prime[i]){
           prime[p++] = i;
           for(int j = 2*i; j <= n; j += i) is_prime[j] = false;
       }
   }
}

int h, w;
int dp[1010][1010];
int dy[2] = {1, 0};
int dx[2] = {0, 1};

bool calc(int y, int x){
    if(dp[y][x] != -1) return dp[y][x];
    if(!(y == h && x == w)){
        if(is_prime[y] || is_prime[x]) return dp[y][x] = true;
    }
    bool res = true;
    rep(i, 0, 2){
        int ny = y + dy[i];
        int nx = x + dx[i];
        res &= calc(ny, nx);
    }
    return dp[y][x] = !res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    sieve(1000);
    cin >> h >> w;
    rep(i, 0, 1010) rep(j, 0, 1010) dp[i][j] = -1;
    cout << (calc(h, w) ? "First" : "Second") << endl;
}
0