結果

問題 No.323 yuki国
ユーザー simansiman
提出日時 2016-03-28 00:18:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 273 ms / 5,000 ms
コード長 1,607 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 78,560 KB
実行使用メモリ 9,836 KB
最終ジャッジ日時 2023-09-10 21:26:27
合計ジャッジ時間 3,921 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 148 ms
9,540 KB
testcase_09 AC 70 ms
9,512 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 67 ms
9,564 KB
testcase_14 AC 152 ms
9,556 KB
testcase_15 AC 61 ms
9,608 KB
testcase_16 AC 143 ms
9,624 KB
testcase_17 AC 74 ms
9,604 KB
testcase_18 AC 4 ms
5,492 KB
testcase_19 AC 111 ms
7,208 KB
testcase_20 AC 7 ms
9,584 KB
testcase_21 AC 273 ms
9,676 KB
testcase_22 AC 34 ms
9,780 KB
testcase_23 AC 264 ms
9,616 KB
testcase_24 AC 11 ms
9,592 KB
testcase_25 AC 84 ms
9,604 KB
testcase_26 AC 11 ms
9,544 KB
testcase_27 AC 193 ms
9,836 KB
testcase_28 AC 87 ms
9,596 KB
testcase_29 AC 87 ms
9,528 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>
#include <time.h>
#include <string>
#include <string.h>
#include <sstream>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;
const int DY[4] = {-1, 0, 0, 1};
const int DX[4] = { 0,-1, 1, 0};

struct Node {
  int y;
  int x;
  int val;

  Node(int y, int x, int val){
    this->y = y;
    this->x = x;
    this->val = val;
  }
};

int main(){
  int h, w;
  cin >> h >> w;
  int a, sy, sx;
  cin >> a >> sy >> sx;
  int b, gy, gx;
  cin >> b >> gy >> gx;
  char field[h][w];

  string line;
  for(int y = 0; y < h; y++){
    cin >> line;
    for(int x = 0; x < w; x++){
      field[y][x] = line[x];
    }
  }

  queue<Node> que;
  que.push(Node(sy, sx, a));
  int limit = 2500;
  bool checkList[h][w][limit];
  memset(checkList, false, sizeof(checkList));

  while(!que.empty()){
    Node node = que.front(); que.pop();
    int y = node.y;
    int x = node.x;
    int val = node.val;

    if(val == 0 || limit < val) continue;
    if(checkList[y][x][val]) continue;
    checkList[y][x][val] = true;

    if(val == b && y == gy && x == gx){
      cout << "Yes" << endl;
      return 0;
    }

    for(int i = 0; i < 4; i++){
      int ny = y + DY[i];
      int nx = x + DX[i];

      if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;

      if(field[ny][nx] == '*'){
        que.push(Node(ny, nx, val+1));
      }else{
        que.push(Node(ny, nx, val-1));
      }
    }
  }

  cout << "No" << endl;
  return 0;
}
0