제출 #379315

#제출 시각아이디문제언어결과실행 시간메모리
379315ChrisTSalesman (IOI09_salesman)C++17
100 / 100
1405 ms46468 KiB
#include<bits/stdc++.h> using namespace std; const int MN = 5e5 + 5; struct Seg { int tree[MN << 1]; int n; Seg() {n = MN; memset(tree,-0x3f,sizeof tree);} void update (int i, int v) { for (tree[i += n-1] = v; i > 1; i >>= 1) tree[i>>1] = max(tree[i],tree[i^1]); } int query (int l, int r) { int ret = -1e9; for (l += n-1, r += n; l < r; l >>= 1, r >>= 1) { if (l&1) ret = max(ret,tree[l++]); if (r&1) ret = max(ret,tree[--r]); } return ret; } } segL, segR, segL2, segR2; vector<array<int,2>> atT[MN]; int main () { int n,u,d,s; scanf ("%d %d %d %d",&n,&u,&d,&s); while (n--) { int t,l,m; scanf ("%d %d %d",&t,&l,&m); atT[t].push_back({l,m}); } atT[MN-1].push_back({s,0}); segL.update(s,d * s); segR.update(s,-u*s); for (int t = 1; t < MN; t++) if (!atT[t].empty()) { int m = (int)atT[t].size(); vector<int> dp1(m), dp2(m); sort(atT[t].begin(),atT[t].end()); for (int i = 0; i < m; i++) { auto [l,c] = atT[t][i]; dp1[i] = max(max(segL.query(1,l),segL2.query(1,l)) - d * l + c,max(segR.query(l,MN),segR2.query(l,MN)) + u * l + c); segL2.update(l,dp1[i] + d * l); segR2.update(l,dp1[i] - u * l); } for (int i = 0; i < m; i++) segL2.update(atT[t][i][0],-1e9), segR2.update(atT[t][i][0],-1e9); for (int i = m-1; i >= 0; i--) { auto [l,c] = atT[t][i]; dp2[i] = max(max(segL.query(1,l),segL2.query(1,l)) - d * l + c,max(segR.query(l,MN),segR2.query(l,MN)) + u * l + c); segL2.update(l,dp2[i] + d * l); segR2.update(l,dp2[i] - u * l); } for (int i = 0; i < m; i++) { auto [l,c] = atT[t][i]; segL2.update(l,-1e9); segR2.update(l,-1e9); segL.update(l,max(dp1[i],dp2[i]) + d * l); segR.update(l,max(dp1[i],dp2[i]) - u * l); } if (t + 1 == MN) return !printf ("%d\n",dp1[0]); } return 0; }

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

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