結果
| 問題 |
No.726 Tree Game
|
| コンテスト | |
| ユーザー |
ゆにぽけ
|
| 提出日時 | 2024-03-06 05:19:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,874 bytes |
| コンパイル時間 | 1,506 ms |
| コンパイル使用メモリ | 134,380 KB |
| 最終ジャッジ日時 | 2025-02-20 01:13:26 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 6 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
bool MillerRabin(long long N)
{
if(N <= 1) return false;
if(N == 2) return true;
if(N % 2 == 0) return false;
vector<long long> A;
if(N < 4759123141LL)
{
A = {2,7,61};
}
else
{
A = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
}
auto mult = [&N](long long x,long long y) -> long long
{
return (__int128_t) x * y % N;
};
auto mod_pow = [&mult](long long p,long long n) -> long long
{
long long res = 1;
while(n)
{
if(n & 1) res = mult(res,p);
n >>= 1;
p = mult(p,p);
}
return res;
};
long long S = 0,D = N - 1;
while(D % 2 == 0)
{
S++;
D >>= 1;
}
for(const long long &a : A)
{
if(N <= a) return true;
long long t;
long long x = mod_pow(a,D);
if(x == 1);
else
{
for(t = 0;t < S;t++)
{
if(x == N - 1) break;
x = mult(x,x);
}
if(t == S) return false;
}
}
return true;
}
void Main()
{
int Y,X;
cin >> Y >> X;
map<pair<int,int>,int> dp;
auto dfs = [&](auto dfs,int y,int x) -> int
{
if(MillerRabin(y) || MillerRabin(x))
{
return 1;
}
pair<int,int> P = make_pair(y,x);
if(dp.find(P) != dp.end())
{
return dp[P];
}
if(!dfs(dfs,y + 1,x) || !dfs(dfs,y,x + 1))
{
return dp[P] = 1;
}
return dp[P] = 0;
};
cout << (dfs(dfs,Y,X) ? "First\n" : "Second\n");
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
/* cin >> tt; */
while(tt--) Main();
}
ゆにぽけ