Submission #861822

#TimeUsernameProblemLanguageResultExecution timeMemory
861822sleepntsheepSalesman (IOI09_salesman)C++17
100 / 100
367 ms37836 KiB
#include <cstdio> #include <cstring> #include <cassert> #include <string> #include <deque> #include <vector> #include <map> #include <queue> #include <algorithm> #include <iostream> #include <utility> using namespace std; using ll =long long; using ld=long double; const ll N = 555555, inf = 1e9; int n, d, u, s, X = 500005; struct binarytree { int t[N*2]; binarytree() {memset(t,0xbf,sizeof t);} inline int qry(int l, int r) { int z=-1e9; for (l+=X,r+=X+1;l<r;l/=2,r/=2){ if(l&1)z=max(z,t[l++]); if(r&1)z=max(t[--r],z); } return z; } inline void upd(int p, int k) { for(t[p+=X]=k;p/=2;)t[p]=max(t[p*2],t[p*2+1]); } } thi, tlo; struct fair { int pos, money; bool operator<(const fair &o) const { return pos<o.pos; } }; vector<fair> a[N]; inline void upd(ll pos, ll val) { thi.upd(pos, val - u * pos); tlo.upd(pos, val - (X - pos) * d); } inline int cost(int pos) { return max(thi.qry(pos, X-1) + u * pos, tlo.qry(0, pos) + (X - pos) * d); } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> u >> d >> s; for (int d, p, m, i = 0; i < n; ++i) cin >> d >> p >> m, a[d].push_back(fair{p, m}); upd(s, 0); for (auto i = 0; i <= 500000; ++i) { auto &x = a[i]; if (x.empty()) continue; sort(x.begin(), x.end()); if (x.size() == 1) upd(x[0].pos, x[0].money + cost(x[0].pos)); else { vector<int> temp(x.size(), -inf), rtemp(x.size(), -inf); for (int i = 0; i < x.size(); ++i) temp[i] = rtemp[i] = x[i].money + cost(x[i].pos); for (int i = 1; i < x.size(); ++i) temp[i] = max(temp[i], temp[i-1] - (x[i].pos - x[i-1].pos) * d + x[i].money); for (int i = (int)x.size() - 2; i >= 0; --i) rtemp[i] = max(rtemp[i], rtemp[i+1] - (x[i+1].pos - x[i].pos) * u + x[i].money); for (int i = 0; i < x.size(); ++i) upd(x[i].pos, max(temp[i], rtemp[i])); } } cout << cost(s); return 0; }

Compilation message (stderr)

salesman.cpp: In function 'int main()':
salesman.cpp:69:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<fair>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for (int i = 0; i < x.size(); ++i) temp[i] = rtemp[i] = x[i].money + cost(x[i].pos);
      |                             ~~^~~~~~~~~~
salesman.cpp:70:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<fair>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             for (int i = 1; i < x.size(); ++i) temp[i] = max(temp[i], temp[i-1] - (x[i].pos - x[i-1].pos) * d + x[i].money);
      |                             ~~^~~~~~~~~~
salesman.cpp:72:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<fair>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |             for (int i = 0; i < x.size(); ++i) upd(x[i].pos, max(temp[i], rtemp[i]));
      |                             ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...