結果

問題 No.2646 Cycle Maze
ユーザー umezo
提出日時 2024-02-26 04:25:41
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,094 ms / 2,500 ms
コード長 1,067 bytes
コンパイル時間 3,207 ms
コンパイル使用メモリ 255,584 KB
実行使用メモリ 99,200 KB
最終ジャッジ日時 2024-09-29 11:34:05
合計ジャッジ時間 13,425 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int k=2520;
int dh[]={1,0,0,0,-1};
int dw[]={0,1,0,-1,0};

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int h,w,t;
  cin>>h>>w>>t;
  int sy,sx,gy,gx;
  cin>>sy>>sx>>gy>>gx;
  sy--,sx--,gy--,gx--;
  vector<string> S(h);
  rep(i,h) cin>>S[i];
  vector<vector<int>> A(h,vector<int>(w));
  rep(i,h) rep(j,w) A[i][j]=S[i][j]-'0';
  
  auto f=[&](int i,int j,int l){
    return (A[i][j]-l+k)%(A[i][j]+1);
  };
  
  vector<vector<vector<int>>> dp(h,vector<vector<int>>(w,vector<int>(t)));
  dp[sy][sx][0]=1;
  for(int l=0;l<t-1;l++){
    rep(i,h) rep(j,w){
      if(dp[i][j][l]==0) continue;
      rep(m,5){
        int ni=i+dh[m];
        int nj=j+dw[m];
        if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
        if(f(ni,nj,l+1)!=0) dp[ni][nj][l+1]=1;
      }
    }
  }
  rep(l,t){
    if(dp[gy][gx][l]){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;

  return 0;
}
0