結果

問題 No.726 Tree Game
ユーザー treeonetreeone
提出日時 2018-03-30 00:06:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,361 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 166,204 KB
実行使用メモリ 19,940 KB
最終ジャッジ日時 2023-09-08 06:54:55
合計ジャッジ時間 7,924 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
    while(1){
        cin >> h >> w;
        rep(i, 0, 1010) rep(j, 0, 1010) dp[i][j] = -1;
        cout << (calc(h, w) ? "First" : "Second") << endl;
    }
}
0