結果
| 問題 |
No.2476 Knight Game
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2023-09-16 16:34:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,263 bytes |
| コンパイル時間 | 2,078 ms |
| コンパイル使用メモリ | 199,556 KB |
| 最終ジャッジ日時 | 2025-02-16 23:00:29 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | RE * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const char newl = '\n';
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
vector<T> ts(n);
for(size_t i=0;i<n;i++) cin>>ts[i];
return ts;
}
template<typename F>
struct FixPoint : F{
FixPoint(F&& f):F(forward<F>(f)){}
template<typename... Args>
decltype(auto) operator()(Args&&... args) const{
return F::operator()(*this,forward<Args>(args)...);
}
};
template<typename F>
inline decltype(auto) MFP(F&& f){
return FixPoint<F>{forward<F>(f)};
}
//INSERT ABOVE HERE
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int T;
cin>>T;
while(T--){
int h,w;
cin>>h>>w;
using ll = long long;
using T = tuple<ll, int, int>;
map<T, int> memo;
int di[]={+1,+1,-1,-1,+2,+2,-2,-2};
int dj[]={+2,-2,+2,-2,+1,-1,+1,-1};
auto get_bit=[&](int i,int j){return 1LL<<(i*w+j);};
auto dfs=MFP([&](auto dfs,ll bit,int i,int j)->int{
if(memo.count(T(bit,i,j))) return memo.at(T(bit,i,j));
int& res=memo[T(bit,i,j)];
res=0;
for(int k=0;k<8;k++){
int ni=i+di[k];
int nj=j+dj[k];
if(0<=ni and ni<h and 0<=nj and nj<w){
ll nbit=bit|get_bit(ni,nj);
if(nbit==bit) continue;
res|=!dfs(nbit,ni,nj);
}
if(res) return res;
}
return res;
});
auto calc=[&](int r,int c)->int{
assert(h<=w);
if(h>w) swap(h,w),swap(r,c);
if(h==1) return 0;
if(h==2){
int lf=c/2;
int rg=(w-1-c)/2;
return (lf%2==1 or rg%2==1);
}
if(h%2==0) return 1;
if(w%2==0) return 1;
return (r+c)%2;
};
if(0){
for(int i=0;i<h;i++){
for(int j=0;j<w;j++)
cout<<dfs(get_bit(i,j),i,j);
cout<<endl;
}
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
assert(dfs(get_bit(i,j),i,j)==calc(i,j));
continue;
}
int r,c;
cin>>r>>c;
r--;c--;
cout<<(calc(r,c)?"Alice":"Bob")<<newl;
}
return 0;
}
beet