# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1071323 | 2024-08-23T06:41:56 Z | 정민찬(#11138) | Cultivation (JOI17_cultivation) | C++17 | 2000 ms | 600 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll inf = 2e18; ll R, C; ll N; ll solve(vector<pll> p, ll H) { vector<pll> upd; ll j = 0; for (ll i=0; i<p.size(); i++) { while (j < p.size() && p[j].first + H <= p[i].first) { upd.push_back({p[j].first + H, -p[j].second}); j ++; } upd.push_back(p[i]); } while (j < p.size()) { upd.push_back({p[j].first + H, -p[j].second}); j ++; } vector<ll> cur; vector<array<ll,4>> save; for (ll i=0; i<upd.size(); i++) { if (upd[i].second > 0) { cur.push_back(upd[i].second); sort(cur.begin(), cur.end()); } else { for (ll j=0; j<cur.size(); j++) { if (cur[j] == -upd[i].second) { cur.erase(cur.begin() + j); break; } } } if (i + 1 != upd.size() && upd[i].first == upd[i+1].first) continue; if (cur.empty()) { save.push_back({upd[i].first, inf, inf, inf}); continue; } ll l = cur[0] - 1, r = C - cur.back(); ll sum = l + r; for (ll j=0; j+1<cur.size(); j++) { sum = max(sum, cur[j+1] - cur[j] - 1); } save.push_back({upd[i].first, sum, l, r}); } ll ans = inf; for (ll i=0; i<save.size(); i++) { ll l = save[i][2], r = save[i][3]; ll sum = save[i][1]; for (ll j=i+1; j<save.size(); j++) { if (save[j][0] > save[i][0] + R - 1) break; l = max(l, save[j][2]); r = max(r, save[j][3]); sum = max(sum, save[j][1]); } ans = min(ans, max(l+r, sum)); } return ans; } int main() { ios_base :: sync_with_stdio(false); cin.tie(NULL); cin >> R >> C; cin >> N; vector<pll> p(N); for (ll i=0; i<N; i++) { cin >> p[i].first >> p[i].second; } sort(p.begin(), p.end()); ll ans = inf; for (ll i=1; i<=2*R; i++) { ans = min(ans, i - 1 + solve(p, i)); } cout << ans << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 4 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 344 KB | Output is correct |
24 | Correct | 15 ms | 600 KB | Output is correct |
25 | Correct | 7 ms | 348 KB | Output is correct |
26 | Correct | 58 ms | 472 KB | Output is correct |
27 | Correct | 40 ms | 348 KB | Output is correct |
28 | Correct | 16 ms | 480 KB | Output is correct |
29 | Correct | 35 ms | 348 KB | Output is correct |
30 | Correct | 45 ms | 472 KB | Output is correct |
31 | Correct | 43 ms | 468 KB | Output is correct |
32 | Correct | 40 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 4 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 344 KB | Output is correct |
24 | Correct | 15 ms | 600 KB | Output is correct |
25 | Correct | 7 ms | 348 KB | Output is correct |
26 | Correct | 58 ms | 472 KB | Output is correct |
27 | Correct | 40 ms | 348 KB | Output is correct |
28 | Correct | 16 ms | 480 KB | Output is correct |
29 | Correct | 35 ms | 348 KB | Output is correct |
30 | Correct | 45 ms | 472 KB | Output is correct |
31 | Correct | 43 ms | 468 KB | Output is correct |
32 | Correct | 40 ms | 348 KB | Output is correct |
33 | Correct | 3 ms | 348 KB | Output is correct |
34 | Correct | 17 ms | 496 KB | Output is correct |
35 | Correct | 39 ms | 348 KB | Output is correct |
36 | Correct | 34 ms | 344 KB | Output is correct |
37 | Correct | 27 ms | 500 KB | Output is correct |
38 | Correct | 33 ms | 600 KB | Output is correct |
39 | Correct | 31 ms | 600 KB | Output is correct |
40 | Correct | 40 ms | 348 KB | Output is correct |
41 | Correct | 24 ms | 600 KB | Output is correct |
42 | Correct | 30 ms | 348 KB | Output is correct |
43 | Correct | 30 ms | 500 KB | Output is correct |
44 | Correct | 36 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2025 ms | 344 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2025 ms | 344 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 344 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 0 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 4 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 344 KB | Output is correct |
24 | Correct | 15 ms | 600 KB | Output is correct |
25 | Correct | 7 ms | 348 KB | Output is correct |
26 | Correct | 58 ms | 472 KB | Output is correct |
27 | Correct | 40 ms | 348 KB | Output is correct |
28 | Correct | 16 ms | 480 KB | Output is correct |
29 | Correct | 35 ms | 348 KB | Output is correct |
30 | Correct | 45 ms | 472 KB | Output is correct |
31 | Correct | 43 ms | 468 KB | Output is correct |
32 | Correct | 40 ms | 348 KB | Output is correct |
33 | Correct | 3 ms | 348 KB | Output is correct |
34 | Correct | 17 ms | 496 KB | Output is correct |
35 | Correct | 39 ms | 348 KB | Output is correct |
36 | Correct | 34 ms | 344 KB | Output is correct |
37 | Correct | 27 ms | 500 KB | Output is correct |
38 | Correct | 33 ms | 600 KB | Output is correct |
39 | Correct | 31 ms | 600 KB | Output is correct |
40 | Correct | 40 ms | 348 KB | Output is correct |
41 | Correct | 24 ms | 600 KB | Output is correct |
42 | Correct | 30 ms | 348 KB | Output is correct |
43 | Correct | 30 ms | 500 KB | Output is correct |
44 | Correct | 36 ms | 348 KB | Output is correct |
45 | Execution timed out | 2025 ms | 344 KB | Time limit exceeded |
46 | Halted | 0 ms | 0 KB | - |