結果

問題 No.2366 登校
ユーザー kotatsugamekotatsugame
提出日時 2023-06-30 22:04:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 4,000 ms
コード長 1,429 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 82,904 KB
実行使用メモリ 19,588 KB
最終ジャッジ日時 2023-09-03 02:59:27
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 86 ms
13,164 KB
testcase_13 AC 76 ms
13,060 KB
testcase_14 AC 77 ms
13,124 KB
testcase_15 AC 90 ms
13,336 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 87 ms
13,068 KB
testcase_18 AC 79 ms
13,112 KB
testcase_19 AC 85 ms
13,048 KB
testcase_20 AC 81 ms
13,372 KB
testcase_21 AC 73 ms
13,116 KB
testcase_22 AC 71 ms
13,060 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 58 ms
19,552 KB
testcase_25 AC 297 ms
19,524 KB
testcase_26 AC 294 ms
19,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<map>
#include<queue>
#include<cassert>
using namespace std;
int N,M,K,T;
int C[80][80],D[80][80];
long dp[80][80][320];
const int d[5]={0,1,0,-1};
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M>>K>>T;
	for(int i=0;i<N;i++)for(int j=0;j<M;j++)C[i][j]=-1;
	for(int i=0;i<K;i++)
	{
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--,b--;
		C[a][b]=c;
		D[a][b]=d;
	}
	if((N-1)+(M-1)<=T)
	{
		cout<<0<<endl;
		return 0;
	}
	const int off=(N-1)+(M-1);
	for(int i=0;i<N;i++)for(int j=0;j<M;j++)for(int t=0;t<=off*2;t++)dp[i][j][t]=1e18;
	dp[0][0][off]=0;
	priority_queue<pair<long,pair<int,int> > >Q;
	Q.push(make_pair(0,make_pair(0,off)));
	long ans=1e18;
	while(!Q.empty())
	{
		long c=-Q.top().first;
		int xy=Q.top().second.first,t=Q.top().second.second;
		Q.pop();
		int x=xy/M,y=xy%M;
		if(dp[x][y][t]<c)continue;
		if(x==N-1&&y==M-1)
		{
			if(t<=off+T)ans=min(ans,c);
			if(C[x][y]!=-1&&t-C[x][y]<=off+T)ans=min(ans,c+D[x][y]);
		}
		if(C[x][y]!=-1)
		{
			int nt=max(t-C[x][y]+1,0);
			long nc=c+D[x][y];
			if(dp[x][y][nt]>nc)
			{
				dp[x][y][nt]=nc;
				Q.push(make_pair(-nc,make_pair(x*M+y,nt)));
			}
		}
		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>=M||t+1>off*2)continue;
			if(dp[tx][ty][t+1]>c)
			{
				dp[tx][ty][t+1]=c;
				Q.push(make_pair(-c,make_pair(tx*M+ty,t+1)));
			}
		}
	}
	if(ans==(long)1e18)ans=-1;
	cout<<ans<<endl;
}
0