結果

問題 No.124 門松列(3)
ユーザー kotatsugamekotatsugame
提出日時 2020-02-27 19:55:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 945 bytes
コンパイル時間 707 ms
コンパイル使用メモリ 76,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 17:02:23
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 4 ms
6,940 KB
testcase_29 AC 4 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
}
0