結果

問題 No.124 門松列(3)
ユーザー kotatsugame
提出日時 2020-02-27 19:55:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 945 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 76,924 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-13 15:59:58
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main()
      | ^~~~

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<queue>
using namespace std;
int W,H;
int dis[100][100][10],M[100][100];
bool ok(int a,int b,int c)
{
return a!=b&&b!=c&&c!=a&&(b>a&&b>c||b<a&&b<c);
}
int d[4]={1,0,-1};
main()
{
cin>>W>>H;
for(int i=0;i<H;i++)for(int j=0;j<W;j++)
{
cin>>M[i][j];
for(int I=0;I<10;I++)
{
dis[i][j][I]=114514;
}
}
dis[0][0][0]=0;
queue<pair<pair<int,int>,int> >P;
P.push(make_pair(make_pair(0,0),0));
while(!P.empty())
{
int x=P.front().first.first,y=P.front().first.second;
int a=P.front().second;
if(x==H-1&&y==W-1)
{
cout<<dis[x][y][a]<<endl;
return 0;
}
P.pop();
int b=M[x][y];
for(int r=0;r<4;r++)
{
int tx=x+d[r],ty=y+d[r^1];
if(tx<0||ty<0||tx>=H||ty>=W)continue;
int c=M[tx][ty];
if(a==0||ok(a,b,c))
{
int nxt=dis[x][y][a]+1;
if(nxt<dis[tx][ty][b])
{
dis[tx][ty][b]=nxt;
P.push(make_pair(make_pair(tx,ty),b));
}
}
}
}
cout<<-1<<endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0