結果

問題 No.3599 Queen Moving Query
コンテスト
ユーザー hiro1729
提出日時 2026-07-24 22:26:21
言語 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
結果
MLE  
実行時間 -
コード長 1,726 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,343 ms
コンパイル使用メモリ 344,660 KB
実行使用メモリ 1,306,708 KB
最終ジャッジ日時 2026-07-24 22:26:39
合計ジャッジ時間 5,933 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other MLE * 2 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main() {
    int H, W, sx, sy, Q, gx, gy, T;
    cin >> H >> W >> sx >> sy;
    sx--; sy--;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    vector<vector<pair<int, int>>> dist(H, vector<pair<int, int>>(W, make_pair(inf, inf)));
    dist[sx][sy].first = 0;
    deque<pair<int, int>> q;
    q.push_back({0, sx * W + sy});
    while (!q.empty()) {
        auto [b, xy] = q.front(); q.pop_front();
        int x = xy / W, y = xy % W;
        for (int dx = -1; dx <= 1; dx++) {
            for (int dy = -1; dy <= 1; dy++) {
                if (dx == 0 && dy == 0) continue;
                int nx = x, ny = y;
                while (true) {
                    nx += dx; ny += dy;
                    if (!(0 <= nx && nx < H && 0 <= ny && ny < W)) break;
                    if (S[nx][ny] == '#') break;
                    if (b == 0) {
                        if (dist[nx][ny].second <= dist[x][y].first) break;
                        dist[nx][ny].second = dist[x][y].first + 1;
                        q.push_back({1, nx * W + ny});
                    } else {
                        if (dist[nx][ny].first <= dist[x][y].second) break;
                        dist[nx][ny].first = dist[x][y].second + 1;
                        q.push_back({0, nx * W + ny});
                    }
                }
            }
        }
    }
    cin >> Q;
    while (Q--) {
        cin >> gx >> gy >> T;
        gx--; gy--;
        int di = (T % 2 == 0 ? dist[gx][gy].first : dist[gx][gy].second);
        if (di < inf && di <= T) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}
0