結果

問題 No.1283 Extra Fee
ユーザー kotatsugamekotatsugame
提出日時 2020-11-08 00:17:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 79,616 KB
実行使用メモリ 11,452 KB
最終ジャッジ日時 2024-04-27 23:37:31
合計ジャッジ時間 5,802 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 13 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 12 ms
5,376 KB
testcase_14 AC 49 ms
5,632 KB
testcase_15 AC 79 ms
6,144 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 177 ms
11,272 KB
testcase_18 AC 270 ms
8,192 KB
testcase_19 AC 299 ms
8,336 KB
testcase_20 AC 282 ms
8,320 KB
testcase_21 AC 282 ms
8,320 KB
testcase_22 AC 251 ms
8,008 KB
testcase_23 AC 226 ms
8,220 KB
testcase_24 AC 300 ms
8,308 KB
testcase_25 AC 306 ms
8,448 KB
testcase_26 AC 307 ms
8,448 KB
testcase_27 AC 313 ms
8,332 KB
testcase_28 AC 310 ms
8,436 KB
testcase_29 AC 191 ms
11,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<queue>
using namespace std;
int N,M;
int c[500][500];
long dist[2][500][500];
int d[5]={0,1,0,-1};
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int x,y;cin>>x>>y;
		cin>>c[x-1][y-1];
	}
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		dist[0][i][j]=dist[1][i][j]=1e18;
	}
	priority_queue<pair<long,pair<int,pair<int,int> > > >P;
	for(int i=0;i<2;i++)
	{
		dist[i][0][0]=0;
		P.push(make_pair(0,make_pair(i,make_pair(0,0))));
	}
	while(!P.empty())
	{
		long cost=-P.top().first;
		int f=P.top().second.first,x=P.top().second.second.first,y=P.top().second.second.second;
		P.pop();
		if(dist[f][x][y]<cost)continue;
		for(int r=0;r<4;r++)
		{
			int tx=x+d[r],ty=y+d[r+1];
			if(tx<0||ty<0||tx>=N||ty>=N)continue;
			long nxt=cost+c[tx][ty]+1;
			if(dist[f][tx][ty]>nxt)
			{
				dist[f][tx][ty]=nxt;
				P.push(make_pair(-nxt,make_pair(f,make_pair(tx,ty))));
			}
			if(f==0)
			{
				nxt-=c[tx][ty];
				if(dist[f+1][tx][ty]>nxt)
				{
					dist[f+1][tx][ty]=nxt;
					P.push(make_pair(-nxt,make_pair(f+1,make_pair(tx,ty))));
				}
			}
		}
	}
	cout<<dist[1][N-1][N-1]<<endl;
}
0