题面
题解
所以博弈论的本质就是爆搜么……
//minamoto
#include<bits/stdc++.h>
#define R register
#define pi pair<int,int>
#define fi first
#define se second
#define IT vector<int>::iterator
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
using namespace std;
const int N=505;
int f[25][N][N],cnt[N*N],g[N][N];vector<int>v[N*N];
int S,T,k;char c[25];
bool dp(int p,int a,int b){
if(!p)return 0;
if(~f[p][a][b])return f[p][a][b];
if(p==1){
f[p][a][b]=((k==1)?(cnt[a*b]<=1):(a+b-2*S<=1));
return f[p][a][b];
}
if(dp(p-1,a,b))return f[p][a][b]=1;
if((p&1)==k){
int c=0;
for(IT it=v[a*b].begin();it!=v[a*b].end();++it)
if(!dp(p-1,*it,a*b/(*it)))++c;
f[p][a][b]=(c==1);
}else{
int c=0;
fp(i,S,((a+b)>>1))if(!dp(p-1,i,a+b-i))++c;
f[p][a][b]=(c==1);
}
return f[p][a][b];
}
bool ck(int a,int b){
if(~g[a][b])return g[a][b];
int c=0;
if(((T+2)&1)==k){
for(IT it=v[a*b].begin();it!=v[a*b].end();++it)
if(dp(T+1,*it,a*b/(*it))&&!dp(T,*it,a*b/(*it)))++c;
}else{
fp(i,S,((a+b)>>1))
if(dp(T+1,i,a+b-i)&&!dp(T,i,a+b-i))++c;
}
g[a][b]=(c==1);
return g[a][b];
}
pi solve(){
memset(f,-1,sizeof(f));
memset(g,-1,sizeof(g));
memset(cnt,0,sizeof(cnt));
fp(i,S*S,500*500){
int t=sqrt(i);v[i].clear();
fp(j,S,t)if(i%j==0)++cnt[i],v[i].push_back(j);
}
fp(s,S+S,1000)fp(i,S,500){
if(i>s)break;
fp(j,i,s-i){
if(i+j>s)break;
if(dp(T+1,i,j)&&!dp(T,i,j)&&ck(i,j))return pi(i,j);
}
}
}
int main(){
freopen("guess25.in","r",stdin);
scanf("%d%s%d",&S,c+1,&T);
k=(c[1]=='A');
pi ans=solve();
printf("%d %d
",ans.fi,ans.se);
return 0;
}