# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
59825 |
2018-07-23T07:36:47 Z |
김세빈(#1725) |
Cultivation (JOI17_cultivation) |
C++11 |
|
2000 ms |
1644 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
pll P[333];
ll K[666][666];
vector <int> L, R;
ll n, h, w, ans = 1e18;
ll check(ll l, ll r)
{
ll x, y, d, i, j, s, e, t, prev;
vector <ll> X, Y;
for(i=1; i<=n; i++){
x = P[i].first - l;
X.push_back(x);
x = P[i].first + r + 1;
X.push_back(x);
Y.push_back(P[i].second);
}
X.push_back(1); Y.push_back(1);
X.push_back(h); Y.push_back(w);
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
for(i=1; i<=X.size(); i++){
for(j=1; j<=Y.size(); j++){
K[i][j] = 0;
}
}
for(i=1; i<=n; i++){
s = lower_bound(X.begin(), X.end(), P[i].first - l) - X.begin() + 1;
e = lower_bound(X.begin(), X.end(), P[i].first + r + 1) - X.begin() + 1;
y = lower_bound(Y.begin(), Y.end(), P[i].second) - Y.begin() + 1;
for(j=s; j<e; j++) K[j][y] = i;
}
s = lower_bound(X.begin(), X.end(), 1) - X.begin() + 1;
e = lower_bound(X.begin(), X.end(), h) - X.begin() + 1;
x = y = d = 0;
for(i=s; i<=e; i++){
prev = -1;
for(j=1; j<=Y.size(); j++){
if(K[i][j]){
t = K[i][j];
if(prev == -1) x = max(x, P[t].second - 1);
else d = max(d, P[t].second - P[prev].second - 1);
prev = t;
}
}
if(prev == -1) return 1e18;
y = max(y, w - P[prev].second);
}
return x + y + max(0ll, d - x - y);
}
int main()
{
ll i, j, k;
scanf("%lld%lld%lld", &h, &w, &n);
for(i=1; i<=n; i++){
scanf("%lld%lld", &P[i].first, &P[i].second);
}
sort(P + 1, P + n + 1);
for(i=1; i<=n; i++){
L.push_back(P[i].first - 1);
for(j=1; j<i; j++){
if(P[i].first != P[j].first) L.push_back(P[i].first - P[j].first - 1);
}
R.push_back(h - P[i].first);
for(j=n; j>i; j--){
if(P[i].first != P[j].first) R.push_back(P[j].first - P[i].first - 1);
}
}
sort(L.begin(), L.end());
L.erase(unique(L.begin(), L.end()), L.end());
sort(R.begin(), R.end());
R.erase(unique(R.begin(), R.end()), R.end());
for(i=0; i<L.size(); i++){
for(j=0; j<R.size(); j++){
k = check(L[i], R[j]) + L[i] + R[j];
ans = min(ans, k);
if(L[i] >= R[j]) k = check(L[i] - R[j], R[j]) + L[i];
ans = min(ans, k);
if(L[i] <= R[j]) k = check(L[i], R[j] - L[i]) + R[j];
ans = min(ans, k);
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message
cultivation.cpp: In function 'll check(ll, ll)':
cultivation.cpp:36:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1; i<=X.size(); i++){
~^~~~~~~~~~
cultivation.cpp:37:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=1; j<=Y.size(); j++){
~^~~~~~~~~~
cultivation.cpp:56:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=1; j<=Y.size(); j++){
~^~~~~~~~~~
cultivation.cpp: In function 'int main()':
cultivation.cpp:100:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<L.size(); i++){
~^~~~~~~~~
cultivation.cpp:101:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0; j<R.size(); j++){
~^~~~~~~~~
cultivation.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld", &h, &w, &n);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &P[i].first, &P[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
3 ms |
572 KB |
Output is correct |
4 |
Correct |
3 ms |
572 KB |
Output is correct |
5 |
Correct |
3 ms |
572 KB |
Output is correct |
6 |
Correct |
4 ms |
644 KB |
Output is correct |
7 |
Correct |
4 ms |
648 KB |
Output is correct |
8 |
Correct |
4 ms |
648 KB |
Output is correct |
9 |
Correct |
4 ms |
648 KB |
Output is correct |
10 |
Correct |
3 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
648 KB |
Output is correct |
12 |
Correct |
3 ms |
648 KB |
Output is correct |
13 |
Correct |
5 ms |
648 KB |
Output is correct |
14 |
Correct |
2 ms |
648 KB |
Output is correct |
15 |
Correct |
3 ms |
648 KB |
Output is correct |
16 |
Correct |
2 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
3 ms |
572 KB |
Output is correct |
4 |
Correct |
3 ms |
572 KB |
Output is correct |
5 |
Correct |
3 ms |
572 KB |
Output is correct |
6 |
Correct |
4 ms |
644 KB |
Output is correct |
7 |
Correct |
4 ms |
648 KB |
Output is correct |
8 |
Correct |
4 ms |
648 KB |
Output is correct |
9 |
Correct |
4 ms |
648 KB |
Output is correct |
10 |
Correct |
3 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
648 KB |
Output is correct |
12 |
Correct |
3 ms |
648 KB |
Output is correct |
13 |
Correct |
5 ms |
648 KB |
Output is correct |
14 |
Correct |
2 ms |
648 KB |
Output is correct |
15 |
Correct |
3 ms |
648 KB |
Output is correct |
16 |
Correct |
2 ms |
648 KB |
Output is correct |
17 |
Correct |
5 ms |
648 KB |
Output is correct |
18 |
Correct |
25 ms |
720 KB |
Output is correct |
19 |
Correct |
18 ms |
976 KB |
Output is correct |
20 |
Correct |
3 ms |
976 KB |
Output is correct |
21 |
Correct |
51 ms |
976 KB |
Output is correct |
22 |
Correct |
110 ms |
1024 KB |
Output is correct |
23 |
Correct |
6 ms |
1024 KB |
Output is correct |
24 |
Correct |
191 ms |
1212 KB |
Output is correct |
25 |
Correct |
155 ms |
1212 KB |
Output is correct |
26 |
Correct |
271 ms |
1356 KB |
Output is correct |
27 |
Correct |
250 ms |
1356 KB |
Output is correct |
28 |
Correct |
170 ms |
1356 KB |
Output is correct |
29 |
Correct |
202 ms |
1356 KB |
Output is correct |
30 |
Correct |
294 ms |
1424 KB |
Output is correct |
31 |
Correct |
247 ms |
1424 KB |
Output is correct |
32 |
Correct |
255 ms |
1516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
3 ms |
572 KB |
Output is correct |
4 |
Correct |
3 ms |
572 KB |
Output is correct |
5 |
Correct |
3 ms |
572 KB |
Output is correct |
6 |
Correct |
4 ms |
644 KB |
Output is correct |
7 |
Correct |
4 ms |
648 KB |
Output is correct |
8 |
Correct |
4 ms |
648 KB |
Output is correct |
9 |
Correct |
4 ms |
648 KB |
Output is correct |
10 |
Correct |
3 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
648 KB |
Output is correct |
12 |
Correct |
3 ms |
648 KB |
Output is correct |
13 |
Correct |
5 ms |
648 KB |
Output is correct |
14 |
Correct |
2 ms |
648 KB |
Output is correct |
15 |
Correct |
3 ms |
648 KB |
Output is correct |
16 |
Correct |
2 ms |
648 KB |
Output is correct |
17 |
Correct |
5 ms |
648 KB |
Output is correct |
18 |
Correct |
25 ms |
720 KB |
Output is correct |
19 |
Correct |
18 ms |
976 KB |
Output is correct |
20 |
Correct |
3 ms |
976 KB |
Output is correct |
21 |
Correct |
51 ms |
976 KB |
Output is correct |
22 |
Correct |
110 ms |
1024 KB |
Output is correct |
23 |
Correct |
6 ms |
1024 KB |
Output is correct |
24 |
Correct |
191 ms |
1212 KB |
Output is correct |
25 |
Correct |
155 ms |
1212 KB |
Output is correct |
26 |
Correct |
271 ms |
1356 KB |
Output is correct |
27 |
Correct |
250 ms |
1356 KB |
Output is correct |
28 |
Correct |
170 ms |
1356 KB |
Output is correct |
29 |
Correct |
202 ms |
1356 KB |
Output is correct |
30 |
Correct |
294 ms |
1424 KB |
Output is correct |
31 |
Correct |
247 ms |
1424 KB |
Output is correct |
32 |
Correct |
255 ms |
1516 KB |
Output is correct |
33 |
Correct |
4 ms |
1516 KB |
Output is correct |
34 |
Correct |
282 ms |
1516 KB |
Output is correct |
35 |
Correct |
398 ms |
1516 KB |
Output is correct |
36 |
Correct |
509 ms |
1516 KB |
Output is correct |
37 |
Correct |
323 ms |
1516 KB |
Output is correct |
38 |
Correct |
526 ms |
1516 KB |
Output is correct |
39 |
Correct |
504 ms |
1520 KB |
Output is correct |
40 |
Correct |
468 ms |
1640 KB |
Output is correct |
41 |
Correct |
266 ms |
1640 KB |
Output is correct |
42 |
Correct |
326 ms |
1640 KB |
Output is correct |
43 |
Correct |
491 ms |
1640 KB |
Output is correct |
44 |
Correct |
415 ms |
1644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
1644 KB |
Output is correct |
2 |
Correct |
1214 ms |
1644 KB |
Output is correct |
3 |
Correct |
1329 ms |
1644 KB |
Output is correct |
4 |
Correct |
1446 ms |
1644 KB |
Output is correct |
5 |
Correct |
1576 ms |
1644 KB |
Output is correct |
6 |
Correct |
290 ms |
1644 KB |
Output is correct |
7 |
Correct |
16 ms |
1644 KB |
Output is correct |
8 |
Correct |
1252 ms |
1644 KB |
Output is correct |
9 |
Correct |
444 ms |
1644 KB |
Output is correct |
10 |
Correct |
1342 ms |
1644 KB |
Output is correct |
11 |
Correct |
1397 ms |
1644 KB |
Output is correct |
12 |
Correct |
1352 ms |
1644 KB |
Output is correct |
13 |
Correct |
68 ms |
1644 KB |
Output is correct |
14 |
Correct |
283 ms |
1644 KB |
Output is correct |
15 |
Correct |
95 ms |
1644 KB |
Output is correct |
16 |
Correct |
1370 ms |
1644 KB |
Output is correct |
17 |
Correct |
1243 ms |
1644 KB |
Output is correct |
18 |
Correct |
357 ms |
1644 KB |
Output is correct |
19 |
Correct |
1441 ms |
1644 KB |
Output is correct |
20 |
Correct |
1336 ms |
1644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
1644 KB |
Output is correct |
2 |
Correct |
1214 ms |
1644 KB |
Output is correct |
3 |
Correct |
1329 ms |
1644 KB |
Output is correct |
4 |
Correct |
1446 ms |
1644 KB |
Output is correct |
5 |
Correct |
1576 ms |
1644 KB |
Output is correct |
6 |
Correct |
290 ms |
1644 KB |
Output is correct |
7 |
Correct |
16 ms |
1644 KB |
Output is correct |
8 |
Correct |
1252 ms |
1644 KB |
Output is correct |
9 |
Correct |
444 ms |
1644 KB |
Output is correct |
10 |
Correct |
1342 ms |
1644 KB |
Output is correct |
11 |
Correct |
1397 ms |
1644 KB |
Output is correct |
12 |
Correct |
1352 ms |
1644 KB |
Output is correct |
13 |
Correct |
68 ms |
1644 KB |
Output is correct |
14 |
Correct |
283 ms |
1644 KB |
Output is correct |
15 |
Correct |
95 ms |
1644 KB |
Output is correct |
16 |
Correct |
1370 ms |
1644 KB |
Output is correct |
17 |
Correct |
1243 ms |
1644 KB |
Output is correct |
18 |
Correct |
357 ms |
1644 KB |
Output is correct |
19 |
Correct |
1441 ms |
1644 KB |
Output is correct |
20 |
Correct |
1336 ms |
1644 KB |
Output is correct |
21 |
Execution timed out |
2023 ms |
1644 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
3 ms |
572 KB |
Output is correct |
4 |
Correct |
3 ms |
572 KB |
Output is correct |
5 |
Correct |
3 ms |
572 KB |
Output is correct |
6 |
Correct |
4 ms |
644 KB |
Output is correct |
7 |
Correct |
4 ms |
648 KB |
Output is correct |
8 |
Correct |
4 ms |
648 KB |
Output is correct |
9 |
Correct |
4 ms |
648 KB |
Output is correct |
10 |
Correct |
3 ms |
648 KB |
Output is correct |
11 |
Correct |
2 ms |
648 KB |
Output is correct |
12 |
Correct |
3 ms |
648 KB |
Output is correct |
13 |
Correct |
5 ms |
648 KB |
Output is correct |
14 |
Correct |
2 ms |
648 KB |
Output is correct |
15 |
Correct |
3 ms |
648 KB |
Output is correct |
16 |
Correct |
2 ms |
648 KB |
Output is correct |
17 |
Correct |
5 ms |
648 KB |
Output is correct |
18 |
Correct |
25 ms |
720 KB |
Output is correct |
19 |
Correct |
18 ms |
976 KB |
Output is correct |
20 |
Correct |
3 ms |
976 KB |
Output is correct |
21 |
Correct |
51 ms |
976 KB |
Output is correct |
22 |
Correct |
110 ms |
1024 KB |
Output is correct |
23 |
Correct |
6 ms |
1024 KB |
Output is correct |
24 |
Correct |
191 ms |
1212 KB |
Output is correct |
25 |
Correct |
155 ms |
1212 KB |
Output is correct |
26 |
Correct |
271 ms |
1356 KB |
Output is correct |
27 |
Correct |
250 ms |
1356 KB |
Output is correct |
28 |
Correct |
170 ms |
1356 KB |
Output is correct |
29 |
Correct |
202 ms |
1356 KB |
Output is correct |
30 |
Correct |
294 ms |
1424 KB |
Output is correct |
31 |
Correct |
247 ms |
1424 KB |
Output is correct |
32 |
Correct |
255 ms |
1516 KB |
Output is correct |
33 |
Correct |
4 ms |
1516 KB |
Output is correct |
34 |
Correct |
282 ms |
1516 KB |
Output is correct |
35 |
Correct |
398 ms |
1516 KB |
Output is correct |
36 |
Correct |
509 ms |
1516 KB |
Output is correct |
37 |
Correct |
323 ms |
1516 KB |
Output is correct |
38 |
Correct |
526 ms |
1516 KB |
Output is correct |
39 |
Correct |
504 ms |
1520 KB |
Output is correct |
40 |
Correct |
468 ms |
1640 KB |
Output is correct |
41 |
Correct |
266 ms |
1640 KB |
Output is correct |
42 |
Correct |
326 ms |
1640 KB |
Output is correct |
43 |
Correct |
491 ms |
1640 KB |
Output is correct |
44 |
Correct |
415 ms |
1644 KB |
Output is correct |
45 |
Correct |
236 ms |
1644 KB |
Output is correct |
46 |
Correct |
1214 ms |
1644 KB |
Output is correct |
47 |
Correct |
1329 ms |
1644 KB |
Output is correct |
48 |
Correct |
1446 ms |
1644 KB |
Output is correct |
49 |
Correct |
1576 ms |
1644 KB |
Output is correct |
50 |
Correct |
290 ms |
1644 KB |
Output is correct |
51 |
Correct |
16 ms |
1644 KB |
Output is correct |
52 |
Correct |
1252 ms |
1644 KB |
Output is correct |
53 |
Correct |
444 ms |
1644 KB |
Output is correct |
54 |
Correct |
1342 ms |
1644 KB |
Output is correct |
55 |
Correct |
1397 ms |
1644 KB |
Output is correct |
56 |
Correct |
1352 ms |
1644 KB |
Output is correct |
57 |
Correct |
68 ms |
1644 KB |
Output is correct |
58 |
Correct |
283 ms |
1644 KB |
Output is correct |
59 |
Correct |
95 ms |
1644 KB |
Output is correct |
60 |
Correct |
1370 ms |
1644 KB |
Output is correct |
61 |
Correct |
1243 ms |
1644 KB |
Output is correct |
62 |
Correct |
357 ms |
1644 KB |
Output is correct |
63 |
Correct |
1441 ms |
1644 KB |
Output is correct |
64 |
Correct |
1336 ms |
1644 KB |
Output is correct |
65 |
Execution timed out |
2023 ms |
1644 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |