Submission #1061286

#TimeUsernameProblemLanguageResultExecution timeMemory
1061286aykhnOvertaking (IOI23_overtaking)C++17
100 / 100
1612 ms129872 KiB
#include "overtaking.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; #define pb push_back #define ins insert #define fi first #define se second #define mpr make_pair #define mxn (ll)(1e3 + 5) #define int long long ll n, m, l, x; vector<ll> w, t, s; vector<pii> v[mxn]; vector<pii> ran[mxn]; vector<ll> pref[mxn]; map<int, int> mp; ll get(ll pos) { return (*prev(mp.upper_bound(pos))).second; } void make(ll l, ll r, ll val) { auto it = prev(mp.upper_bound(r)); if (mp.find(r + 1) == mp.end()) mp[r + 1] = (*it).second; mp[l] = val; auto itl = next(mp.find(l)); auto itr = mp.find(r + 1); mp.erase(itl, itr); } void init(signed L, signed N, vector<ll> T, vector<signed> W, signed X, signed M, vector<signed> S) { n = N, m = M, l = L, x = X; for (ll x : W) w.pb(x); for (ll x : T) t.pb(x); for (ll x : S) s.pb(x); for (ll i = 0; i < n; i++) v[0].pb({t[i], w[i]}); for (ll i = 0; i + 1 < m; i++) { sort(v[i].begin(), v[i].end(), [&](const pii &a, const pii &b) { if (a.fi == b.fi) return a.se < b.se; return a.fi < b.fi; }); for (ll j = 0; j < v[i].size(); j++) { if (!j || pref[i][j - 1] <= v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se) { v[i + 1].pb({v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se, v[i][j].se}); ran[i].pb({v[i][j].fi, v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se}); pref[i].pb(v[i][j].fi + (s[i + 1] - s[i]) * v[i][j].se); continue; } v[i + 1].pb({pref[i][j - 1], v[i][j].se}); pref[i].pb(pref[i][j - 1]); } } mp[0] = -1; for (ll i = m - 2; i >= 0; i--) { vector<pair<pii, ll>> late; for (ll j = 0; j < ran[i].size(); j++) { ll a = ran[i][j].fi; ll c = ran[i][j].se; ll b = (j + 1 < ran[i].size() ? ran[i][j + 1].fi : (ll)(2e18)); ll lb = a + 1 + (s[m - 1] - s[i]) * x; ll ub = min(c - (s[i + 1] - s[i]) * x, b) + (s[m - 1] - s[i]) * x; if (lb > ub) continue; ll upd = get(c + (s[m - 1] - s[i + 1]) * x); if (upd == -1) upd = c + (s[m - 1] - s[i + 1]) * x; late.pb({{lb, ub}, upd}); } for (const pair<pii, ll> &p : late) { make(p.fi.fi, p.fi.se, p.se); } } // for (pair<pii, ll> x : st) cout << x.fi.fi << ' ' << x.fi.se << ' ' << x.se << " | "; // cout << '\n'; } ll arrival_time(ll Y) { Y += l * x; ll cur = get(Y); return (cur == -1 ? Y : cur); }

Compilation message (stderr)

overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:41:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 |     for (ll x : W)  w.pb(x); for (ll x : T)  t.pb(x); for (ll x : S)  s.pb(x);
      |     ^~~
overtaking.cpp:41:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   41 |     for (ll x : W)  w.pb(x); for (ll x : T)  t.pb(x); for (ll x : S)  s.pb(x);
      |                              ^~~
overtaking.cpp:50:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (ll j = 0; j < v[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~
overtaking.cpp:67:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for (ll j = 0; j < ran[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~~
overtaking.cpp:71:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             ll b = (j + 1 < ran[i].size() ? ran[i][j + 1].fi : (ll)(2e18));
      |                     ~~~~~~^~~~~~~~~~~~~~~
#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...