結果
問題 | No.2366 登校 |
ユーザー |
👑 ![]() |
提出日時 | 2023-06-30 23:07:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 875 ms / 4,000 ms |
コード長 | 2,893 bytes |
コンパイル時間 | 2,553 ms |
コンパイル使用メモリ | 217,828 KB |
最終ジャッジ日時 | 2025-02-15 04:34:32 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h>#pragma GCC optimize("Ofast")#pragma GCC optimize("unroll-loops")using namespace std;using std::cout;using std::cin;using std::endl;using ll=long long;using ld=long double;ll ILL=2167167167167167167;const int INF=2100000000;const int mod=1e9+7;#define rep(i,a,b) for (ll i=a;i<b;i++)#define all(p) p.begin(),p.end()template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}template<class T> T vec_sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}void solve();// oddloopint main() {ios::sync_with_stdio(false);cin.tie(nullptr);int t=1;//cin>>t;rep(i,0,t) solve();}void solve(){ll N,M,K,T;cin>>N>>M>>K>>T;int B=5;ll L=B*(N+M)+1;int S=2*(N+M);T+=S;chmin(T,L-1);vector dp(N,vector(M,vector<ll>(L,ILL)));dp[0][0][S]=0;_pq<pair<ll,tuple<ll,ll,ll>>> pq;pq.push({0,{0,0,S}});vector<vector<ll>> C(N,vector<ll>(M,-1));auto D=C;rep(i,0,K){ll a,b,c,d;cin>>a>>b>>c>>d;a--,b--;c--;if(c==0) continue;C[a][b]=c;D[a][b]=d;}vector<int> dx={1,-1,0,0,0},dy={0,0,1,-1,0};while(!pq.empty()){ll cost,x,y,z;cost=pq.top().first;tie(x,y,z)=pq.top().second;pq.pop();if(dp[x][y][z]!=cost) continue;//cout<<x<<" "<<y<<" "<<z<<" "<<cost<<endl;if(z!=L-1){rep(k,0,5){int s=dx[k]+x,t=dy[k]+y;if(s==-1||t==-1||s==N||t==M) continue;if(chmin(dp[s][t][z+1],dp[x][y][z])) pq.push({cost,{s,t,z+1}});}}if(C[x][y]==-1) continue;ll n_z=max(0ll,z-C[x][y]);cost+=D[x][y];if(chmin(dp[x][y][n_z],cost)) pq.push({cost,{x,y,n_z}});}cout<<(dp[N-1][M-1][T]==ILL?-1:dp[N-1][M-1][T])<<"\n";}