#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int R, C; cin>>R>>C;
int n; cin>>n;
vector<int> x(n), y(n);
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
int res = R + C;
auto check = [&](int a, int c){
vector<vector<int>> row(R + 1);
for(int i=0;i<n;i++){
//~ x[i] - a, x[i] + c
int l = max(1ll, x[i] - a), r = min(R, x[i] + c);
for(int j=l;j<=r;j++) row[j].push_back(y[i]);
}
int A = 0, B = 0, D = 0;
for(int i=1;i<=R;i++){
if(row[i].empty()) return;
sort(row[i].begin(), row[i].end());
for(int j=1;j<(int)row[i].size();j++){
D = max(D, row[i][j] - row[i][j-1] - 1);
}
A = max(A, row[i][0] - 1);
B = max(B, C - row[i].back());
}
res = min(res, a + c + max(A + B, D));
};
for(int a=0;a<R;a++){
for(int c=0;a+c<R;c++){
check(a, c);
}
}
cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
352 KB |
Output is correct |
19 |
Correct |
12 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
27 ms |
360 KB |
Output is correct |
22 |
Correct |
68 ms |
384 KB |
Output is correct |
23 |
Correct |
14 ms |
352 KB |
Output is correct |
24 |
Correct |
121 ms |
416 KB |
Output is correct |
25 |
Correct |
96 ms |
512 KB |
Output is correct |
26 |
Correct |
211 ms |
572 KB |
Output is correct |
27 |
Correct |
182 ms |
452 KB |
Output is correct |
28 |
Correct |
107 ms |
428 KB |
Output is correct |
29 |
Correct |
170 ms |
436 KB |
Output is correct |
30 |
Correct |
182 ms |
480 KB |
Output is correct |
31 |
Correct |
192 ms |
468 KB |
Output is correct |
32 |
Correct |
216 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
352 KB |
Output is correct |
19 |
Correct |
12 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
27 ms |
360 KB |
Output is correct |
22 |
Correct |
68 ms |
384 KB |
Output is correct |
23 |
Correct |
14 ms |
352 KB |
Output is correct |
24 |
Correct |
121 ms |
416 KB |
Output is correct |
25 |
Correct |
96 ms |
512 KB |
Output is correct |
26 |
Correct |
211 ms |
572 KB |
Output is correct |
27 |
Correct |
182 ms |
452 KB |
Output is correct |
28 |
Correct |
107 ms |
428 KB |
Output is correct |
29 |
Correct |
170 ms |
436 KB |
Output is correct |
30 |
Correct |
182 ms |
480 KB |
Output is correct |
31 |
Correct |
192 ms |
468 KB |
Output is correct |
32 |
Correct |
216 ms |
468 KB |
Output is correct |
33 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
352 KB |
Output is correct |
19 |
Correct |
12 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
27 ms |
360 KB |
Output is correct |
22 |
Correct |
68 ms |
384 KB |
Output is correct |
23 |
Correct |
14 ms |
352 KB |
Output is correct |
24 |
Correct |
121 ms |
416 KB |
Output is correct |
25 |
Correct |
96 ms |
512 KB |
Output is correct |
26 |
Correct |
211 ms |
572 KB |
Output is correct |
27 |
Correct |
182 ms |
452 KB |
Output is correct |
28 |
Correct |
107 ms |
428 KB |
Output is correct |
29 |
Correct |
170 ms |
436 KB |
Output is correct |
30 |
Correct |
182 ms |
480 KB |
Output is correct |
31 |
Correct |
192 ms |
468 KB |
Output is correct |
32 |
Correct |
216 ms |
468 KB |
Output is correct |
33 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |