結果
| 問題 |
No.2366 登校
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-10-26 11:09:57 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,271 bytes |
| コンパイル時間 | 3,271 ms |
| コンパイル使用メモリ | 260,172 KB |
| 実行使用メモリ | 15,356 KB |
| 最終ジャッジ日時 | 2024-09-25 12:19:43 |
| 合計ジャッジ時間 | 9,083 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 TLE * 1 -- * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll memo[81][81][15000];
int vis[81][81][15000];
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll ans = 1e18;
ll n,m,k,t;
cin>>n>>m>>k>>t;
vector<vector<pair<ll,ll>>> use(n,vector<pair<ll,ll>>(m));
for(int i = 0;i<k;i++){
ll a,b,c,d;
cin>>a>>b>>c>>d;
a--;b--;
use[a][b] = make_pair(c,d);
}
using dat = pair<ll,pair<ll,ll>>;
priority_queue<pair<ll,dat>,vector<pair<ll,dat>>,greater<pair<ll,dat>>> que;
que.push(make_pair(0,make_pair(0,make_pair(0,0))));
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
for(int i = 0;i<n;i++) for(int j = 0;j<m;j++) for(int k = 0;k<15000;k++) memo[i][j][k] = 1e18;
ll can = 1e18;
while(!que.empty()){
auto now = que.top();
que.pop();
int ni = now.second.second.first;
int nj = now.second.second.second;
if(vis[ni][nj][now.second.first+7000]++) continue;
if(ni==n-1&&nj==m-1){
if(now.second.first>t) continue;
ans = min(ans,now.first);
continue;
}
for(int k = 0;k<4;k++){
int nni = ni + dx[k];
int nnj = nj + dy[k];
if(nni<0||nnj<0||nni>=n||nnj>=m) continue;
ll nxt = now.second.first;
nxt++;
ll cost = now.first;
if(nxt<=-7000) nxt = -7000;
if(nxt>=7000) nxt = 7000;
dat will = make_pair(nxt,make_pair(nni,nnj));
if(memo[nni][nnj][nxt+7000]<=cost) continue;
memo[nni][nnj][nxt+7000] = cost;
que.push(make_pair(cost,will));
}
if(use[ni][nj].first!=0){
ll nxt = now.second.first + 1;
ll cost = now.first;
nxt -= use[ni][nj].first;
cost += use[ni][nj].second;
int nni = ni;
int nnj = nj;
dat will = make_pair(nxt,make_pair(nni,nnj));
if(nxt<=-7000) nxt = -7000;
if(nxt>=7000) nxt = 7000;
if(memo[ni][nj][nxt+7000]<=cost) continue;
memo[ni][nj][nxt+7000] = cost;
que.push(make_pair(cost,will));
}
}
if(ans==1e18) ans = -1;
cout<<ans<<endl;
}
momoyuu