#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef long long ll;
#define int ll
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
int sz; cin >> sz;
vector<int> x(sz), y(sz);
for(int i=0;i<sz;i++){
cin >> x[i] >> y[i];
}
vector<int> p(sz);
iota(p.begin(), p.end(), 0);
sort(p.begin(), p.end(), [&](int i, int j){
return y[i] < y[j];
});
int res = 2 * (n + m);
for(int u=0;u<n;u++){
for(int d=0;d<n;d++){
vector<vector<int>> used(n + 1);
for(auto i : p){
int l = max(1ll, x[i] - u), r = min(n, x[i] + d);
for(int j=l;j<=r;j++){
used[j].push_back(y[i]);
}
}
int mnl = 0, mnr = 0, mn = 0, ok = 1;
for(int i=1;i<=n;i++){
if(used[i].empty()){
ok = 0;
break;
}
mnl = max(mnl, used[i][0] - 1);
mnr = max(mnr, m - used[i].back());
for(int j=1;j<(int)used[i].size();j++){
//~ cout<<i<<" "<<used[i][j]<<" "<<used[i][j-1]<<"\n";
mn = max(mn, used[i][j] - used[i][j-1] - 1);
}
}
if(!ok) continue;
//~ cout<<u<<" "<<d<<" "<<mnl<<" "<<mnr<<" "<<mn<<"\n";
res = min(res, u + d + max(mnl + mnr, mn));
}
}
cout<<res<<"\n";
}
# |
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 |
1 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
356 KB |
Output is correct |
19 |
Correct |
21 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
29 ms |
340 KB |
Output is correct |
22 |
Correct |
56 ms |
388 KB |
Output is correct |
23 |
Correct |
25 ms |
340 KB |
Output is correct |
24 |
Correct |
78 ms |
408 KB |
Output is correct |
25 |
Correct |
64 ms |
404 KB |
Output is correct |
26 |
Correct |
105 ms |
516 KB |
Output is correct |
27 |
Correct |
99 ms |
512 KB |
Output is correct |
28 |
Correct |
71 ms |
432 KB |
Output is correct |
29 |
Correct |
86 ms |
508 KB |
Output is correct |
30 |
Correct |
107 ms |
520 KB |
Output is correct |
31 |
Correct |
100 ms |
508 KB |
Output is correct |
32 |
Correct |
103 ms |
516 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 |
1 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
356 KB |
Output is correct |
19 |
Correct |
21 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
29 ms |
340 KB |
Output is correct |
22 |
Correct |
56 ms |
388 KB |
Output is correct |
23 |
Correct |
25 ms |
340 KB |
Output is correct |
24 |
Correct |
78 ms |
408 KB |
Output is correct |
25 |
Correct |
64 ms |
404 KB |
Output is correct |
26 |
Correct |
105 ms |
516 KB |
Output is correct |
27 |
Correct |
99 ms |
512 KB |
Output is correct |
28 |
Correct |
71 ms |
432 KB |
Output is correct |
29 |
Correct |
86 ms |
508 KB |
Output is correct |
30 |
Correct |
107 ms |
520 KB |
Output is correct |
31 |
Correct |
100 ms |
508 KB |
Output is correct |
32 |
Correct |
103 ms |
516 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
91 ms |
528 KB |
Output is correct |
35 |
Correct |
100 ms |
532 KB |
Output is correct |
36 |
Correct |
99 ms |
520 KB |
Output is correct |
37 |
Correct |
68 ms |
496 KB |
Output is correct |
38 |
Correct |
101 ms |
528 KB |
Output is correct |
39 |
Correct |
100 ms |
524 KB |
Output is correct |
40 |
Correct |
102 ms |
524 KB |
Output is correct |
41 |
Correct |
87 ms |
512 KB |
Output is correct |
42 |
Correct |
89 ms |
512 KB |
Output is correct |
43 |
Correct |
95 ms |
512 KB |
Output is correct |
44 |
Correct |
103 ms |
540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 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 |
356 KB |
Output is correct |
19 |
Correct |
21 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
29 ms |
340 KB |
Output is correct |
22 |
Correct |
56 ms |
388 KB |
Output is correct |
23 |
Correct |
25 ms |
340 KB |
Output is correct |
24 |
Correct |
78 ms |
408 KB |
Output is correct |
25 |
Correct |
64 ms |
404 KB |
Output is correct |
26 |
Correct |
105 ms |
516 KB |
Output is correct |
27 |
Correct |
99 ms |
512 KB |
Output is correct |
28 |
Correct |
71 ms |
432 KB |
Output is correct |
29 |
Correct |
86 ms |
508 KB |
Output is correct |
30 |
Correct |
107 ms |
520 KB |
Output is correct |
31 |
Correct |
100 ms |
508 KB |
Output is correct |
32 |
Correct |
103 ms |
516 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
91 ms |
528 KB |
Output is correct |
35 |
Correct |
100 ms |
532 KB |
Output is correct |
36 |
Correct |
99 ms |
520 KB |
Output is correct |
37 |
Correct |
68 ms |
496 KB |
Output is correct |
38 |
Correct |
101 ms |
528 KB |
Output is correct |
39 |
Correct |
100 ms |
524 KB |
Output is correct |
40 |
Correct |
102 ms |
524 KB |
Output is correct |
41 |
Correct |
87 ms |
512 KB |
Output is correct |
42 |
Correct |
89 ms |
512 KB |
Output is correct |
43 |
Correct |
95 ms |
512 KB |
Output is correct |
44 |
Correct |
103 ms |
540 KB |
Output is correct |
45 |
Runtime error |
3 ms |
596 KB |
Execution killed with signal 6 |
46 |
Halted |
0 ms |
0 KB |
- |