結果

問題 No.323 yuki国
ユーザー beetbeet
提出日時 2018-11-14 11:52:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 5,000 ms
コード長 1,137 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 208,600 KB
実行使用メモリ 13,508 KB
最終ジャッジ日時 2023-08-26 01:01:36
合計ジャッジ時間 7,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,216 KB
testcase_01 AC 5 ms
13,428 KB
testcase_02 AC 4 ms
13,216 KB
testcase_03 AC 8 ms
13,196 KB
testcase_04 AC 5 ms
13,212 KB
testcase_05 AC 5 ms
13,488 KB
testcase_06 AC 4 ms
13,220 KB
testcase_07 AC 4 ms
13,508 KB
testcase_08 AC 118 ms
13,324 KB
testcase_09 AC 119 ms
13,316 KB
testcase_10 AC 5 ms
13,292 KB
testcase_11 AC 4 ms
13,220 KB
testcase_12 AC 5 ms
13,436 KB
testcase_13 AC 118 ms
13,248 KB
testcase_14 AC 117 ms
13,252 KB
testcase_15 AC 37 ms
13,460 KB
testcase_16 AC 121 ms
13,352 KB
testcase_17 AC 161 ms
13,324 KB
testcase_18 AC 54 ms
13,316 KB
testcase_19 AC 98 ms
13,308 KB
testcase_20 AC 189 ms
13,300 KB
testcase_21 AC 204 ms
13,360 KB
testcase_22 AC 205 ms
13,304 KB
testcase_23 AC 212 ms
13,444 KB
testcase_24 AC 45 ms
13,484 KB
testcase_25 AC 43 ms
13,332 KB
testcase_26 AC 164 ms
13,304 KB
testcase_27 AC 159 ms
13,360 KB
testcase_28 AC 154 ms
13,248 KB
testcase_29 AC 164 ms
13,248 KB
testcase_30 AC 4 ms
13,288 KB
testcase_31 AC 5 ms
13,288 KB
testcase_32 AC 5 ms
13,276 KB
testcase_33 AC 5 ms
13,284 KB
testcase_34 AC 6 ms
13,212 KB
testcase_35 AC 4 ms
13,332 KB
testcase_36 AC 5 ms
13,292 KB
testcase_37 AC 5 ms
13,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 4050;
bool dp[MAX][50][50];
signed main(){
  Int h,w;
  cin>>h>>w;
  
  Int a,sy,sx;
  cin>>a>>sy>>sx;

  Int b,gy,gx;
  cin>>b>>gy>>gx;

  vector<string> st(h);
  for(Int i=0;i<h;i++) cin>>st[i];

  using T = tuple<Int, Int, Int>;
  queue<T> q;  
  memset(dp,0,sizeof(dp));
  
  dp[a][sy][sx]=1; 
  q.emplace(a,sy,sx);

  auto in=[&](Int y,Int x){return 0<=y&&y<h&&0<=x&&x<w;};
  auto check=[&](Int s){return 0<s&&s<MAX;}; 

  Int dy[]={0,0,1,-1};  
  Int dx[]={1,-1,0,0};
  
  while(!q.empty()){
    Int s,y,x;
    tie(s,y,x)=q.front();q.pop();
    for(Int k=0;k<4;k++){
      Int ny=y+dy[k],nx=x+dx[k];
      if(!in(ny,nx)) continue;

      Int ns=s+(st[ny][nx]=='.'?-1:1);
      if(!check(ns)) continue;

      if(dp[ns][ny][nx]) continue;      
      dp[ns][ny][nx]=1;
      q.emplace(ns,ny,nx);      
    }
  }
  
  cout<<(dp[b][gy][gx]?"Yes":"No")<<endl;
  return 0;
}
0