Skip to content

Commit f256611

Browse files
committed
atcoder/abc076D
1 parent 1581cd8 commit f256611

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

atcoder/abc076/D/main.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
using ll = long long;
5+
6+
int N;
7+
vector<int> ts;
8+
vector<int> vs;
9+
10+
double solve() {
11+
int T = 0;
12+
vector<vector<int>> cs(N);
13+
for (int i = 0; i < N; ++i) {
14+
int l = T, r = T + ts[i], v = vs[i];
15+
cs[i] = { l, r, v };
16+
T += ts[i];
17+
}
18+
cs.push_back({ 0, 0, 0 });
19+
cs.push_back({ T, T, 0 });
20+
const auto minv = [&](double t) {
21+
double res = 100;
22+
for (auto const& c : cs) {
23+
auto l = c[0], r = c[1], v = c[2];
24+
if (t < l) {
25+
res = min(res, v + (l - t));
26+
} else if (t > r) {
27+
res = min(res, v + (t - r));
28+
} else {
29+
res = min(res, double(v));
30+
}
31+
}
32+
return res;
33+
};
34+
35+
double S = 0;
36+
for (int tt = 0; tt < 2 * T; ++tt) {
37+
double t = tt * 0.5, nt = (tt + 1) * 0.5;
38+
double v = minv(t), nv = minv(nt);
39+
S += 0.5 * (v + nv) * 0.5;
40+
}
41+
return S;
42+
}
43+
44+
int main() {
45+
ios_base::sync_with_stdio(false);
46+
cin.tie(0); cout.tie(0);
47+
48+
cin >> N;
49+
ts.assign(N, 0);
50+
vs.assign(N, 0);
51+
for (int i = 0; i < N; ++i) {
52+
cin >> ts[i];
53+
}
54+
for (int i = 0; i < N; ++i) {
55+
cin >> vs[i];
56+
}
57+
cout << fixed << setprecision(3) << solve() << endl;
58+
59+
return 0;
60+
}

0 commit comments

Comments
 (0)