結果

問題 No.2646 Cycle Maze
ユーザー tnakao0123tnakao0123
提出日時 2024-04-25 12:15:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 371 ms / 2,500 ms
コード長 1,372 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 58,752 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 12:15:05
合計ジャッジ時間 4,051 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 9 ms
5,376 KB
testcase_27 AC 30 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 6 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 8 ms
5,376 KB
testcase_34 AC 21 ms
5,376 KB
testcase_35 AC 18 ms
5,376 KB
testcase_36 AC 11 ms
5,376 KB
testcase_37 AC 5 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 9 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 12 ms
5,376 KB
testcase_42 AC 7 ms
5,376 KB
testcase_43 AC 3 ms
5,376 KB
testcase_44 AC 8 ms
5,376 KB
testcase_45 AC 80 ms
5,376 KB
testcase_46 AC 74 ms
5,376 KB
testcase_47 AC 3 ms
5,376 KB
testcase_48 AC 45 ms
5,376 KB
testcase_49 AC 62 ms
5,376 KB
testcase_50 AC 155 ms
5,376 KB
testcase_51 AC 334 ms
5,376 KB
testcase_52 AC 371 ms
5,376 KB
testcase_53 AC 333 ms
5,376 KB
testcase_54 AC 346 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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);

  for (int d = 1; d < t && ! uq.empty(); 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);
	  }
	}
      }
    }
    //for (int i = 0; i < hw; i++) printf("%d", ds[i]); putchar('\n');

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

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

  return 0;
}
0