結果

問題 No.726 Tree Game
ユーザー mjkttenhoubotmjkttenhoubot
提出日時 2018-08-24 23:22:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,009 ms / 2,000 ms
コード長 3,312 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 178,396 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 14:23:50
合計ジャッジ時間 6,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 1,009 ms
4,376 KB
testcase_22 AC 1,007 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 1,008 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define scnaf scanf
#define sacnf scanf
#define sancf scanf

#define ln '\n'
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type,x) type x;cin >> x
#define MP(a,b) make_pair((a),(b))
#define PB(a) push_back((a))
#define P(p) cout << (p) << endl;
#define S(s) cin >> (s);
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i))
#define rep(i,n) reps(i,0,(n))
#define rreps(i,a,b) for(int (i)=(a); (i)>=(b); --(i))
#define rrep(i,n) reprt(i,n,0)

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
const double EPS = 1e-9;
const double PI  = acos(-1.0);

ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

void Yes(bool f) {if(f){P("Yes");}else{P("No")}}
void yES(bool f) {if(f){P("yES");}else{P("nO")}}
void Yay(bool f) {if(f){P("Yay!");}else{P(":(")}}

void ll2str(const ll &n,string &s) { stringstream stream; stream << n; stream >> s; }
void int2str(const int &n,string &s) { stringstream stream; stream << n; stream >> s; }
void str2ll(ll &n,const string &s) { stringstream stream(s); stream >> n; }
void str2int(int &n,const string &s) { stringstream stream(s); stream >> n; }

/*********TEMPLATE**********/

clock_t start = clock();
ll dif_x, dif_y;
map<int,bool> prime;

bool isPrime(ll num) {
  if (num==1) return false;
  if (num==2) return true;
  if (num%2==0) return false;
  for (ll i=3; i<sqrt(num)+1; i+=2) {
    if (num%i==0) return false;
  }
  return true;
}

bool simulate(ll x, ll y, ll teban) {
  if ((double)(clock()-start)/CLOCKS_PER_SEC>1) {
    if ((dif_x+dif_y)%2==1) {
      P("First");
    } else {
      P("Second");
    }
    exit(0);
  }
  if (prime.count(x)==0) prime[x]=isPrime(x);
  if (prime.count(y)==0) prime[y]=isPrime(y);
  if (prime.count(x+1)==0) prime[x+1]=isPrime(x+1);
  if (prime.count(y+1)==0) prime[y+1]=isPrime(y+1);
  bool go_x = prime[x+1] or prime[y];
  bool go_y = prime[x] or prime[y+1];
  if (go_x and go_y) {
    return teban%2==1;
  } else if (go_x) {
    return simulate(x,y+1,teban+1);
  } else if (go_y) {
    return simulate(x+1,y,teban+1);
  } else {
    if ((simulate(x+1,y,teban+1)==(teban%2==0)) or (simulate(x,y+1,teban+1)==(teban%2==0))) {
      return teban%2==0;
    } else {
      return teban%2==1;
    }
  }
}

signed main() {

  ll x,y;
  cin >> x >> y;
  ll x_n=x+1,y_n=y+1;
  while (1) {
    if (isPrime(x_n)) break;
    ++x_n;
  }
  while (1) {
    if (isPrime(y_n)) break;
    ++y_n;
  }
  dif_x = x_n - x;
  dif_y = y_n - y;
  if (simulate(x,y,0)) {
    P("First");
  } else {
    P("Second")
  }
}
0