結果

問題 No.3606 Ice Grid Game
コンテスト
ユーザー tau1235
提出日時 2026-07-31 22:18:07
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 65 ms / 2,000 ms
+ 327µs
コード長 992 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,292 ms
コンパイル使用メモリ 341,080 KB
実行使用メモリ 42,864 KB
最終ジャッジ日時 2026-07-31 22:18:13
合計ジャッジ時間 4,310 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

void solve(){
  vector<int> dy={1,0,-1,0},dx={0,1,0,-1};
  int h,w,r,c;
  cin>>h>>w>>r>>c;
  vector<string> s(h+2,string(w+2,'#'));
  for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) s[i][j]='.';
  vector<pair<int,int>> vp={{r,c}};
  auto f=[&](int i,int j,int dir){
    while (true){
      int ni=i+dy[dir],nj=j+dx[dir];
      if (s[ni][nj]=='#') return;
      vp.push_back({ni,nj});
      s[i][j]='#';
      i=ni;j=nj;
    }
  };
  auto rec=[&](auto rec,int i,int j,int t)-> int {
    int ret=0;
    for (int dir=0;dir<4;dir++){
      if (s[i+dy[dir]][j+dx[dir]]=='#') continue;
      f(i,j,dir);
      auto [ni,nj]=vp.back();
      ret|=rec(rec,ni,nj,t^1)!=t;
      while (vp.back()!=pair{i,j}){
        auto [i2,j2]=vp.back();
        s[i2][j2]='.';
        vp.pop_back();
      }
    }
    return ret^t;
  };
  int ans=rec(rec,r,c,0);
  if (ans) cout<<"Alice\n";
  else cout<<"Bob\n";
}

int main(){
  int t;
  cin>>t;
  while (t--) solve();
}
0