結果
| 問題 |
No.2366 登校
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2023-06-30 22:17:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 511 ms / 4,000 ms |
| コード長 | 1,602 bytes |
| コンパイル時間 | 4,307 ms |
| コンパイル使用メモリ | 257,336 KB |
| 実行使用メモリ | 20,056 KB |
| 最終ジャッジ日時 | 2025-06-20 11:11:26 |
| 合計ジャッジ時間 | 8,553 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
#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;
}
沙耶花