結果

問題 No.1037 exhausted
ユーザー kiyoshi0205kiyoshi0205
提出日時 2020-04-24 23:06:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 2,475 bytes
コンパイル時間 2,525 ms
コンパイル使用メモリ 182,524 KB
実行使用メモリ 66,124 KB
最終ジャッジ日時 2024-04-23 04:10:21
合計ジャッジ時間 2,975 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 22 ms
65,928 KB
testcase_13 AC 22 ms
65,728 KB
testcase_14 AC 25 ms
65,888 KB
testcase_15 AC 24 ms
65,948 KB
testcase_16 AC 24 ms
65,720 KB
testcase_17 AC 23 ms
65,956 KB
testcase_18 AC 23 ms
65,920 KB
testcase_19 AC 23 ms
65,764 KB
testcase_20 AC 22 ms
65,612 KB
testcase_21 AC 22 ms
65,884 KB
testcase_22 AC 31 ms
66,124 KB
権限があれば一括ダウンロードができます

ソースコード

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);
}
0