제출 #328522

#제출 시각아이디문제언어결과실행 시간메모리
328522Mackerel_PikeSalesman (IOI09_salesman)C++14
37 / 100
356 ms23148 KiB
#include<bits/stdc++.h> using namespace std; #define FOR(i, x, y) for(int i = (x); i < (y); ++i) #define REP(i, x, y) for(int i = (x); i <= (y); ++i) #define PB push_back #define MP make_pair #define PH push #define fst first #define snd second typedef long long ll; typedef unsigned long long ull; typedef double lf; typedef long double Lf; typedef pair<int, int> pii; const int maxn = 5e5 + 5; const ll INF = 0x3f3f3f3f3f3f3f3f; int n, u, d, s; ll ans = 0; ll f[maxn], g[maxn]; class Fair{ public: int t, l, m; Fair(){} Fair(int t_, int l_, int m_): t(t_), l(l_), m(m_){} inline bool operator < (const Fair &oth)const{ return MP(t, l) < MP(oth.t, oth.l); } } a[maxn]; class PrefixFenwickTree{ public: ll dat[maxn]; inline PrefixFenwickTree(){ FOR(i, 0, maxn) dat[i] = -INF; return; } inline void update(int x, ll k){ for(++x; x < maxn; x += x & (-x)) dat[x] = max(dat[x], k); return; } inline ll query(int x){ ll ret = 0; for(++x; x; x -= x & (-x)) ret = max(ret, dat[x]); return ret; } }pre; class SuffixFenwickTree{ public: ll dat[maxn]; inline SuffixFenwickTree(){ FOR(i, 0, maxn) dat[i] = -INF; return; } inline void update(int x, ll k){ for(++x; x; x -= x & (-x)) dat[x] = max(dat[x], k); return; } inline ll query(int x){ ll ret = -INF; for(++x; x < maxn; x += x & (-x)) ret = max(ret, dat[x]); return ret; } }suf; inline void update(int p){ pre.update(a[p].l, f[p] + a[p].l * d); suf.update(a[p].l, f[p] - a[p].l * u); return; } int main(){ scanf("%d%d%d%d", &n, &u, &d, &s); FOR(i, 0, n) scanf("%d%d%d", &a[i].t, &a[i].l, &a[i].m); a[n++] = Fair(0, s, 0); sort(a, a + n); // FOR(i, 0, n) // printf("%d %d %d\n", a[i].t, a[i].l, a[i].m); update(0); for(int i = 1, j; i < n; i = j){ for(j = i; j < n && a[j].t == a[i].t; ++j) g[j] = max(pre.query(a[j].l) - a[j].l * d, suf.query(a[j].l) + a[j].l * u); ll mx = -INF, sum = 0; for(j = i; j < n && a[j].t == a[i].t; ++j){ mx = max(mx, g[j] - sum); sum += a[j].m; // printf("j = %d mx = %lld sum = %lld\n", j, mx, sum); f[j] = mx + sum; } mx = -INF, sum = 0; for(--j; j >= i; --j){ mx = max(mx, g[j] - sum); sum += a[j].m; f[j] = mx + sum; } for(j = i; j < n && a[j].t == a[i].t; ++j) update(j); } /* FOR(i, 0, n) printf("%lld ", f[i]); puts(""); FOR(i, 0, n) printf("%lld ", g[i]); puts(""); */ FOR(i, 0, n) ans = max(ans, f[i] - (a[i].l < a[0].l ? (a[0].l - a[i].l) * d : (a[i].l - a[0].l) * u)); printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

salesman.cpp: In function 'int main()':
salesman.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |  scanf("%d%d%d%d", &n, &u, &d, &s);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
salesman.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |   scanf("%d%d%d", &a[i].t, &a[i].l, &a[i].m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...