제출 #1032026

#제출 시각아이디문제언어결과실행 시간메모리
1032026GrindMachine추월 (IOI23_overtaking)C++17
100 / 100
1456 ms109644 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) (int)a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x,y) ((x+y-1)/(y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) #define rev(i,s,e) for(int i = s; i >= e; --i) #define trav(i,a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a,b); } template<typename T> void amax(T &a, T b) { a = max(a,b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* already knew some key ideas */ const int MOD = 1e9 + 7; const int N = 1e3 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; #include "overtaking.h" vector<ll> T; vector<int> W,S; ll X,m; vector<pll> segs; vector<ll> fv; void init(int L, int n, std::vector<long long> T_, std::vector<int> W_, int X_, int M, std::vector<int> S_) { T = T_, W = W_, S = S_; X = X_, m = M; ll e[n][m], t[n][m]; rep(i,n){ e[i][0] = t[i][0] = T[i]; } rep1(j,m-1){ rep(i,n){ e[i][j] = t[i][j-1]+(ll)W[i]*(S[j]-S[j-1]); t[i][j] = e[i][j]; } vector<pll> ord; rep(i,n){ ord.pb({t[i][j-1],i}); } sort(all(ord)); ll ptr = 0, mx = 0; rep(i,n){ while(ptr < n and ord[ptr].ff < ord[i].ff){ amax(mx,e[ord[ptr].ss][j]); ptr++; } amax(t[ord[i].ss][j],mx); } } vector<ll> b; rep(i,n){ rep(j,m){ b.pb(t[i][j]-X*S[j]); } } sort(all(b)); b.resize(unique(all(b))-b.begin()); segs.pb({-inf2,b[0]-1}); rep(i,sz(b)){ segs.pb({b[i],b[i]}); if(i+1 < sz(b)){ segs.pb({b[i]+1,b[i+1]-1}); } } segs.pb({b.back()+1,inf2}); ll siz = sz(segs); ll f[n][m]; rep(i,n) f[i][m-1] = t[i][m-1]; fv = vector<ll>(siz,-1); rev(j,m-2,0){ vector<pll> ord; rep(i,n){ ord.pb({t[i][j+1],i}); } sort(all(ord)); for(auto [tv,i] : ord){ ll l = t[i][j]-X*S[j]; ll r = t[i][j+1]-X*S[j+1]; l = lower_bound(all(segs),pll{l,l})-segs.begin(); r = lower_bound(all(segs),pll{r,r})-segs.begin(); l++, r--; for(int ind = l; ind <= r; ++ind){ fv[ind] = f[i][j+1]; } } rep(i,n){ ll val = t[i][j]-X*S[j]; ll ind = lower_bound(all(segs),pll{val,val})-segs.begin(); f[i][j] = max(t[i][j]+X*(S[m-1]-S[j]),fv[ind]); } } } long long arrival_time(long long t) { ll ind = lower_bound(all(segs),pll{t+1,-1})-segs.begin()-1; ll ans = max(t+X*S[m-1],fv[ind]); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...