結果

問題 No.3599 Queen Moving Query
コンテスト
ユーザー Rubikun
提出日時 2026-07-24 21:48:55
言語 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
結果
TLE  
実行時間 -
コード長 2,318 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,247 ms
コンパイル使用メモリ 220,060 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2026-07-24 21:51:01
合計ジャッジ時間 15,705 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=15<<26;

ll dis[2][MAX];
int mask[2][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll H,W,sh,sw;cin>>H>>W>>sh>>sw;sh--;sw--;
    vst S(H);
    for(int i=0;i<H;i++){
        cin>>S[i];
    }
    for(int q=0;q<2;q++){
        for(int i=0;i<H*W;i++){
            dis[q][i]=INF;
        }
    }
    queue<pii> Q;
    Q.push(mp(0,sh*W+sh));
    dis[0][sh*W+sh]=0;
    while(!Q.empty()){
        auto [t,po]=Q.front();Q.pop();
        int h=po/W,w=po%W;
        for(int dh=-1;dh<=1;dh++){
            for(int dw=-1;dw<=1;dw++){
                if(dh==0&&dw==0) continue;
                int z=(dh+1)*3+(dw+1);
                int toh=h,tow=w;
                while(1){
                    toh+=dh;
                    tow+=dw;
                    if(toh<0||toh>=H||tow<0||tow>=W||S[toh][tow]=='#') break;
                    if(dis[t^1][toh*W+tow]==dis[t][po]+1&&(mask[t^1][toh*W+tow]&(1<<z))) break;
                    if(dis[t^1][toh*W+tow]<dis[t][po]+1) break;
                    if(chmin(dis[t^1][toh*W+tow],dis[t][po]+1)){
                        mask[t^1][toh*W+tow]|=(1<<z);
                        Q.push(mp(t^1,toh*W+tow));
                    }
                }
            }
        }
    }
    
    int QQ;cin>>QQ;
    while(QQ--){
        int h,w,t;cin>>h>>w>>t;
        h--;w--;
        if(dis[t&1][h*W+w]<=t) cout<<"Yes\n";
        else cout<<"No\n";
    }
}


0