Submission #733422

#TimeUsernameProblemLanguageResultExecution timeMemory
733422penguin133Salesman (IOI09_salesman)C++17
6 / 100
169 ms65536 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, u, d, s; int dp[500005]; pii A[500005]; struct node{ int s, e, m, val; node *l, *r; node(int _s, int _e){ s = _s, e = _e, m = (s + e) >> 1, val = -1e18; if(s != e)l = new node(s, m), r = new node(m+1, e); } void upd(int p, int v){ if(s == e)val = max(val, v); else{ if(p <= m)l->upd(p, v); else r->upd(p, v); val = max(l->val, r->val); } } int qry(int a, int b){ if(s == a && b == e)return val; else if(b <= m)return l->qry(a, b); else if(a > m)return r->qry(a, b); else return max(l->qry(a, m), r->qry(m+1, b)); } }*dwn, *up; void solve(){ cin >> n >> u >> d >> s; int mx = s; for(int i=1;i<=n;i++){ cin >> A[i].fi >> A[i].se.fi >> A[i].se.se; mx = max(mx, A[i].se.fi); } dwn = new node(1, mx); up = new node(1, mx); sort(A+1, A+n+1); A[0].se.fi = s; A[n+1].se.fi = s; dwn->upd(s, -d * s); up->upd(s, u * s); for(int i=1;i<=n+1;i++){ int top = dwn->qry(A[i].se.fi, mx) + d * A[i].se.fi + A[i].se.se; int bot = up->qry(1, A[i].se.fi) - u * A[i].se.fi + A[i].se.se; dp[i] = max(top, bot); /* for(int j=i-1;j>=0;j--){ int cst; if(A[j].se.fi > A[i].se.fi)cst = d * (A[j].se.fi - A[i].se.fi); else cst = u * (A[i].se.fi - A[j].se.fi); dp[i] = max(dp[i], dp[j] - cst + A[i].se.se); } */ dwn->upd(A[i].se.fi, dp[i] - d * A[i].se.fi); up->upd(A[i].se.fi, dp[i] + u * A[i].se.fi); } cout << dp[n+1]; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

Compilation message (stderr)

salesman.cpp: In constructor 'node::node(int, int)':
salesman.cpp:21:43: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   21 |   s = _s, e = _e, m = (s + e) >> 1, val = -1e18;
      |                                           ^~~~~
salesman.cpp: At global scope:
salesman.cpp:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   72 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...