제출 #337023

#제출 시각아이디문제언어결과실행 시간메모리
337023VROOM_VARUNSalesman (IOI09_salesman)C++14
100 / 100
1731 ms65536 KiB
/* ID: varunra2 LANG: C++ TASK: salesman */ #include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "lib/debug.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define debug_arr(...) \ cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__) #pragma GCC diagnostic ignored "-Wsign-compare" //#pragma GCC diagnostic ignored "-Wunused-parameter" //#pragma GCC diagnostic ignored "-Wunused-variable" #else #define debug(...) 42 #endif #define EPS 1e-9 #define IN(A, B, C) assert(B <= A && A <= C) #define INF (int)1e9 #define MEM(a, b) memset(a, (b), sizeof(a)) #define MOD 1000000007 #define MP make_pair #define PB push_back #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define x first #define y second const double PI = acos(-1.0); typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef map<int, int> MPII; typedef multiset<int> MSETI; typedef set<int> SETI; typedef set<string> SETS; typedef vector<int> VI; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<string> VS; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define trav(a, x) for (auto& a : x) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef vector<int> vi; #pragma GCC diagnostic ignored "-Wsign-compare" // util functions int n, u, d, s; VVI fairs; void init() { fairs.resize(n); } const int mx = 500005; struct segtree { VI st; VI lzy; int n; void init(int _n = 0) { _n = mx; n = _n; st.assign(4 * n, -INF); lzy.assign(4 * n, -INF); } void push(int node, int l, int r) { st[node] = max(st[node], lzy[node]); if (l < r) { lzy[2 * node + 1] = max(lzy[2 * node + 1], lzy[node]); lzy[2 * node + 2] = max(lzy[2 * node + 2], lzy[node]); } lzy[node] = -INF; } int qry(int ind, int node, int l, int r) { if (ind < l or ind > r) return -INF; push(node, l, r); if (ind == l and ind == r) return st[node]; int mid = (l + r) / 2; return max(qry(ind, 2 * node + 1, l, mid), qry(ind, 2 * node + 2, mid + 1, r)); } void upd(int tl, int tr, int val, int node, int l, int r) { if (tl > r or tr < l) return; push(node, l, r); if (l >= tl and r <= tr) { lzy[node] = max(lzy[node], val); push(node, l, r); return; } int mid = (l + r) / 2; upd(tl, tr, val, 2 * node + 1, l, mid); upd(tl, tr, val, 2 * node + 2, mid + 1, r); st[node] = max(st[2 * node + 1], st[2 * node + 2]); } int qry(int ind) { return qry(ind, 0, 0, n - 1); } void upd(int l, int r, int val) { if (l == -1) l = 0; if (r == -1) r = n - 1; r = min(r, n - 1); l = min(l, n - 1); upd(l, r, val, 0, 0, n - 1); } } lft, rt; int main() { // #ifndef ONLINE_JUDGE // freopen("salesman.in", "r", stdin); // freopen("salesman.out", "w", stdout); // #endif cin.sync_with_stdio(0); cin.tie(0); cin >> n >> u >> d >> s; init(); lft.init(); rt.init(); for (int i = 0; i < n; i++) { fairs[i].resize(3); for (int j = 0; j < 3; j++) cin >> fairs[i][j]; } sort(all(fairs)); lft.upd(s, -1, s * d); rt.upd(-1, s, -s * u); // debug(lft.qry(0), s * d); VI dp(n, -INF); VI ndp(n, -INF); for (int i = 0, j = 0; i < n; i = j) { while (j < n and fairs[i][0] == fairs[j][0]) j++; int mx = -INF; int cop = i; for (int i = cop; i < j; i++) { int day, money, pos; day = fairs[i][0]; pos = fairs[i][1]; money = fairs[i][2]; // debug("new uwa"); // debug(lft.qry(pos), pos, d); // debug(lft.qry(pos) - pos * d); // debug(rt.qry(pos), pos, u); // debug(pos * u + rt.qry(pos)); ndp[i] = max(lft.qry(pos) - pos * d, pos * u + rt.qry(pos)) + money; dp[i] = max(ndp[i], mx + money - pos * d); mx = max(mx + money, ndp[i] + pos * d); } mx = -INF; for (int i = j - 1; i >= cop; i--) { int day, money, pos; day = fairs[i][0]; pos = fairs[i][1]; money = fairs[i][2]; dp[i] = max(dp[i], mx + money + pos * u); mx = max(mx + money, ndp[i] - pos * u); lft.upd(pos, -1, dp[i] + pos * d); rt.upd(-1, pos, dp[i] - pos * u); } } int ret = 0; // debug(dp); // debug(ndp); for (int i = 0; i < n; i++) { ret = max(ret, dp[i] - abs(fairs[i][1] - s) * (fairs[i][1] < s ? d : u)); } cout << ret << '\n'; return 0; }

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

salesman.cpp: In function 'int main()':
salesman.cpp:152:11: warning: variable 'day' set but not used [-Wunused-but-set-variable]
  152 |       int day, money, pos;
      |           ^~~
salesman.cpp:167:11: warning: variable 'day' set but not used [-Wunused-but-set-variable]
  167 |       int day, money, pos;
      |           ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...