# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
127901 |
2019-07-10T08:18:41 Z |
윤교준(#3110) |
Long Distance Coach (JOI17_coach) |
C++14 |
|
2000 ms |
5344 KB |
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int MAXN = 200055;
const int MAXM = 200055;
vector<ll> FV[MAXM];
ll DP[MAXM];
ll CS[MAXM];
ll S[MAXN]; int E[MAXN];
ll D[MAXM]; int C[MAXM];
ll X, T;
int N, M, W;
// <= x
int f(int i, ll x) { return int(upper_bound(allv(FV[i]), x) - FV[i].begin()); }
int fS(int i, ll x) {
int ret = 0;
for(; i <= M; i++) ret += f(i, x);
return ret;
}
void process() {
vector<pii> EV;
for(int i = 1; i <= M; i++) EV.eb(i, -i);
for(int i = 1; i <= N; i++) EV.eb(E[i], i);
sorv(EV); revv(EV);
for(auto &ev : EV) {
int idx = ev.second;
if(idx < 0) {
idx = -idx;
DP[idx] = DP[idx+1] + (X-D[idx]+T-1)/T * W;
for(int j = 1; j <= N; j++) if(idx <= E[j]) {
ll ret0 = -CS[idx-1] + ll(W) * (-idx+1) * ((S[j]-1)/T);
ret0 -= ll(W) * fS(idx-1, (S[j]-1)/T-1);
ll ret = DP[E[j]+1] + CS[E[j]] + ll(W) * E[j] * ((S[j]-1)/T);
ret -= ll(W) * fS(E[j], ((S[j]-1)/T-1));
ret += ret0;
upmin(DP[idx], ret);
}
} else {
// TODO
}
}
}
void precal() {
for(int i = 1; i <= N; i++) {
ll x = S[i] % T;
if(!x) x = T;
x--;
int s = 0, e = M; for(int m; s < e;) {
m = (s+e+1) >> 1;
if(D[m] <= x) s = m;
else e = m-1;
}
E[i] = s;
}
for(int i = 1; i <= N; i++) {
ll d = S[i] % T, x = (S[i] - d) / T;
int s = 0, e = M; for(int m; s < e;) {
m = (s+e) >> 1;
if(d == D[m]) { s = m; break; }
if(d < D[m]) e = m-1;
else s = m+1;
}
if(0 <= s && s <= M && d == D[s]) {
FV[s].eb(x);
}
}
for(int i = 1; i <= M; i++)
CS[i] = CS[i-1] + C[i];
}
void input() {
ios::sync_with_stdio(false);
vector<pli> V;
cin >> X >> N >> M >> W >> T;
for(int i = 1; i <= N; i++) cin >> S[i];
for(int i = 0; i < M; i++) {
ll a; int b;
cin >> a >> b;
V.eb(a, b);
}
sort(S+1, S+N+1);
N++; S[N] = X;
sorv(V);
for(int i = 1; i <= M; i++)
tie(D[i], C[i]) = V[i-1];
}
int main() {
input();
precal();
process();
cout << DP[1] + ll(W) * ((X+T-1)/T - fS(0, (X+T-1)/T - 1)) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5084 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5084 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5112 KB |
Output is correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
25 |
Correct |
7 ms |
5112 KB |
Output is correct |
26 |
Correct |
8 ms |
5112 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
8 ms |
5112 KB |
Output is correct |
29 |
Correct |
8 ms |
5112 KB |
Output is correct |
30 |
Correct |
9 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
7 ms |
5084 KB |
Output is correct |
34 |
Correct |
7 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5112 KB |
Output is correct |
36 |
Correct |
9 ms |
5112 KB |
Output is correct |
37 |
Correct |
9 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5084 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5112 KB |
Output is correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
25 |
Correct |
7 ms |
5112 KB |
Output is correct |
26 |
Correct |
8 ms |
5112 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
8 ms |
5112 KB |
Output is correct |
29 |
Correct |
8 ms |
5112 KB |
Output is correct |
30 |
Correct |
9 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
7 ms |
5084 KB |
Output is correct |
34 |
Correct |
7 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5112 KB |
Output is correct |
36 |
Correct |
9 ms |
5112 KB |
Output is correct |
37 |
Correct |
9 ms |
5112 KB |
Output is correct |
38 |
Execution timed out |
2063 ms |
5344 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Correct |
6 ms |
4984 KB |
Output is correct |
7 |
Correct |
6 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
6 ms |
5084 KB |
Output is correct |
10 |
Correct |
6 ms |
5112 KB |
Output is correct |
11 |
Correct |
6 ms |
5116 KB |
Output is correct |
12 |
Correct |
6 ms |
5112 KB |
Output is correct |
13 |
Correct |
6 ms |
5112 KB |
Output is correct |
14 |
Correct |
6 ms |
5112 KB |
Output is correct |
15 |
Correct |
6 ms |
4984 KB |
Output is correct |
16 |
Correct |
6 ms |
5112 KB |
Output is correct |
17 |
Correct |
6 ms |
5112 KB |
Output is correct |
18 |
Correct |
6 ms |
4984 KB |
Output is correct |
19 |
Correct |
6 ms |
5112 KB |
Output is correct |
20 |
Correct |
6 ms |
4984 KB |
Output is correct |
21 |
Correct |
6 ms |
4984 KB |
Output is correct |
22 |
Correct |
6 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5112 KB |
Output is correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
25 |
Correct |
7 ms |
5112 KB |
Output is correct |
26 |
Correct |
8 ms |
5112 KB |
Output is correct |
27 |
Correct |
7 ms |
5112 KB |
Output is correct |
28 |
Correct |
8 ms |
5112 KB |
Output is correct |
29 |
Correct |
8 ms |
5112 KB |
Output is correct |
30 |
Correct |
9 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
7 ms |
5112 KB |
Output is correct |
33 |
Correct |
7 ms |
5084 KB |
Output is correct |
34 |
Correct |
7 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5112 KB |
Output is correct |
36 |
Correct |
9 ms |
5112 KB |
Output is correct |
37 |
Correct |
9 ms |
5112 KB |
Output is correct |
38 |
Execution timed out |
2063 ms |
5344 KB |
Time limit exceeded |
39 |
Halted |
0 ms |
0 KB |
- |