結果

問題 No.1037 exhausted
ユーザー kiyoshi0205
提出日時 2020-04-24 23:06:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,475 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 186,200 KB
実行使用メモリ 66,048 KB
最終ジャッジ日時 2024-10-15 03:43:46
合計ジャッジ時間 3,183 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll inf=1LL<<60;
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}
using P=pair<ll,int>;
int main(){
// int codeforces;cin>>codeforces;while(codeforces--){
ll ans=-1;
int i,j=0,k,f=0,N,V,L;
scanf("%d %d %d",&N,&V,&L);
scanf("%d %d %d",&i,&j,&k);
if(i!=0){++N;f=1;}
vector<int> ax(N,0),v(N,0),w(N,0);
ax[f]=i;v[f]=min(j,V);w[f]=k;
rep1(i,N-f){
cin>>ax[i+f]>>v[i+f]>>w[i+f];
chmin(v[i+f],V);
}
if(ax[N-1]!=L){
++N;
ax.eb(L);v.eb(0);w.eb(0);
}
vector<ll> dist(N*(V+1)*2,inf);
priority_queue<P,vector<P>,greater<P>> que;
que.push(P(0,V*2+1));
while(!que.empty()){
P x=que.top();que.pop();
if(!chmin(dist[x.second],x.first))continue;
i=x.second/((V+1)<<1);
j=x.second%((V+1)<<1);
if(i==N-1){
ans=x.first;
break;
}
if(j<=V){
que.push(P(x.first+w[i],min(j+v[i],V)+i*((V+1)<<1)+V+1));
}else{
j-=V+1;
}
if(j>=ax[i+1]-ax[i]){
que.push(P(x.first,(i+1)*((V+1)<<1)+j+ax[i]-ax[i+1]));
}
}
printf("%lld\n",ans);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0