제출 #556991

#제출 시각아이디문제언어결과실행 시간메모리
556991timreizinSalesman (IOI09_salesman)C++17
85 / 100
3085 ms59128 KiB
#include <iostream> #include <vector> #include <algorithm> #include <deque> #include <set> #include <string> #include <numeric> #include <cmath> #include <cassert> #include <array> #include <numeric> using namespace std; using ll = long long; class SegmentTree { private: int amount; vector<ll> tree; ll get(int a, int b, int l, int r, int v) { if (a > r || b < l) return -1e9; if (a == l && b == r) return tree[v]; int m = (l + r) >> 1; return max(get(a, min(b, m), l, m, v << 1), get(max(a, m + 1), b, m + 1, r, (v << 1) + 1)); } void build(int l, int r, int v) { if (l > r) return; if (l == r) { tree[v] = -1e9; return; } int m = (l + r) >> 1; build(l, m, v << 1); build(m + 1, r, (v << 1) + 1); tree[v] = max(tree[v << 1], tree[(v << 1) + 1]); } void update(int p, int l, int r, int v, ll value) { if (l > r) return; if (l == r) { tree[v] = value; return; } int m = (l + r) >> 1; if (p <= m) update(p, l, m, v << 1, value); else update(p, m + 1, r, (v << 1) + 1, value); tree[v] = max(tree[v << 1], tree[(v << 1) + 1]); } public: SegmentTree(int n = 0) : amount(n) { tree.resize(4 * amount + 5); build(0, n - 1, 1); } ll get(int a, int b) { return get(a, b, 0, amount - 1, 1); } void update(int p, ll value) { update(p, 0, amount - 1, 1, value); } }; int main() { cin.tie(0)->sync_with_stdio(0); int n; ll d, u, s; cin >> n >> u >> d >> s; vector<tuple<int, ll, ll>> fairs(n); for (auto &[t, l, m] : fairs) cin >> t >> l >> m; sort(fairs.begin(), fairs.end()); vector<vector<pair<ll, ll>>> times; int last = get<0>(fairs.front()); times.push_back(vector<pair<ll, ll>>()); for (auto [t, l, m] : fairs) { if (t != last) times.push_back(vector<pair<ll, ll>>()); times.back().emplace_back(l, m); last = t; } vector<tuple<int, ll, ll>>().swap(fairs); ll res = 0; SegmentTree left(500002), right(500002); left.update(s, s * d); right.update(s, -s * u); for (auto fairs : times) { vector<ll> dp(fairs.size(), -1e9); for (int i = 0; i < dp.size(); ++i) { ll sum = 0; for (int j = i; j >= 0; --j) { sum += fairs[j].second; ll bestj = max(left.get(0, fairs[j].first) - d * fairs[j].first, right.get(fairs[j].first, 500001) + u * fairs[j].first); dp[i] = max(dp[i], bestj + sum - (fairs[i].first - fairs[j].first) * d); } } for (int i = (int)dp.size() - 1; i >= 0; --i) { ll sum = 0; for (int j = i; j < dp.size(); ++j) { sum += fairs[j].second; ll bestj = max(left.get(0, fairs[j].first) - d * fairs[j].first, right.get(fairs[j].first, 500001) + u * fairs[j].first); dp[i] = max(dp[i], bestj + sum - (fairs[j].first - fairs[i].first) * u); } } for (int i = 0; i < dp.size(); ++i) { ll move = (s < fairs[i].first ? u * (fairs[i].first - s) : d * (s - fairs[i].first)); res = max(res, dp[i] - move); left.update(fairs[i].first, dp[i] + fairs[i].first * d); right.update(fairs[i].first, dp[i] - fairs[i].first * u); } } cout << res; return 0; } /* 4 5 3 100 2 80 100 20 125 130 10 75 150 5 120 110 */ /* 4 5 3 100 1 80 100 1 125 130 1 75 150 1 120 110 */ //125 + 90 -

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

salesman.cpp: In function 'int main()':
salesman.cpp:105:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |         for (int i = 0; i < dp.size(); ++i)
      |                         ~~^~~~~~~~~~~
salesman.cpp:118:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |             for (int j = i; j < dp.size(); ++j)
      |                             ~~^~~~~~~~~~~
salesman.cpp:125:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |         for (int i = 0; i < dp.size(); ++i)
      |                         ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...