E - Lucky 7 Battle (atcoder.jp)
题意:
思路:
Code:
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int mxn=2e5+10;
const int mxe=1e6+10;
const int mod=1e9+7;
const int Inf=0x3f3f3f3f;
string s,x;
int N;
int dp[mxn][10];
void solve(){
cin>>N>>s>>x;
s=" "+s;
x=" "+x;
dp[N][0]=1;
for(int i=N;i;i--){
int d=s[i]-'0';
for(int j=0;j<7;j++){
if(x[i]=='T'){
if(dp[i][(j*10)%7]||dp[i][(j*10+d)%7]) dp[i-1][j]=1;
}else{
if(dp[i][(j*10)%7]&&dp[i][(j*10+d)%7]) dp[i-1][j]=1;
}
}
}
if(dp[0][0]!=0) cout<<"Takahashi"<<'\n';
else cout<<"Aoki"<<'\n';
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int __=1;//cin>>__;
while(__--)solve();return 0;
}