#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 305;
int n, r, c;
pi a[MAXN];
struct sweep{
int pos, val, mode;
bool operator<(const sweep &s)const{
return pi(pos, -mode) < pi(s.pos, -s.mode);
}
};
lint Do(int i, int j){
vector<sweep> sw;
for(int k=0; k<n; k++){
int le = max(1, a[k].first - i);
int ri = min(r, a[k].first + j);
int v = a[k].second;
sw.push_back({le, v, +1});
sw.push_back({ri + 1, v, -1});
}
vector<int> v = {1, r + 1};
for(int i=0; i<sw.size(); i++){
v.push_back(sw[i].pos);
}
sort(sw.begin(), sw.end());
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
multiset<int> s;
int ptr = 0;
int lv = 0, rv = 0, sum = 0;
for(int i=0; i+1<v.size(); i++){
while(ptr < sw.size() && sw[ptr].pos == v[i]){
if(sw[ptr].mode == 1) s.insert(sw[ptr].val);
else s.erase(s.find(sw[ptr].val));
ptr++;
}
if(s.size() == 0) return 1e18;
lv = max(lv, *s.begin() - 1);
rv = max(rv, c - *s.rbegin());
auto it = s.begin();
while(next(it) != s.end()){
auto in = next(it);
sum = max(*in - *it - 1, sum);
it = in;
}
}
return 1ll * max(lv + rv, sum) + i + j;
}
lint solve(){
lint ans = 1e18;
sort(a, a+n);
vector<int> v;
for(int i=0; i<n; i++){
v.push_back(a[i].first - 1);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for(auto &l : v){
vector<int> v;
for(int j=0; j<n; j++){
for(int k=j; k<n; k++){
if(a[k].first - a[j].first >= l) v.push_back(a[k].first - a[j].first - l);
}
v.push_back(r - a[j].first);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for(auto &j : v){
ans = min(ans, Do(l, j));
}
}
return ans;
}
int main(){
cin >> r >> c >> n;
for(int i=0; i<n; i++){
cin >> a[i].first >> a[i].second;
}
lint ans = solve();
for(int i=0; i<n; i++) a[i].first = r + 1 - a[i].first;
ans = min(ans, solve());
cout << ans << endl;
}
Compilation message
cultivation.cpp: In function 'lint Do(int, int)':
cultivation.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<sw.size(); i++){
~^~~~~~~~~~
cultivation.cpp:37:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i+1<v.size(); i++){
~~~^~~~~~~~~
cultivation.cpp:38:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ptr < sw.size() && sw[ptr].pos == v[i]){
~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
2 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
544 KB |
Output is correct |
12 |
Correct |
3 ms |
544 KB |
Output is correct |
13 |
Correct |
2 ms |
544 KB |
Output is correct |
14 |
Correct |
2 ms |
544 KB |
Output is correct |
15 |
Correct |
3 ms |
544 KB |
Output is correct |
16 |
Correct |
4 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
2 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
544 KB |
Output is correct |
12 |
Correct |
3 ms |
544 KB |
Output is correct |
13 |
Correct |
2 ms |
544 KB |
Output is correct |
14 |
Correct |
2 ms |
544 KB |
Output is correct |
15 |
Correct |
3 ms |
544 KB |
Output is correct |
16 |
Correct |
4 ms |
544 KB |
Output is correct |
17 |
Correct |
5 ms |
544 KB |
Output is correct |
18 |
Correct |
38 ms |
748 KB |
Output is correct |
19 |
Correct |
11 ms |
748 KB |
Output is correct |
20 |
Correct |
4 ms |
748 KB |
Output is correct |
21 |
Correct |
50 ms |
748 KB |
Output is correct |
22 |
Correct |
171 ms |
748 KB |
Output is correct |
23 |
Correct |
7 ms |
748 KB |
Output is correct |
24 |
Correct |
324 ms |
904 KB |
Output is correct |
25 |
Correct |
244 ms |
904 KB |
Output is correct |
26 |
Correct |
560 ms |
1060 KB |
Output is correct |
27 |
Correct |
612 ms |
1092 KB |
Output is correct |
28 |
Correct |
385 ms |
1092 KB |
Output is correct |
29 |
Correct |
531 ms |
1104 KB |
Output is correct |
30 |
Correct |
558 ms |
1104 KB |
Output is correct |
31 |
Correct |
591 ms |
1148 KB |
Output is correct |
32 |
Correct |
621 ms |
1152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
2 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
544 KB |
Output is correct |
12 |
Correct |
3 ms |
544 KB |
Output is correct |
13 |
Correct |
2 ms |
544 KB |
Output is correct |
14 |
Correct |
2 ms |
544 KB |
Output is correct |
15 |
Correct |
3 ms |
544 KB |
Output is correct |
16 |
Correct |
4 ms |
544 KB |
Output is correct |
17 |
Correct |
5 ms |
544 KB |
Output is correct |
18 |
Correct |
38 ms |
748 KB |
Output is correct |
19 |
Correct |
11 ms |
748 KB |
Output is correct |
20 |
Correct |
4 ms |
748 KB |
Output is correct |
21 |
Correct |
50 ms |
748 KB |
Output is correct |
22 |
Correct |
171 ms |
748 KB |
Output is correct |
23 |
Correct |
7 ms |
748 KB |
Output is correct |
24 |
Correct |
324 ms |
904 KB |
Output is correct |
25 |
Correct |
244 ms |
904 KB |
Output is correct |
26 |
Correct |
560 ms |
1060 KB |
Output is correct |
27 |
Correct |
612 ms |
1092 KB |
Output is correct |
28 |
Correct |
385 ms |
1092 KB |
Output is correct |
29 |
Correct |
531 ms |
1104 KB |
Output is correct |
30 |
Correct |
558 ms |
1104 KB |
Output is correct |
31 |
Correct |
591 ms |
1148 KB |
Output is correct |
32 |
Correct |
621 ms |
1152 KB |
Output is correct |
33 |
Correct |
8 ms |
1152 KB |
Output is correct |
34 |
Correct |
481 ms |
1152 KB |
Output is correct |
35 |
Correct |
547 ms |
1152 KB |
Output is correct |
36 |
Correct |
610 ms |
1152 KB |
Output is correct |
37 |
Correct |
444 ms |
1224 KB |
Output is correct |
38 |
Correct |
560 ms |
1284 KB |
Output is correct |
39 |
Correct |
544 ms |
1284 KB |
Output is correct |
40 |
Correct |
555 ms |
1284 KB |
Output is correct |
41 |
Correct |
194 ms |
1284 KB |
Output is correct |
42 |
Correct |
447 ms |
1284 KB |
Output is correct |
43 |
Correct |
540 ms |
1284 KB |
Output is correct |
44 |
Correct |
557 ms |
1284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1284 KB |
Output is correct |
2 |
Correct |
48 ms |
1284 KB |
Output is correct |
3 |
Correct |
53 ms |
1284 KB |
Output is correct |
4 |
Correct |
45 ms |
1284 KB |
Output is correct |
5 |
Correct |
52 ms |
1284 KB |
Output is correct |
6 |
Incorrect |
31 ms |
1284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1284 KB |
Output is correct |
2 |
Correct |
48 ms |
1284 KB |
Output is correct |
3 |
Correct |
53 ms |
1284 KB |
Output is correct |
4 |
Correct |
45 ms |
1284 KB |
Output is correct |
5 |
Correct |
52 ms |
1284 KB |
Output is correct |
6 |
Incorrect |
31 ms |
1284 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
416 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
2 ms |
544 KB |
Output is correct |
11 |
Correct |
3 ms |
544 KB |
Output is correct |
12 |
Correct |
3 ms |
544 KB |
Output is correct |
13 |
Correct |
2 ms |
544 KB |
Output is correct |
14 |
Correct |
2 ms |
544 KB |
Output is correct |
15 |
Correct |
3 ms |
544 KB |
Output is correct |
16 |
Correct |
4 ms |
544 KB |
Output is correct |
17 |
Correct |
5 ms |
544 KB |
Output is correct |
18 |
Correct |
38 ms |
748 KB |
Output is correct |
19 |
Correct |
11 ms |
748 KB |
Output is correct |
20 |
Correct |
4 ms |
748 KB |
Output is correct |
21 |
Correct |
50 ms |
748 KB |
Output is correct |
22 |
Correct |
171 ms |
748 KB |
Output is correct |
23 |
Correct |
7 ms |
748 KB |
Output is correct |
24 |
Correct |
324 ms |
904 KB |
Output is correct |
25 |
Correct |
244 ms |
904 KB |
Output is correct |
26 |
Correct |
560 ms |
1060 KB |
Output is correct |
27 |
Correct |
612 ms |
1092 KB |
Output is correct |
28 |
Correct |
385 ms |
1092 KB |
Output is correct |
29 |
Correct |
531 ms |
1104 KB |
Output is correct |
30 |
Correct |
558 ms |
1104 KB |
Output is correct |
31 |
Correct |
591 ms |
1148 KB |
Output is correct |
32 |
Correct |
621 ms |
1152 KB |
Output is correct |
33 |
Correct |
8 ms |
1152 KB |
Output is correct |
34 |
Correct |
481 ms |
1152 KB |
Output is correct |
35 |
Correct |
547 ms |
1152 KB |
Output is correct |
36 |
Correct |
610 ms |
1152 KB |
Output is correct |
37 |
Correct |
444 ms |
1224 KB |
Output is correct |
38 |
Correct |
560 ms |
1284 KB |
Output is correct |
39 |
Correct |
544 ms |
1284 KB |
Output is correct |
40 |
Correct |
555 ms |
1284 KB |
Output is correct |
41 |
Correct |
194 ms |
1284 KB |
Output is correct |
42 |
Correct |
447 ms |
1284 KB |
Output is correct |
43 |
Correct |
540 ms |
1284 KB |
Output is correct |
44 |
Correct |
557 ms |
1284 KB |
Output is correct |
45 |
Correct |
18 ms |
1284 KB |
Output is correct |
46 |
Correct |
48 ms |
1284 KB |
Output is correct |
47 |
Correct |
53 ms |
1284 KB |
Output is correct |
48 |
Correct |
45 ms |
1284 KB |
Output is correct |
49 |
Correct |
52 ms |
1284 KB |
Output is correct |
50 |
Incorrect |
31 ms |
1284 KB |
Output isn't correct |
51 |
Halted |
0 ms |
0 KB |
- |