結果

問題 No.2278 Time Bomb Game 2
ユーザー 沙耶花
提出日時 2023-04-21 22:17:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 3,580 ms
コンパイル使用メモリ 252,748 KB
最終ジャッジ日時 2025-02-12 11:53:21
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 70
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

bool win(string s,int T,int K){
	int N = s.size();
	bool f = false;
	{
		int c = K;
		while(c!=N){
			c++;
			if(c==N)break;
			if(s[c]!=s[K]){
				int diff = abs(c-K);
				if(diff<=T){
					if((T-diff)%2==0)f = true;
				}
				break;
			}
		}
	}
	{
		int c = K;
		while(c!=-1){
			c--;
			if(c==-1)break;
			if(s[c]!=s[K]){
				int diff = abs(c-K);
				if(diff<=T){
					if((T-diff)%2==0)f = true;
				}
				break;
			}
		}
	}
	return f;
}

int main(){
	
	int N,K,T;
	cin>>N>>K>>T;
	
	K--;
	string s;
	cin>>s;
	if(s==string(N,'A')){
		cout<<"Bob"<<endl;
		return 0;
	}
	if(s==string(N,'B')){
		cout<<"Alice"<<endl;
		return 0;
	}
	
	if((K+1==N||s[K+1]!=s[K]) && (K-1==-1||s[K-1]!=s[K])){
		if(T%2==0){
			if(s[K]=='B')cout<<"Alice"<<endl;
			else cout<<"Bob"<<endl;
			return 0;
		}
		if((K==0||win(s,T-1,K-1)) && (K==N-1||win(s,T-1,K+1))){
			if(s[K]=='B')cout<<"Alice"<<endl;
			else cout<<"Bob"<<endl;
		}
		else{
			if(s[K]=='A')cout<<"Alice"<<endl;
			else cout<<"Bob"<<endl;
		}
	}
	else{
		bool f = win(s,T,K);
		if(f){
			if(s[K]=='A')cout<<"Alice"<<endl;
			else cout<<"Bob"<<endl;
		}
		else{
			if(s[K]=='B')cout<<"Alice"<<endl;
			else cout<<"Bob"<<endl;
		}
	}
	
	return 0;
}
0