Submission #1232226

#TimeUsernameProblemLanguageResultExecution timeMemory
1232226steveonalexOvertaking (IOI23_overtaking)C++20
100 / 100
534 ms70156 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define MASK(i) (1ULL << (i)) #define GETBIT(mask, i) (((mask) >> (i)) & 1) #define ALL(v) (v).begin(), (v).end() ll max(ll a, ll b){return (a > b) ? a : b;} ll min(ll a, ll b){return (a < b) ? a : b;} ll gcd(ll a, ll b){return __gcd(abs(a), abs(b));} ll lcm(ll a, ll b){return abs(a) / gcd(a, b) * abs(b);} ll LASTBIT(ll mask){return (mask) & (-mask);} int pop_cnt(ull mask){return __builtin_popcountll(mask);} int ctz(ull mask){return __builtin_ctzll(mask);} int logOf(ull mask){return 63 - __builtin_clzll(mask);} mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);} template <class T1, class T2> bool maximize(T1 &a, T2 b){ if (a < b) {a = b; return true;} return false; } template <class T1, class T2> bool minimize(T1 &a, T2 b){ if (a > b) {a = b; return true;} return false; } template <class T> void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){ for(auto item: container) out << item << separator; out << finish; } template <class T> void remove_dup(vector<T> &a){ sort(ALL(a)); a.resize(unique(ALL(a)) - a.begin()); } #include "overtaking.h" const int N = 1100; int n, m; ll X, L; vector<ll> t; vector<int> w, s; vector<pair<ll, ll>> lmao[N], aftermath[N]; void init_overtake_scheme(); void init_answer(); void init(int _L, int N, vector<ll> T, vector<int> W, int _X, int M, vector<int> S){ L = _L, m = M, s = S; X = _X; n = 0; for(int i = 0; i < N; ++i){ if (W[i] > X) { n++; t.push_back(T[i]); w.push_back(W[i]); } } init_overtake_scheme(); init_answer(); } void init_overtake_scheme(){ vector<pair<ll, ll>> buses; for(int i= 0; i < n; ++i){ buses.push_back({t[i], w[i]}); } for(int i = 1; i < m; ++i){ sort(ALL(buses)); lmao[i-1] = buses; ll diff = s[i] - s[i-1]; for(auto &j: buses){ j.first += diff * j.second; } for(int j = 1; j < (int) buses.size(); ++j){ maximize(buses[j].first, buses[j-1].first); } aftermath[i-1] = buses; } sort(ALL(buses)); lmao[m-1] = buses; } ostream& operator << (ostream &os, pair<ll, ll> x){ return os << "(" << x.first << ", " << x.second << ")"; } ll ans[N][N]; ll walking(int i, int j){ ll Y = aftermath[i][j-1].first; ++i; int l = 0, r = j; while(l < r){ int mid = (l + r + 1) >> 1; pair<ll, ll> cur1 = make_pair(Y, X), cur2 = lmao[i][mid-1]; if (cur1 < cur2) r = mid - 1; else l = mid; } j = l; if (j == 0) return Y + 1LL * X * (L - s[i]); l = i+1, r = m; while(l < r){ int mid = (l + r) >> 1; ll cur = Y + 1LL * X * (s[mid] - s[i]); if (cur <= aftermath[mid-1][j-1].first) r = mid; else l = mid + 1; } if (l == m) return Y + 1LL * X * (L - s[i]); return ans[l-1][j]; } void init_answer(){ for(int i = m-2; i >= 0; --i) for(int j = n; j >= 1; --j){ ans[i][j] = walking(i, j); } } ll arrival_time(ll Y){ int j = n; int l = 0, r = n; while(l < r){ int mid = (l + r + 1) >> 1; pair<ll, ll> cur1 = make_pair(Y, X), cur2 = lmao[0][mid-1]; if (cur1 < cur2) r = mid - 1; else l = mid; } j = l; if (j == 0) return Y + 1LL * X * L; l = 1, r = m; while(l < r){ int mid = (l + r) >> 1; ll cur = Y + 1LL * X * s[mid]; if (cur <= aftermath[mid-1][j-1].first) r = mid; else l = mid + 1; } if (l == m) return Y + 1LL * X * L; return ans[l-1][j]; }
#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...