Submission #1068770

#TimeUsernameProblemLanguageResultExecution timeMemory
1068770ewirlanOvertaking (IOI23_overtaking)C++17
39 / 100
3556 ms76228 KiB
// #ifndef __SIZEOF_INT128__ #define __SIZEOF_INT128__ #endif #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace chrono; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define rep(i, p, k) for(int i(p); i < (k); ++i) #define per(i, p, k) for(int i(p); i > (k); --i) #define sz(x) (int)(x).size() #define sc static_cast typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef __int128_t lll; //#define int ll template <typename T = int> using par = std::pair <T, T>; #define fi first #define se second #define test int _number_of_tests(in()); while(_number_of_tests--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb emplace_back struct Timer { string name{""}; time_point<high_resolution_clock> end, start{high_resolution_clock::now()}; duration<float, std::milli> dur; Timer() = default; Timer(string nm): name(nm) {} ~Timer() { end = high_resolution_clock::now(); dur= end - start; cout << "@" << name << "> " << dur.count() << " ms" << '\n'; } }; template <typename T = int> inline T in() { static T x; std::cin >> x; return x; } std::string yn(bool b) { if(b) return "YES\n"; else return "NO\n"; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par); template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek) { for(const auto& i : wek)out << i << ' '; return out; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par) { out << '{'<<par.first<<", "<<par.second<<"}"; return out; } #define show(x) cerr << #x << " = " << x << '\n'; int l, n, x, m; vector <ll> t; vector <int> w; vector <int> s; #define g0 get<0> #define g1 get<1> #define g2 get<2> constexpr int maxn = 1003; vector <tuple <ll, int, int>> dp[maxn]; ll mt[maxn][maxn]; struct ty{ ll p, k, w; ty(ll a, ll b, ll c) : p(a), k(b), w(c) {} }; vector <ty> odp; void init(int Wl, int Wn, vector <ll> Wt, vector <int> Ww, int Wx, int Wm, vector <int> Ws) { l = Wl; n = Wn; t = Wt; x = Wx; m = Wm; w = Ww; s = Ws; vector < tuple<ll, int, int>> v; rep(i, 0, n)v.pb(t[i], w[i], i); rep(i, 1, m){ sort(all(v)); rep(j, 0, n)mt[i-1][g2(v[j])] = g0(v[j]); dp[i-1] = v; ll d(s[i]-s[i-1]); vector <tuple <ll, int, int>> v2; v2.pb(g0(v[0]) + g1(v[0])*d, g1(v[0]), g2(v[0])); rep(j, 1, n)v2.pb(max(g0(v[j])+ g1(v[j])*d, g0(v2[j-1])), g1(v[j]), g2(v[j])); v = v2; } rep(j, 0, n)mt[m-1][g2(v[j])] = g0(v[j]); dp[m-1] = v; // rep(i, 0, m+1)dp[i].pb(1e18, 0, n+1); // rep(i, 0, m+1)mt[i][n+1] = 1e18; vector <pair <vector <ty>, pair <int, int>>> dc; vector <ll> sd(m); rep(i, 1, m){ ll d(x*ll(s[i]-s[i-1])); vector <pair <ll, ll>> v; rep(j, 0, n)v.pb(g0(dp[i-1][j]) + (g1(dp[i-1][j])<=x?0:1), mt[i][g2(dp[i-1][j])]-d); vector <ty> w; for(auto [g, m]: v){ if(sz(w) && w.back().w >= m)continue; while(sz(w) && (w.back().p == g))w.pop_back(); if(sz(w)) w.back().k = min(w.back().k, g-1); w.pb(g, m, m); } vector <ty> wp; for(auto i: w)if(i.p <= i.k)wp.pb(i.p, i.k, i.w+d); dc.pb(wp, par<int>{i, i}); sd[i] = sd[i-1] + d; } while(sz(dc) > 1){ // cerr << "----------------\n"; // for(auto [v, i]: dc){ // cerr << i << ' '; // for(auto [p, k, w]: v)cerr << '(' << p << '-' << k << ": " << w << ") "; // cerr << '\n'; // } vector <pair <vector <ty>, pair <int, int>>> dc2; if(sz(dc) % 2)dc2.pb(dc[0]); for(int ind(sz(dc)%2); ind < sz(dc); ind += 2){ auto [wa, ia] = dc[ind]; auto [wb, ib] = dc[ind+1]; ll ofs(sd[ia.second] - sd[ia.first-1]); ll ofsb(sd[ib.second] - sd[ib.first-1]); set <ll> s; for(auto [p, k, w]: wa)for(auto i: {p, k, p-ofs, k-ofs})rep(j, -1, 2)s.insert(i+j); for(auto [p, k, w]: wb)for(auto i: {p, k, p-ofs, k-ofs})rep(j, -1, 2)s.insert(i+j); int ja(0), jb(0); vector <ty> o2; for(auto i: s){ // cerr << i <<'-'; ll I(-1); bool c(0); while(ja < sz(wa) && wa[ja].k < i)++ja; if(ja < sz(wa) && wa[ja].p <= i && i <= wa[ja].k){ I = wa[ja].w; c = 1; } else I = i+ofs; // cerr << I<<'-'; while(jb < sz(wb) && (wb[jb].p > wb[jb].k || wb[jb].k < I))++jb; if(jb < sz(wb) && wb[jb].p <= I && I <= wb[jb].k){ I = max(I, wb[jb].w); c = 1; } else I += ofsb; // cerr <<I<<' '; if(c){ if(!sz(o2) || o2.back().w != I)o2.pb(i, i, I); else o2.back().k = max(o2.back().k, i); } } // cerr << '\n'; dc2.pb(o2, pair <int, int>{ia.first, ib.second}); } dc = dc2; } odp = dc[0].first; // cerr << "ODP:\n"; // for(auto [p, k, w]: odp)cerr << '(' << p << '-' << k << ": " << w << ") "; } ll arrival_time(ll y) { if(!sz(odp))return y+1ll*l*x; int p(0), k(sz(odp)-1), s; while(k > p){ s = (p+k)/2; if(y > odp[s].k)p = s+1; else k = s; } if(odp[p].p <= y && y <= odp[p].k)return odp[p].w; return y+1ll*l*x; }
#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...