# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
801604 |
2023-08-02T06:51:49 Z |
GEN 이지후(#10129) |
Cultivation (JOI17_cultivation) |
C++17 |
|
2000 ms |
20152 KB |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<lint, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
lint sumFixed(lint r, lint c, lint g, vector<pi> a) {
vector<array<lint, 3>> event;
for (auto &[x, y] : a) {
event.push_back({x, y, +1});
event.push_back({x + 1 + g, y, -1});
}
event.push_back({0, -1, 0});
event.push_back({r + g, -1, 0});
sort(all(event));
multiset<lint> s;
vector<array<lint, 5>> chop;
vector<lint> crd;
for (int i = 0; i < sz(event);) {
int j = i;
while (j < sz(event) && event[i][0] == event[j][0]) {
if (event[j][2] == +1)
s.insert(event[j][1]);
else if (event[j][2] == -1)
s.erase(s.find(event[j][1]));
j++;
}
if (j == sz(event))
break;
lint lmax = 0, rmax = 0, lrmax = 0;
if (sz(s) == 0) {
lmax = 1e18;
rmax = 1e18;
} else {
lmax = max(lmax, *s.begin());
rmax = max(rmax, c - 1 - *s.rbegin());
{
auto it = s.begin();
while (next(it) != s.end()) {
lrmax = max(lrmax, *next(it) - *it - 1);
it++;
}
}
}
chop.push_back({event[i][0], event[j][0], lmax, rmax, lrmax});
crd.push_back(min(g, event[i][0]));
crd.push_back(max(0ll, event[j][0] - r));
i = j;
}
sort(all(crd));
crd.resize(unique(all(crd)) - crd.begin());
int k = 0;
priority_queue<pi> pq1, pq2, pq3;
lint ans = 1e18;
for (auto &x : crd) {
while (k < sz(chop) && chop[k][0] < x + r) {
pq1.push({chop[k][2], chop[k][1]});
pq2.push({chop[k][3], chop[k][1]});
pq3.push({chop[k][4], chop[k][1]});
k++;
}
while (sz(pq1) && pq1.top()[1] <= x)
pq1.pop();
while (sz(pq2) && pq2.top()[1] <= x)
pq2.pop();
while (sz(pq3) && pq3.top()[1] <= x)
pq3.pop();
ans = min(ans, max(pq1.top()[0] + pq2.top()[0], pq3.top()[0]));
}
return ans;
}
map<pi, lint> mp;
lint solve(lint r, lint c, lint dl, lint dr, vector<pi> a) {
if (mp.count({dl, dr}))
return mp[pi{dl, dr}];
vector<array<lint, 3>> event;
for (auto &[x, y] : a) {
int l = max(0ll, x - dl);
int e = min(r * 1ll, x + 1 + dr);
event.push_back({l, y, +1});
event.push_back({e, y, -1});
}
sort(all(event));
if (event[0][0] != 0 || event.back()[0] != r)
return mp[pi{dl, dr}] = 1e18;
lint lmax = 0, rmax = 0, lrmax = 0;
multiset<lint> s;
for (int i = 0; i < sz(event);) {
int j = i;
while (j < sz(event) && event[i][0] == event[j][0]) {
if (event[j][2] == +1)
s.insert(event[j][1]);
else
s.erase(s.find(event[j][1]));
j++;
}
if (j == sz(event))
break;
if (sz(s) == 0)
return mp[pi{dl, dr}] = 1e18;
lmax = max(lmax, *s.begin());
rmax = max(rmax, c - 1 - *s.rbegin());
{
auto it = s.begin();
while (next(it) != s.end()) {
lrmax = max(lrmax, *next(it) - *it - 1);
it++;
}
}
i = j;
}
return mp[pi{dl, dr}] = max(lmax + rmax, lrmax);
}
// n^4
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, r, c;
cin >> r >> c >> n;
vector<pi> a(n);
for (auto &[x, y] : a)
cin >> x >> y, x--, y--;
sort(all(a));
lint ans = 1e18;
vector<lint> gaps = {0};
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[j][0] > a[i][0])
gaps.push_back(a[j][0] - a[i][0] - 1);
}
}
sort(all(gaps));
gaps.resize(unique(all(gaps)) - gaps.begin());
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans = min(ans, a[i][0] + r - 1 - a[j][0] + solve(r, c, a[i][0], r - 1 - a[j][0], a));
}
}
for (auto &dy : gaps) {
ans = min(ans, sumFixed(r, c, dy, a) + dy);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
18 ms |
648 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
18 ms |
404 KB |
Output is correct |
22 |
Correct |
80 ms |
1420 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
152 ms |
596 KB |
Output is correct |
25 |
Correct |
106 ms |
516 KB |
Output is correct |
26 |
Correct |
245 ms |
856 KB |
Output is correct |
27 |
Correct |
243 ms |
984 KB |
Output is correct |
28 |
Correct |
133 ms |
596 KB |
Output is correct |
29 |
Correct |
222 ms |
920 KB |
Output is correct |
30 |
Correct |
248 ms |
956 KB |
Output is correct |
31 |
Correct |
263 ms |
856 KB |
Output is correct |
32 |
Correct |
254 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
18 ms |
648 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
18 ms |
404 KB |
Output is correct |
22 |
Correct |
80 ms |
1420 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
152 ms |
596 KB |
Output is correct |
25 |
Correct |
106 ms |
516 KB |
Output is correct |
26 |
Correct |
245 ms |
856 KB |
Output is correct |
27 |
Correct |
243 ms |
984 KB |
Output is correct |
28 |
Correct |
133 ms |
596 KB |
Output is correct |
29 |
Correct |
222 ms |
920 KB |
Output is correct |
30 |
Correct |
248 ms |
956 KB |
Output is correct |
31 |
Correct |
263 ms |
856 KB |
Output is correct |
32 |
Correct |
254 ms |
984 KB |
Output is correct |
33 |
Correct |
13 ms |
644 KB |
Output is correct |
34 |
Correct |
189 ms |
984 KB |
Output is correct |
35 |
Correct |
260 ms |
856 KB |
Output is correct |
36 |
Correct |
246 ms |
984 KB |
Output is correct |
37 |
Correct |
195 ms |
984 KB |
Output is correct |
38 |
Correct |
248 ms |
984 KB |
Output is correct |
39 |
Correct |
238 ms |
984 KB |
Output is correct |
40 |
Correct |
239 ms |
984 KB |
Output is correct |
41 |
Correct |
62 ms |
728 KB |
Output is correct |
42 |
Correct |
161 ms |
984 KB |
Output is correct |
43 |
Correct |
223 ms |
856 KB |
Output is correct |
44 |
Correct |
268 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
8 ms |
352 KB |
Output is correct |
4 |
Correct |
8 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
8 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
8 ms |
340 KB |
Output is correct |
11 |
Correct |
8 ms |
344 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
8 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
6 ms |
340 KB |
Output is correct |
19 |
Correct |
9 ms |
340 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
7 ms |
340 KB |
Output is correct |
3 |
Correct |
8 ms |
352 KB |
Output is correct |
4 |
Correct |
8 ms |
336 KB |
Output is correct |
5 |
Correct |
8 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
8 ms |
348 KB |
Output is correct |
9 |
Correct |
5 ms |
340 KB |
Output is correct |
10 |
Correct |
8 ms |
340 KB |
Output is correct |
11 |
Correct |
8 ms |
344 KB |
Output is correct |
12 |
Correct |
8 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
8 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
6 ms |
340 KB |
Output is correct |
19 |
Correct |
9 ms |
340 KB |
Output is correct |
20 |
Correct |
10 ms |
384 KB |
Output is correct |
21 |
Correct |
901 ms |
11564 KB |
Output is correct |
22 |
Correct |
1135 ms |
3376 KB |
Output is correct |
23 |
Correct |
1209 ms |
3960 KB |
Output is correct |
24 |
Correct |
1152 ms |
4812 KB |
Output is correct |
25 |
Correct |
1178 ms |
3372 KB |
Output is correct |
26 |
Correct |
365 ms |
688 KB |
Output is correct |
27 |
Correct |
1103 ms |
20152 KB |
Output is correct |
28 |
Correct |
1179 ms |
7156 KB |
Output is correct |
29 |
Correct |
1145 ms |
2324 KB |
Output is correct |
30 |
Correct |
1152 ms |
11976 KB |
Output is correct |
31 |
Correct |
1192 ms |
7280 KB |
Output is correct |
32 |
Correct |
1093 ms |
7712 KB |
Output is correct |
33 |
Correct |
1153 ms |
1060 KB |
Output is correct |
34 |
Correct |
1174 ms |
2700 KB |
Output is correct |
35 |
Correct |
1171 ms |
9680 KB |
Output is correct |
36 |
Correct |
1249 ms |
16632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
18 ms |
648 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
18 ms |
404 KB |
Output is correct |
22 |
Correct |
80 ms |
1420 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
152 ms |
596 KB |
Output is correct |
25 |
Correct |
106 ms |
516 KB |
Output is correct |
26 |
Correct |
245 ms |
856 KB |
Output is correct |
27 |
Correct |
243 ms |
984 KB |
Output is correct |
28 |
Correct |
133 ms |
596 KB |
Output is correct |
29 |
Correct |
222 ms |
920 KB |
Output is correct |
30 |
Correct |
248 ms |
956 KB |
Output is correct |
31 |
Correct |
263 ms |
856 KB |
Output is correct |
32 |
Correct |
254 ms |
984 KB |
Output is correct |
33 |
Correct |
13 ms |
644 KB |
Output is correct |
34 |
Correct |
189 ms |
984 KB |
Output is correct |
35 |
Correct |
260 ms |
856 KB |
Output is correct |
36 |
Correct |
246 ms |
984 KB |
Output is correct |
37 |
Correct |
195 ms |
984 KB |
Output is correct |
38 |
Correct |
248 ms |
984 KB |
Output is correct |
39 |
Correct |
238 ms |
984 KB |
Output is correct |
40 |
Correct |
239 ms |
984 KB |
Output is correct |
41 |
Correct |
62 ms |
728 KB |
Output is correct |
42 |
Correct |
161 ms |
984 KB |
Output is correct |
43 |
Correct |
223 ms |
856 KB |
Output is correct |
44 |
Correct |
268 ms |
984 KB |
Output is correct |
45 |
Correct |
3 ms |
340 KB |
Output is correct |
46 |
Correct |
7 ms |
340 KB |
Output is correct |
47 |
Correct |
8 ms |
352 KB |
Output is correct |
48 |
Correct |
8 ms |
336 KB |
Output is correct |
49 |
Correct |
8 ms |
340 KB |
Output is correct |
50 |
Correct |
6 ms |
340 KB |
Output is correct |
51 |
Correct |
2 ms |
340 KB |
Output is correct |
52 |
Correct |
8 ms |
348 KB |
Output is correct |
53 |
Correct |
5 ms |
340 KB |
Output is correct |
54 |
Correct |
8 ms |
340 KB |
Output is correct |
55 |
Correct |
8 ms |
344 KB |
Output is correct |
56 |
Correct |
8 ms |
384 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
4 ms |
340 KB |
Output is correct |
59 |
Correct |
4 ms |
340 KB |
Output is correct |
60 |
Correct |
8 ms |
384 KB |
Output is correct |
61 |
Correct |
9 ms |
340 KB |
Output is correct |
62 |
Correct |
6 ms |
340 KB |
Output is correct |
63 |
Correct |
9 ms |
340 KB |
Output is correct |
64 |
Correct |
10 ms |
384 KB |
Output is correct |
65 |
Correct |
901 ms |
11564 KB |
Output is correct |
66 |
Correct |
1135 ms |
3376 KB |
Output is correct |
67 |
Correct |
1209 ms |
3960 KB |
Output is correct |
68 |
Correct |
1152 ms |
4812 KB |
Output is correct |
69 |
Correct |
1178 ms |
3372 KB |
Output is correct |
70 |
Correct |
365 ms |
688 KB |
Output is correct |
71 |
Correct |
1103 ms |
20152 KB |
Output is correct |
72 |
Correct |
1179 ms |
7156 KB |
Output is correct |
73 |
Correct |
1145 ms |
2324 KB |
Output is correct |
74 |
Correct |
1152 ms |
11976 KB |
Output is correct |
75 |
Correct |
1192 ms |
7280 KB |
Output is correct |
76 |
Correct |
1093 ms |
7712 KB |
Output is correct |
77 |
Correct |
1153 ms |
1060 KB |
Output is correct |
78 |
Correct |
1174 ms |
2700 KB |
Output is correct |
79 |
Correct |
1171 ms |
9680 KB |
Output is correct |
80 |
Correct |
1249 ms |
16632 KB |
Output is correct |
81 |
Execution timed out |
2059 ms |
940 KB |
Time limit exceeded |
82 |
Halted |
0 ms |
0 KB |
- |