結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-15 01:04:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,074 bytes |
| コンパイル時間 | 2,168 ms |
| コンパイル使用メモリ | 201,168 KB |
| 最終ジャッジ日時 | 2025-01-10 10:59:44 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | int h,w; scanf("%d%d",&h,&w);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:32:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
32 | int sx,sy,gx,gy; scanf("%d%d%d%d",&sy,&sx,&gy,&gx); sx--; sy--; gx--; gy--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:34:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | rep(i,h) scanf("%s",B[i]);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using graph=vector<vector<int>>;
void add_edge(graph& G,int u,int v){
G[u].emplace_back(v);
G[v].emplace_back(u);
}
vector<int> distance(const graph& G,int s){
const int INF=INT_MAX;
int n=G.size();
vector<int> d(n,INF);
d[s]=0;
queue<int> Q; Q.emplace(s);
while(!Q.empty()){
int u=Q.front(); Q.pop();
for(int v:G[u]) if(d[v]==INF) {
d[v]=d[u]+1;
Q.emplace(v);
}
}
return d;
}
int main(){
int h,w; scanf("%d%d",&h,&w);
int sx,sy,gx,gy; scanf("%d%d%d%d",&sy,&sx,&gy,&gx); sx--; sy--; gx--; gy--;
char B[50][51];
rep(i,h) scanf("%s",B[i]);
graph G(h*w);
rep(i,h) rep(j,w) {
if(i<h-1 && abs(B[i][j]-B[i+1][j])<=1) add_edge(G,i*w+j,(i+1)*w+j);
if(j<w-1 && abs(B[i][j]-B[i][j+1])<=1) add_edge(G,i*w+j,i*w+(j+1));
if(i<h-2 && B[i][j]==B[i+2][j] && B[i][j]>B[i+1][j]) add_edge(G,i*w+j,(i+2)*w+j);
if(j<w-2 && B[i][j]==B[i][j+2] && B[i][j]>B[i][j+1]) add_edge(G,i*w+j,i*w+(j+2));
}
puts(distance(G,sy*w+sx)[gy*w+gx]<INT_MAX?"YES":"NO");
return 0;
}