結果
| 問題 | No.3599 Queen Moving Query |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-24 22:39:18 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,724 bytes |
| 記録 | |
| コンパイル時間 | 2,337 ms |
| コンパイル使用メモリ | 343,508 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-07-24 22:39:26 |
| 合計ジャッジ時間 | 6,814 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 WA * 1 RE * 18 |
ソースコード
#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<int>> dist0(H, vector<int>(W, inf));
vector<vector<int>> dist1(H, vector<int>(W, inf));
dist0[sx][sy] = 0;
deque<pair<int, int>> q;
q.push_back({0, sx * W + sy});
while (!q.empty()) {
assert(q.size() <= 2 * H * W);
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 (dist1[nx][ny] <= dist0[x][y]) break;
dist1[nx][ny] = dist0[x][y] + 1;
q.push_back({1, nx * W + ny});
} else {
if (dist0[nx][ny] <= dist1[x][y]) break;
dist0[nx][ny] = dist1[x][y] + 1;
q.push_back({0, nx * W + ny});
}
}
}
}
}
cin >> Q;
while (Q--) {
cin >> gx >> gy >> T;
gx--; gy--;
int di = (T % 2 == 0 ? dist0[gx][gy] : dist1[gx][gy]);
if (di < inf && di <= T) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}