# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
113118 | 2019-05-23T19:42:15 Z | Bruteforceman | Long Distance Coach (JOI17_coach) | C++11 | 2 ms | 384 KB |
#include "bits/stdc++.h" using namespace std; long long s[200010]; long long d[200010]; long long c[200010]; int N, M; long long X, W, T; typedef pair <long long, int> pii; vector <pii> v; long long dp[200010]; long long p[200010]; int cnt[200010]; struct CHT { vector <long long> M, C; bool bad(int i, int j, int k) { return (C[k] - C[j]) * (M[j] - M[i]) <= (C[j] - C[i]) * (M[j] - M[k]); } void add_line(long long m, long long c) { if(!M.empty() && M.back() == m) { if(C.back() < c) return ; else { M.pop_back(); C.pop_back(); } } M.push_back(m); C.push_back(c); while(M.size() >= 3 && bad(M.size() - 3, M.size() - 2, M.size() - 1)) { M.erase(M.end() - 2); C.erase(C.end() - 2); } } long long search(int b, int e, long long val) { if(b == e) { return M[b] * val + C[b]; } int mid = (b + e) >> 1; if((M[mid] * val + C[mid]) >= (M[mid + 1] * val + C[mid + 1])) { return search(mid + 1, e, val); } else { return search(b, mid, val); } } long long eval(long long x) { return search(0, M.size() - 1, x); } } cht; int main(int argc, char const *argv[]) { scanf("%lld %d %d %lld %lld", &X, &N, &M, &W, &T); for(int i = 1; i <= N; i++) { scanf("%lld", &s[i]); } s[++N] = X; for(int i = 1; i <= N; i++) { v.push_back(pii(s[i] % T, i)); } for(int i = 1; i <= M; i++) { scanf("%lld %lld", &d[i], &c[i]); v.push_back(pii(d[i], -i)); } sort(v.begin(), v.end()); long long ans = (X / T) + 1; for(int i = 1; i <= M; i++) { ans += 1 + ((X - d[i]) / T); } ans *= W; int sz = N + M; v.insert(v.begin(), pii(0, 0)); for(int i = 1; i <= sz; i++) { if(v[i].second < 0) { int id = -v[i].second; p[i] = c[id] - W * (1 + ((X - d[id]) / T)); cnt[i] = 1; } p[i] += p[i - 1]; cnt[i] += cnt[i - 1]; } cht.add_line(0, 0); dp[0] = 0; for(int i = 1; i <= sz; i++) { if(v[i].second < 0) { dp[i] = dp[i - 1]; } else { long long var = W * (s[v[i].second] / T); long long cost = 0; long long add = p[i] + var * cnt[i]; dp[i] = add + cht.eval(var); } long long m = -cnt[i]; long long c = dp[i] - p[i]; cht.add_line(m, c); } ans += dp[sz]; printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |