結果

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1
 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
using ui = unsigned int;
 
constexpr int mod = 998244353;
constexpr int inf = 0x3f3f3f3f;
constexpr double EPS = 1e-8;
const double PI = acos(-1.0);

constexpr int N = 2e5 + 10;

int n, k, t;
char s[N];

bool ok(char c1, char c2, int k, int t, bool f){
  int lft = -1, rgt = n;
  per(i, k - 1, -1){
    if(s[i] == c2){
      lft = i;
      break;
    }
  }
  rep(i, k + 1, n){
    if(s[i] == c2){
      rgt = i;
      break;
    }
  }
  int len = rgt - lft - 1;
  if(len != 1){
    if(lft != -1 && k - lft <= t){
      int d = t - (k - lft);
      if(d % 2 == 0)  return 1;
    }
    if(rgt != n && rgt - k <= t){
      int d = t - (rgt - k);
      if(d % 2 == 0)  return 1;
    }
    return 0;
  }
  
  if(t % 2 == 0)  return 0;

  if(!f)  return 0;

  if(k && !ok(c2, c1, k - 1, t - 1, 0)) return 1;
  if(k+1<n && !ok(c2, c1, k + 1, t - 1, 0)) return 1;
  return 0;
}

void _main(){
  cin >> n >> k >> t;
  cin >> s;
  --k;
  if(s[k] == 'A'){
    if(ok('A', 'B', k, t, 1)){
      cout << "Alice\n";
    } else {
      cout << "Bob\n";
    }
  } else {
    if(ok('B', 'A', k, t, 1)){
      cout << "Bob\n";
    } else {
      cout << "Alice\n";
    }
  }
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  _main();
  return 0;
}
0