結果
| 問題 | No.3599 Queen Moving Query |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-07-25 18:46:59 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,226 bytes |
| 記録 | |
| コンパイル時間 | 383 ms |
| コンパイル使用メモリ | 75,872 KB |
| 実行使用メモリ | 26,532 KB |
| 最終ジャッジ日時 | 2026-07-25 18:47:20 |
| 合計ジャッジ時間 | 8,435 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 WA * 13 RE * 1 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 3599.cc: No.3599 Queen Moving Query - yukicoder
*/
#include<cstdio>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_HW = 100000;
const int MAX_GN = MAX_HW << 4;
const int INF = 1 << 30;
const int dxs[] = {0, -1, -1, -1, 0, 1, 1, 1};
const int dys[] = {1, 1, 0, -1, -1, -1, 0, 1};
/* typedef */
using pii = pair<int,int>;
/* global variables */
char s[MAX_HW + 4];
int ds[MAX_GN];
/* subroutines */
/* main */
int main() {
int h, w, sx, sy;
scanf("%d%d%d%d", &h, &w, &sx, &sy);
sx--, sy--;
for (int i = 0; i < h; i++) scanf("%s", s + i * w);
int hw = h * w, gn = hw << 4;
fill(ds, ds + gn, INF);
priority_queue<pii> q;
for (int di = 0; di < 8; di++)
ds[((sx * w + sy) << 4) | (di << 1) | 0] = 0;
for (int di = 0; di < 8; di++) {
int vx = sx + dxs[di], vy = sy + dys[di];
if (vx >= 0 && vx < h && vy >= 0 && vy < w) {
int vp = vy * w + vx;
if (s[vp] == '.') {
int v = (vp << 4) | (di << 1) | 1;
ds[v] = 1, q.push({-1, v});
}
}
}
while (! q.empty()) {
auto [ud, u] = q.top(); q.pop();
ud = -ud;
if (ds[u] != ud) continue;
int up = (u >> 4), udi = ((u >> 1) & 7), uz = (u & 1);
int ux = up / w, uy = up % w;
int vz = (uz ^ 1);
for (int vdi = 0; vdi < 8; vdi++) {
int vx = ux + dxs[vdi], vy = uy + dys[vdi];
if (vx >= 0 && vx < h && vy >= 0 && vy < w) {
int vp = vx * w + vy;
if (s[vp] == '.') {
int v = (vp << 4) | (vdi << 1) | vz;
int vd = ud + (udi != vdi ? 1 : 0);
if (ds[v] > vd) ds[v] = vd, q.push({-vd, v});
if (udi == vdi) {
int v1 = v ^ 1;
if (ds[v1] > vd) ds[v1] = vd, q.push({-vd, v1});
}
}
}
}
}
int qn;
scanf("%d", &qn);
while (qn--) {
int gx, gy, t;
scanf("%d%d%d", &gx, &gy, &t);
gx--, gy--;
int gp = gx * w + gy;
int tp = (t & 1);
int d0 = INF, d1 = INF;
for (int di = 0; di < 8; di++) {
int g0 = (gp << 4) | (di << 1), g1 = (g0 | 1);
d0 = min(d0, ds[g0]);
d1 = min(d1, ds[g1]);
}
if ((tp == 0 && d0 <= t) || (tp == 1 && d1 <= t))
puts("Yes");
else
puts("No");
}
return 0;
}
tnakao0123