Advertisement
welleyth

G. Run

Mar 30th, 2022
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6. #define int long long
  7. #define pb push_back
  8. #define mp make_pair
  9.  
  10. #pragma GCC optimize("Ofast")
  11. #pragma GCC optimize("unroll-loops")
  12. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
  13. #pragma GCC target("avx,avx2")
  14.  
  15. constexpr int INF = (int)4e18;
  16. constexpr int N = (int)1e6 + 11;
  17. constexpr int MAXN = (int)1e5 + 11;
  18. constexpr int md = (int)998244353;
  19.  
  20. mt19937_64 rnd(std::chrono::steady_clock().now().time_since_epoch().count());
  21.  
  22. struct edge{
  23.     int id,x,d,t,p;
  24.     edge(){}
  25.     edge(int id,int x,int d,int t,int p):id(id),x(x),d(d),t(t),p(p){}
  26. };
  27.  
  28. void solve(){
  29.     int n,L;
  30.     cin >> n >> L;
  31.  
  32.     map<int,vector<edge>> g;
  33.     map<int,int> d;
  34.     map<int,pair<int,int>> pr;
  35.     d[0] = 0;
  36.  
  37.     for(int i = 0; i < n; i++){
  38.         int x,di,t,p;
  39.         cin >> x >> di >> t >> p;
  40.         if(x - p < 0)
  41.             continue;
  42.         g[x-p].pb({i+1,x,di,t,p});
  43.         d[x-p] = INF;
  44.         d[x+di] = INF;
  45.     }
  46.     d[0] = 0;
  47.     d[L] = INF;
  48.     int mn = 0;
  49.     int prevX = 0;
  50.     set<pair<pair<int,int>,pair<int,int>>> st; /// d[x]+x,prX-p,prX+d,id
  51.     map<int,vector<pair<pair<int,int>,pair<int,int>>>> toDelete;
  52.     for(auto&[x,y] : d){
  53.         for(auto& p : toDelete[x])
  54.             st.erase(p);
  55.         if(!st.empty() && d[x] > st.begin()->first.first - x){
  56.             d[x] = st.begin()->first.first - x;
  57.             pr[x] = mp(st.begin()->first.second,st.begin()->second.second);
  58.         }
  59.         if(d[x] > mn + x){
  60.             d[x] = mn + x;
  61.             pr[x] = mp(prevX,-1);
  62.         }
  63.         if(mn > d[x]-x){
  64.             prevX = x;
  65.             mn = d[x] - x;
  66.         }
  67.         for(auto& e : g[x]){
  68.             int to = e.x + e.d;
  69.             int t = e.t;
  70.             int id = e.id;
  71.             int jump = e.x;
  72.             int p = e.p;
  73.             if(d[to] > d[x]+p+t){
  74.                 d[to] = d[x]+p+t;
  75.                 pr[to] = mp(x,id);
  76.                 st.insert(mp(mp(d[to]+to,x),mp(to,id)));
  77.                 toDelete[to].pb(mp(mp(d[to]+to,x),mp(to,id)));
  78.             }
  79.         }
  80.     }
  81.  
  82.     cout << d[L] << "\n";
  83.     vector<int> trampoline;
  84.     int y = L;
  85.     while(y > 0){
  86.         int t = pr[y].second;
  87.         if(t != -1)
  88.             trampoline.pb(t);
  89.         y = pr[y].first;
  90.     }
  91.     reverse(trampoline.begin(),trampoline.end());
  92.     cout << trampoline.size() << "\n";
  93.     for(auto& x : trampoline)
  94.         cout << x << " ";
  95.  
  96.     return;
  97. }
  98. signed main(){
  99.     ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  100.     int tests = 1;
  101. //    cin >> tests;
  102.     while(tests--){
  103.         solve();
  104.     }
  105. }
  106. /**
  107.  
  108.  
  109.  
  110. **/
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement