結果
| 問題 |
No.8063 幅優先探索
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-01 22:24:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 629 bytes |
| コンパイル時間 | 750 ms |
| コンパイル使用メモリ | 76,032 KB |
| 実行使用メモリ | 9,472 KB |
| 最終ジャッジ日時 | 2024-06-27 11:34:38 |
| 合計ジャッジ時間 | 1,303 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main()
| ^~~~
ソースコード
#include<iostream>
#include<queue>
using namespace std;
int R,C,sx,sy,gx,gy;
string s[1000];
int d[1000][1000];
int dx[4]={0,1,0,-1};
main()
{
cin>>R>>C>>sx>>sy>>gx>>gy;
for(int i=0;i<R;i++)cin>>s[i];
for(int i=0;i<R;i++)for(int j=0;j<C;j++)d[i][j]=1e9;
sx--,sy--,gx--,gy--;
d[sx][sy]=0;
queue<pair<int,int> >P;
P.push(make_pair(sx,sy));
while(!P.empty())
{
int x=P.front().first,y=P.front().second;
P.pop();
for(int r=0;r<4;r++)
{
int tx=x+dx[r],ty=y+dx[r^1];
if(tx<0||ty<0||tx>=R||ty>=C||d[tx][ty]<=d[x][y]+1)continue;
d[tx][ty]=d[x][y]+1;
P.push(make_pair(tx,ty));
}
}
cout<<d[gx][gy]<<endl;
}