Task: | Aquarium |
Sender: | aalto2024a_012 |
Submission time: | 2024-09-04 16:53:25 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
#18 | ACCEPTED | 0.00 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | ACCEPTED | 0.00 s | details |
#21 | ACCEPTED | 0.00 s | details |
#22 | ACCEPTED | 0.00 s | details |
#23 | ACCEPTED | 0.00 s | details |
#24 | ACCEPTED | 0.00 s | details |
#25 | ACCEPTED | 0.00 s | details |
#26 | ACCEPTED | 0.00 s | details |
#27 | ACCEPTED | 0.00 s | details |
#28 | ACCEPTED | 0.00 s | details |
#29 | ACCEPTED | 0.00 s | details |
#30 | ACCEPTED | 0.00 s | details |
#31 | ACCEPTED | 0.00 s | details |
#32 | ACCEPTED | 0.00 s | details |
#33 | ACCEPTED | 0.00 s | details |
#34 | ACCEPTED | 0.00 s | details |
#35 | ACCEPTED | 0.00 s | details |
#36 | ACCEPTED | 0.00 s | details |
#37 | ACCEPTED | 0.00 s | details |
#38 | ACCEPTED | 0.00 s | details |
#39 | ACCEPTED | 0.00 s | details |
#40 | ACCEPTED | 0.00 s | details |
#41 | ACCEPTED | 0.00 s | details |
#42 | ACCEPTED | 0.00 s | details |
#43 | ACCEPTED | 0.00 s | details |
#44 | ACCEPTED | 0.00 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:50:20: warning: statement has no effect [-Wunused-value] 50 | #define debug(...) 42 | ^~ input/code.cpp:75:9: note: in expansion of macro 'debug' 75 | debug(v, cur, tot); | ^~~~~ input/code.cpp:50:20: warning: statement has no effect [-Wunused-value] 50 | #define debug(...) 42 | ^~ input/code.cpp:82:9: note: in expansion of macro 'debug' 82 | debug(le, ri); | ^~~~~
Code
#include <bits/stdc++.h> using namespace std; #define int long long string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif const int N = 10005; int n, h[N], q, v; signed main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; } cin >> q >> v; if (v <= h[q]) { cout << v << '\n'; return 0; } v -= h[q]; int le = q, ri = q, cur = h[q], tot = h[q]; double add = 0; while (v) { debug(v, cur, tot); // find first column higher than cur to the left while (le >= 1 && h[le] <= cur) le--; // find first column higher than cur to the right while (ri <= n && h[ri] <= cur) ri++; debug(le, ri); // spill to left or right if (le < 1 || ri > n) break; if (h[le] < h[ri]) { // fill till h[le] int need = ((ri - le + 1) - 1) * h[le] - tot; if (v < need) { // does it fill until h[le]? if (v >= need - h[le]) { cur = h[le]; } else { // doesn't int left = v - (((ri - le + 1) - 2) * cur - tot); add = (double)left / (double)((ri - le + 1) - 2); } break; } v -= need; tot += need; cur = h[le]; continue; } else if (h[le] > h[ri]) { // fill till h[ri] int need = ((ri - le + 1) - 1) * h[ri] - tot; if (v < need) { // does it fill until h[le]? if (v >= need - h[ri]) { cur = h[ri]; } else { // doesn't int left = v - (((ri - le + 1) - 2) * cur - tot); add = (double)left / (double)((ri - le + 1) - 2); } break; } v -= need; tot += need; cur = h[ri]; continue; } else { // h[le] = h[ri] // fill till both int need = ((ri - le + 1) - 0) * h[ri] - tot; if (v < need) { // does it fill until both h[le] and h[ri]? if (v >= need - h[ri] - h[le]) { cur = h[ri]; } else { // doesn't int left = v - (((ri - le + 1) - 2) * cur - tot); add = (double)left / (double)((ri - le + 1) - 2); } break; } v -= need; tot += need; cur = h[ri]; continue; } } double final = cur + add; cout << fixed << setprecision(3) << final; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 1 1 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Verdict: ACCEPTED
input |
---|
2 1 2 1 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 3
Verdict: ACCEPTED
input |
---|
3 1 1 3 2 7 |
correct output |
---|
1 |
user output |
---|
1.000 |
Test 4
Verdict: ACCEPTED
input |
---|
5 1 1 5 3 5 3 6 |
correct output |
---|
5 |
user output |
---|
5.000 |
Test 5
Verdict: ACCEPTED
input |
---|
6 5 3 1 2 4 6 3 4 |
correct output |
---|
2 |
user output |
---|
2.000 |
Test 6
Verdict: ACCEPTED
input |
---|
8 7 5 3 1 2 4 6 8 4 7 |
correct output |
---|
3 |
user output |
---|
3.000 |
Test 7
Verdict: ACCEPTED
input |
---|
9 2 1 9 5 9 4 5 4 3 4 5 |
correct output |
---|
5 |
user output |
---|
5 |
Test 8
Verdict: ACCEPTED
input |
---|
10 9 7 5 3 1 2 4 6 8 10 5 11 |
correct output |
---|
3.66667 |
user output |
---|
3.667 |
Test 9
Verdict: ACCEPTED
input |
---|
12 11 9 7 5 3 1 2 4 6 8 10 12 6 16 |
correct output |
---|
4 |
user output |
---|
4.000 |
Test 10
Verdict: ACCEPTED
input |
---|
14 13 11 9 7 5 3 1 2 4 6 8 10 12 ... |
correct output |
---|
5 |
user output |
---|
5.000 |
Test 11
Verdict: ACCEPTED
input |
---|
16 15 13 11 9 7 5 3 1 2 4 6 8 10 ... |
correct output |
---|
5.6 |
user output |
---|
5.600 |
Test 12
Verdict: ACCEPTED
input |
---|
18 17 15 13 11 9 7 5 3 1 2 4 6 8 ... |
correct output |
---|
6 |
user output |
---|
6.000 |
Test 13
Verdict: ACCEPTED
input |
---|
20 19 17 15 13 11 9 7 5 3 1 2 4 6... |
correct output |
---|
7 |
user output |
---|
7.000 |
Test 14
Verdict: ACCEPTED
input |
---|
25 5 1 24 14 24 11 13 11 9 9 4 6 ... |
correct output |
---|
6 |
user output |
---|
6.000 |
Test 15
Verdict: ACCEPTED
input |
---|
30 29 27 25 23 21 19 17 15 13 11 ... |
correct output |
---|
10 |
user output |
---|
10.000 |
Test 16
Verdict: ACCEPTED
input |
---|
40 39 37 35 33 31 29 27 25 23 21 ... |
correct output |
---|
13.4615 |
user output |
---|
13.462 |
Test 17
Verdict: ACCEPTED
input |
---|
50 49 47 45 43 41 39 37 35 33 31 ... |
correct output |
---|
17 |
user output |
---|
17.000 |
Test 18
Verdict: ACCEPTED
input |
---|
70 69 67 65 63 61 59 57 55 53 51 ... |
correct output |
---|
23.2609 |
user output |
---|
23.261 |
Test 19
Verdict: ACCEPTED
input |
---|
1 1 1 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 20
Verdict: ACCEPTED
input |
---|
2 3 2 1 16 |
correct output |
---|
3 |
user output |
---|
3.000 |
Test 21
Verdict: ACCEPTED
input |
---|
3 6 4 3 3 81 |
correct output |
---|
3 |
user output |
---|
3.000 |
Test 22
Verdict: ACCEPTED
input |
---|
5 14 8 5 24 16 5 625 |
correct output |
---|
16 |
user output |
---|
16.000 |
Test 23
Verdict: ACCEPTED
input |
---|
6 19 11 6 34 23 35 3 1296 |
correct output |
---|
19 |
user output |
---|
19.000 |
Test 24
Verdict: ACCEPTED
input |
---|
8 32 18 9 61 39 62 32 35 4 4096 |
correct output |
---|
61 |
user output |
---|
61.000 |
Test 25
Verdict: ACCEPTED
input |
---|
9 40 22 10 77 49 78 40 44 39 3 6561 |
correct output |
---|
40 |
user output |
---|
40.000 |
Test 26
Verdict: ACCEPTED
input |
---|
10 49 26 12 94 60 96 49 54 48 39 4 10000 |
correct output |
---|
94 |
user output |
---|
94.000 |
Test 27
Verdict: ACCEPTED
input |
---|
12 69 36 15 135 85 138 69 76 67 5... |
correct output |
---|
69 |
user output |
---|
69.000 |
Test 28
Verdict: ACCEPTED
input |
---|
14 93 47 18 184 114 187 93 102 90... |
correct output |
---|
141 |
user output |
---|
141.000 |
Test 29
Verdict: ACCEPTED
input |
---|
16 121 60 22 240 148 244 120 132 ... |
correct output |
---|
240 |
user output |
---|
240.000 |
Test 30
Verdict: ACCEPTED
input |
---|
18 151 74 25 303 186 308 151 166 ... |
correct output |
---|
303 |
user output |
---|
303.000 |
Test 31
Verdict: ACCEPTED
input |
---|
20 186 90 29 374 229 381 185 204 ... |
correct output |
---|
286 |
user output |
---|
286.000 |
Test 32
Verdict: ACCEPTED
input |
---|
25 287 136 40 584 355 594 286 316... |
correct output |
---|
516 |
user output |
---|
516.000 |
Test 33
Verdict: ACCEPTED
input |
---|
30 409 191 52 841 508 855 409 452... |
correct output |
---|
656 |
user output |
---|
656.000 |
Test 34
Verdict: ACCEPTED
input |
---|
40 720 328 80 1494 898 1519 719 7... |
correct output |
---|
1519 |
user output |
---|
1519.000 |
Test 35
Verdict: ACCEPTED
input |
---|
50 1118 503 113 2333 1397 2372 11... |
correct output |
---|
2372 |
user output |
---|
2372.000 |
Test 36
Verdict: ACCEPTED
input |
---|
70 2176 964 195 4570 2725 4648 21... |
correct output |
---|
4648 |
user output |
---|
4648.000 |
Test 37
Verdict: ACCEPTED
input |
---|
100 4416 1932 356 9323 5542 9483 4... |
correct output |
---|
9700 |
user output |
---|
9700.000 |
Test 38
Verdict: ACCEPTED
input |
---|
500 104548 249301 180224 233177 52... |
correct output |
---|
104548 |
user output |
---|
104548.000 |
Test 39
Verdict: ACCEPTED
input |
---|
600 150482 358999 259492 335771 64... |
correct output |
---|
353835 |
user output |
---|
353835.000 |
Test 40
Verdict: ACCEPTED
input |
---|
900 446578 58127 573897 680544 236... |
correct output |
---|
790626 |
user output |
---|
790626.000 |
Test 41
Verdict: ACCEPTED
input |
---|
900 783372 729637 443692 140636 78... |
correct output |
---|
805592 |
user output |
---|
805592.000 |
Test 42
Verdict: ACCEPTED
input |
---|
100 4416 1932 356 9323 5542 9483 4... |
correct output |
---|
9700 |
user output |
---|
9700.000 |
Test 43
Verdict: ACCEPTED
input |
---|
500 104548 249301 180224 233177 52... |
correct output |
---|
104548 |
user output |
---|
104548.000 |
Test 44
Verdict: ACCEPTED
input |
---|
600 150482 358999 259492 335771 64... |
correct output |
---|
353835 |
user output |
---|
353835.000 |