結果

問題 No.3599 Queen Moving Query
コンテスト
ユーザー tnakao0123
提出日時 2026-07-25 18:23:15
言語 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  
実行時間 -
コード長 1,858 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 331 ms
コンパイル使用メモリ 75,364 KB
実行使用メモリ 6,736 KB
最終ジャッジ日時 2026-07-25 18:23:27
合計ジャッジ時間 8,612 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 2 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- 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 * 2;
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 * 2;
  fill(ds, ds + gn, INF);
  int st = (sx * w + sy) << 1;
  ds[st] = 0;
  priority_queue<pii> q;
  q.push({0, st});

  while (! q.empty()) {
    auto [ud, u] = q.top(); q.pop();
    ud = -ud;
    if (ds[u] != ud) continue;

    int up = (u >> 1), uz = (u & 1);
    int ux = up / w, uy = up % w;
    int vz = (uz ^ 1), vd = ud + 1;
    
    for (int di = 0; di < 8; di++) {
      int dx = dxs[di], dy = dys[di];
      int vx = ux + dx, vy = uy + dy, z = 1;
      while (vx >= 0 && vx < h && vy >= 0 && vy < w) {
	int vp = vx * w + vy;
	if (s[vp] == '#') break;
	int v = (vp << 1) | vz;
	if (ds[v] > vd) ds[v] = vd, q.push({-vd, v});
	if (z > 1) {
	  int v1 = v ^ 1;
	  if (ds[v1] > vd) ds[v1] = vd, q.push({-vd, v1});
	}
	vx += dx, vy += dy, z++;
      }
    }
  }

  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 g0 = (gp << 1), g1 = (g0 | 1);
    int tp = (t & 1);
    //printf(" gx,gy=%d,%d t=%d: d0=%d d1=%d\n", gx, gy, t, ds[g0], ds[g1]);

    if ((tp == 0 && ds[g0] <= t) || (tp == 1 && ds[g1] <= t))
      puts("Yes");
    else
      puts("No");
  }
  
  return 0;
}

0