結果
| 問題 |
No.2366 登校
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-30 22:49:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,163 bytes |
| コンパイル時間 | 1,735 ms |
| コンパイル使用メモリ | 153,232 KB |
| 最終ジャッジ日時 | 2025-02-15 04:23:52 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 WA * 6 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
vector<int> dy = {-1,0,1,0};
vector<int> dx = {0,-1,0,1};
int main(){
int N,M,K,T; cin >> N >> M >> K >> T;
vector<vector<pair<int,int>>> A(N,vector<pair<int,int>>(M,{0,0}));
rep(i,K){
int a,b,c,d; cin >> a >> b >> c >> d; a--; b--;
if(c!=1) A[a][b] = {c,d};
}
if(N+M-2<=T){
cout << "0\n";
return 0;
}
vector D(N,vector(M,vector<ll>(200,1LL<<60)));
vector used(N,vector(M,vector<bool>(200,false)));
ll ans = 1LL<<60;
rep(i,200) chmin(ans,D[N-1][M-1][i]);
priority_queue<pair<ll,vector<int>>,vector<pair<ll,vector<int>>>,greater<pair<ll,vector<int>>>> q;
q.push({0LL,{0,0,T}});
while(!q.empty()){
ll d = q.top().first;
vector<int> tv = q.top().second; q.pop();
int y = tv[0], x = tv[1], l = tv[2];
if(used[y][x][l]) continue;
used[y][x][l] = true; D[y][x][l] = d;
if(l!=0){
rep(i,4){
int ny = y + dy[i];
int nx = x + dx[i];
if(!(0<=ny&&ny<N&&0<=nx&&nx<M)) continue;
if(D[ny][nx][l-1] <= d) continue;
q.push({d,{ny,nx,l-1}});
}
}
if(A[y][x]!=pair<int,int>({0,0})){
if(D[y][x][min(199,l-1+A[y][x].first)] <= d+A[y][x].second) continue;
q.push({d+A[y][x].second,{y,x,min(199,l-1+A[y][x].first)}});
}
}
rep(i,200) chmin(ans,D[N-1][M-1][i]);
if(ans>=(1LL<<60)) ans = -1;
cout << ans << '\n';
return 0;
};