結果

問題 No.2646 Cycle Maze
ユーザー tnakao0123
提出日時 2024-04-25 10:26:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,293 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 57,568 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-07 21:03:28
合計ジャッジ時間 4,358 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 47 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2646.cc:  No.2646 Cycle Maze - yukicoder
 */

#include<cstdio>
#include<queue>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_H = 200;
const int MAX_W = 200;
const int MAX_HW = MAX_H * MAX_W;
const int dxs[] = { 1, 0, -1, 0, 0 }, dys[] = { 0, -1, 0, 1, 0 };

/* typedef */

typedef queue<int> qi;

/* global variables */

char s[MAX_HW + 4];
bool ds[MAX_HW];

/* subroutines */

/* main */

int main() {
  int h, w, t, sy, sx, gy, gx;
  scanf("%d%d%d%d%d%d%d", &h, &w, &t, &sy, &sx, &gy, &gx);
  sy--, sx--, gy--, gx--;
  int hw = h * w, st = sy * w + sx, gl = gy * w + gx;

  for (int i = 0; i < h; i++) scanf("%s", s + i * w);

  qi uq;
  uq.push(st);
  int d = 0;

  while (d < t) {
    d++;
    fill(ds, ds + hw, false);
    qi vq;

    while (! uq.empty()) {
      int u = uq.front(); uq.pop();
      int uy = u / w, ux = u % w;

      for (int di = 0; di < 5; di++) {
	int vy = uy + dys[di], vx = ux + dxs[di], v = vy * w + vx;
	if (vy >= 0 && vy < h && vx >= 0 && vx < w && ! ds[v]) {
	  int av = (s[v] - '0');
	  int bv = (av - d) % (av + 1);
	  if (bv != 0) {
	    ds[v] = true;
	    vq.push(v);
	  }
	}
      }
    }

    if (ds[gl]) break;
    swap(uq, vq);
  }

  if (ds[gl]) puts("Yes");
  else puts("No");

  return 0;
}
0