# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
921497 | gs25 | Salesman (IOI09_salesman) | C++17 | 3070 ms | 56988 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = 1; i <= n; ++i)
#define ff first
#define ss second
using namespace std;
typedef long long ll;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ", ";
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? ", " : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define dbg(x...) \
cerr << "\e[91m" << __func__ << ":" << __LINE__ << " [" << #x << "] = ["; \
_print(x); \
cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
int N,U,S,D;
const int MAXN = 500010;
vector<pair<int,int>> fuck[MAXN];
struct segment_tree{
int n; vector<int> seg;
const int inf = 1e9;
segment_tree(int x){
n = x+1;
seg.resize(4*n+8,-inf);
}
void update(int node, int s, int e, int pos, int val){
if(pos<s||pos>e) return;
if(s==e){
seg[node] = val; return;
}
int m = s+e>>1;
update(2*node,s,m,pos,val);
update(2*node+1,m+1,e,pos,val);
seg[node] = max(seg[2*node],seg[2*node+1]);
return;
}
int query(int node, int s, int e, int l, int r){
if(r<s||l>e) return -inf;
if(l<=s&&e<=r) return seg[node];
int m = s+e>>1;
return max(query(2*node,s,m,l,r),query(2*node+1,m+1,e,l,r));
}
void update(int pos, int val){
return update(1,0,n,pos,val);
}
int query(int l, int r){
return query(1,0,n,l,r);
}
};
const int inf = 1e9;
int bada(int pos, int M, segment_tree& seg1, segment_tree& seg2){
int lmax = M - D*pos + seg1.query(0,pos);
int rmax = M + U*pos + seg2.query(pos,MAXN-1);
dbg(lmax,rmax);
int MM = max(lmax,rmax);
//seg1.update(pos,MM+D*pos);
//seg2.update(pos,MM-U*pos);
return MM;
}
int tmp1[MAXN],tmp2[MAXN];
void solve(){
cin >> N >> U >> D >> S;
rep(i,N){
int t,pos,M; cin >> t >> pos >> M;
fuck[t].pb({pos,M});
}
fuck[0].pb({S,0});
fuck[MAXN-1].pb({S,0});
segment_tree seg1(MAXN), seg2(MAXN);
rep(i,N) sort(all(fuck[i]));
seg1.update(S,D*S);
seg2.update(S,-U*S);
for(int i=1; i<MAXN; i++){
if(fuck[i].size()==0) continue;
auto& vec = fuck[i];
int t = vec.size();
vector<int> tmp(t,0);
for(int i=0;i<t;i++){
auto& [pos,M] = vec[i];
dbg(pos,M);
tmp1[i] = bada(pos,M,seg1,seg2);
tmp2[i] = tmp1[i];
}
for(int i=1; i<t; i++){
tmp1[i] = max(tmp1[i],vec[i].second + tmp1[i-1]-D*(vec[i].first - vec[i-1].first));
}
for(int i=t-2;i>=0;i--){
tmp2[i] = max(tmp2[i],vec[i].second + tmp2[i+1]-U*(vec[i+1].first-vec[i].first));
}
for(int i=0; i<t; i++){
auto& [pos,M] = vec[i];
dbg(tmp[i]);
tmp1[i] = max(tmp1[i],tmp2[i]);
seg1.update(pos,tmp1[i]+D*pos);
seg2.update(pos,tmp1[i]-U*pos);
}
}
cout << seg1.query(S,S) - D*S;
}
int32_t main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1; //cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |