結果

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

ソースコード

diff #
raw source code

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T; cin >> T;
    while(T--){
        int H,W; cin >> H >> W;
        int r,c; cin >> r >> c,r--,c--;

        auto g = [&](int h,int w) -> bool { //h*wに左上から右上へ進行した後の盤面で先手勝ち?.
            assert(h > 0 && w > 0);
            if(h > w) return true;
            else return false;
        };
        auto f = [&]() -> bool {
            if(r == 0) return false; //上へ進む.
            int ret = 0;
            if(c != 0){ //左へ進む.
                ret++;
                if(r == H-1){if(g(H,c)) ret--;}
                else if(c == W-1){
                    if(r != H-2){
                        if(W == 2) ret--;
                        else if(!g(W-2,r) || (r < H-3 && !g(W-2,H-3-r))) ret--; 
                    }  
                }
                else if(c == W-2) ret--;
                else{
                    if(r == H-2){
                        if(g(H,W-1-c)) ret--;
                    }
                    else{
                        //1<=r<=h-3 , 1<=c<=w-3
                        bool lose = false;
                        if(c != W-3 && !g(H-2,W-3-c)) lose = true;
                        if(r == H-3){
                            if(c == 1) lose = true;
                            else if(g(c-1,r)) lose = true;
                        }
                        else if(c > 2){
                            if(r == H-4) lose = true;
                            if(H > 4 && c > 3 && !g(H-4,c-3)) lose = true;
                        }
                        if(lose == false) ret--; 
                    }
                }
            }
            c = W-1-c; //右に進むは 反転して左に進む.
            if(c != 0){
                ret++;
                if(r == H-1){if(g(H,c)) ret--;}
                else if(c == W-1){
                    if(r != H-2){
                        if(W == 2) ret--;
                        else if(!g(W-2,r) || (r < H-3 && !g(W-2,H-3-r))) ret--; 
                    }  
                }
                else if(c == W-2) ret--;
                else{
                    if(r == H-2){
                        if(g(H,W-1-c))  ret--;
                    }
                    else{
                        bool lose = false;
                        if(c != W-3 && !g(H-2,W-3-c)) lose = true;
                        if(r == H-3){
                            if(c == 1) lose = true;
                            else if(g(c-1,r)) lose = true;
                        }
                        else if(c > 2){
                            if(r == H-4) lose = true;
                            if(H > 4 && c > 3 && !g(H-4,c-3)) lose = true;
                        }
                        if(lose == false) ret--; 
                    }
                }
            }
            c = W-1-c;
            if(ret == 0) return true;
            else return false;
        };
        bool win = false;
        win |= f(),swap(r,c),swap(H,W),c = W-1-c;
        win |= f(),swap(r,c),swap(H,W),c = W-1-c;
        win |= f(),swap(r,c),swap(H,W),c = W-1-c;
        win |= f(),swap(r,c),swap(H,W),c = W-1-c;
        if(win) cout << "Alice\n";
        else cout << "Bob\n";
    }
} 
0