結果

問題 No.323 yuki国
ユーザー siman
提出日時 2016-03-28 00:18:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 303 ms / 5,000 ms
コード長 1,607 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 79,168 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-06-28 12:30:18
合計ジャッジ時間 3,833 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

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