結果

問題 No.2366 登校
ユーザー 沙耶花沙耶花
提出日時 2023-06-30 22:17:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 537 ms / 4,000 ms
コード長 1,602 bytes
コンパイル時間 4,785 ms
コンパイル使用メモリ 265,024 KB
実行使用メモリ 19,824 KB
最終ジャッジ日時 2023-09-03 02:59:41
合計ジャッジ時間 9,398 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
16,008 KB
testcase_01 AC 4 ms
16,048 KB
testcase_02 AC 4 ms
16,048 KB
testcase_03 AC 5 ms
16,184 KB
testcase_04 AC 4 ms
15,968 KB
testcase_05 AC 5 ms
16,304 KB
testcase_06 AC 5 ms
16,156 KB
testcase_07 AC 5 ms
16,144 KB
testcase_08 AC 5 ms
16,228 KB
testcase_09 AC 5 ms
16,244 KB
testcase_10 AC 4 ms
16,132 KB
testcase_11 AC 5 ms
16,208 KB
testcase_12 AC 251 ms
18,872 KB
testcase_13 AC 233 ms
18,872 KB
testcase_14 AC 241 ms
18,704 KB
testcase_15 AC 250 ms
18,740 KB
testcase_16 AC 247 ms
18,872 KB
testcase_17 AC 248 ms
18,816 KB
testcase_18 AC 246 ms
18,740 KB
testcase_19 AC 250 ms
18,688 KB
testcase_20 AC 248 ms
18,748 KB
testcase_21 AC 232 ms
18,804 KB
testcase_22 AC 213 ms
18,616 KB
testcase_23 AC 89 ms
19,824 KB
testcase_24 AC 90 ms
19,812 KB
testcase_25 AC 537 ms
19,808 KB
testcase_26 AC 530 ms
19,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
long long dis[325][80][80];
int cs[80][80],ds[80][80];
int main(){
	
	int N,M,K,T;
	cin>>N>>M>>K>>T;
	
	T = min(T,160);
	
	rep(i,325){
		rep(j,N){
			rep(k,M)dis[i][j][k]  = Inf64;
		}
	}
	
	rep(i,K){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--,b--;
		cs[a][b] = c;
		ds[a][b] = d;
	}
	
	int cen = 160;
	dis[cen][0][0] = 0;
	priority_queue<pair<long long,vector<int>>,vector<pair<long long,vector<int>>>,greater<pair<long long,vector<int>>>> Q;
	Q.emplace(0LL,vector<int>({cen,0,0}));
	vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1};
	while(Q.size()>0){
		long long D = Q.top().first;
		int a = Q.top().second[0];
		int x = Q.top().second[1];
		int y = Q.top().second[2];
		Q.pop();
		if(dis[a][x][y]!=D)continue;
		rep(i,4){
			int aa = a+1;
			int xx = x+dx[i];
			int yy = y+dy[i];
			
			if(xx>=N||yy>=M||xx<0||yy<0||aa>=325||aa<0)continue;
			if(dis[aa][xx][yy]>D){
				dis[aa][xx][yy] = D;
				Q.emplace(D,vector<int>({aa,xx,yy}));
			}
			
		}
		if(cs[x][y]!=0){
			long long DD = D + ds[x][y];
			//cout<<DD<<','<<endl;
			int aa = max(0,a- cs[x][y] + 1);
			//cout<<a<<','<<aa<<endl;
			int xx = x,yy = y;
			if(dis[aa][xx][yy]>DD){
				dis[aa][xx][yy] = DD;
				Q.emplace(DD,vector<int>({aa,xx,yy}));
			}
		}
	}
	
	long long ans = Inf64;
	rep(i,cen+T+1)ans = min(ans,dis[i][N-1][M-1]);
	if(ans==Inf64)ans = -1;
	cout<<ans<<endl;
	
    return 0;
}

0