#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const ll maxn = 310;
int n, r, c;
int x[maxn], y[maxn];
int used[maxn];
void solve()
{
cin >> r >> c;
cin >> n;
for (ll i = 1; i <= n; i ++)
cin >> x[i] >> y[i];
int res = r + c - 2;
for (int up = 0; up <= r; up ++)
for (int id = 1; id <= n; id ++)
{
int dw = x[id] - 1;
int atl_lf = 0, atl_rf = 0, atl_sum = 0;
for (int i = 1; i <= r; i ++)
{
set < int > pos;
for (int j = 1; j <= n; j ++)
{
if (i < x[j])
{
if (x[j] - dw <= i)
pos.insert(y[j]);
}
else
{
if (x[j] + up >= i)
pos.insert(y[j]);
}
}
if (pos.empty())
{
atl_sum = 1e9;
break;
}
atl_lf = max(atl_lf, *pos.begin() - 1);
atl_rf = max(atl_rf, c - *pos.rbegin());
for (set < int > :: iterator it = pos.begin(); next(it) != pos.end(); it ++)
{
atl_sum = max(atl_sum, *next(it) - *it - 1);
}
}
//cout << "data " << up << " " << dw << " " << atl_lf << " " << atl_rf << " " << atl_sum << endl;
res = min(res, up + dw + max(atl_sum, atl_lf + atl_rf));
}
cout << res << endl;
}
int main()
{
solve();
return 0;
}
/**
40 30
50
19 20
18 16
34 28
5 8
28 21
24 13
7 1
28 23
28 18
12 6
3 6
18 8
40 27
22 19
23 22
8 6
9 12
16 10
27 25
26 19
4 9
40 26
21 22
10 8
5 2
30 25
12 12
3 1
24 14
5 3
4 8
19 9
21 16
6 3
38 29
27 20
37 25
36 24
22 20
29 26
30 19
16 14
3 3
39 25
5 7
20 15
13 12
33 30
27 16
25 14
1000000000 1000000000
25
496770868 499466029
150245306 140351260
443861207 442170127
915815913 907024280
592352731 580300173
614771420 602707761
545759771 564678204
790963611 795646738
466306333 474998682
700037062 710428701
326403486 341417980
13108429 18468915
296795338 282907012
207909366 219254859
617032761 616107308
248155618 254253131
284599784 288724312
68437874 69050438
36863359 47496556
343816887 338965809
560430677 554034425
327115091 319475338
290706522 308826179
799518444 796166899
438981788 441006320
1000000000 1000000000
17
822413671 70423910
260075513 431043546
300945721 793553248
142848049 163787897
392462410 831950868
699005697 111397300
444396260 130450496
642691616 595456084
467968916 463598810
159764248 611476406
929313754 539645102
365153650 964108073
906780716 373514044
970118116 655138295
257280896 236115217
909808245 942097331
523555293 969550238
*/
Compilation message
cultivation.cpp: In function 'void solve()':
cultivation.cpp:17:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
17 | for (ll i = 1; i <= n; i ++)
| ^~~
cultivation.cpp:21:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
21 | int res = r + c - 2;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
592 KB |
Output is correct |
18 |
Correct |
53 ms |
348 KB |
Output is correct |
19 |
Correct |
28 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
88 ms |
348 KB |
Output is correct |
22 |
Correct |
502 ms |
412 KB |
Output is correct |
23 |
Correct |
37 ms |
344 KB |
Output is correct |
24 |
Correct |
1409 ms |
412 KB |
Output is correct |
25 |
Correct |
871 ms |
412 KB |
Output is correct |
26 |
Execution timed out |
2021 ms |
344 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
592 KB |
Output is correct |
18 |
Correct |
53 ms |
348 KB |
Output is correct |
19 |
Correct |
28 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
88 ms |
348 KB |
Output is correct |
22 |
Correct |
502 ms |
412 KB |
Output is correct |
23 |
Correct |
37 ms |
344 KB |
Output is correct |
24 |
Correct |
1409 ms |
412 KB |
Output is correct |
25 |
Correct |
871 ms |
412 KB |
Output is correct |
26 |
Execution timed out |
2021 ms |
344 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2032 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2032 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
592 KB |
Output is correct |
18 |
Correct |
53 ms |
348 KB |
Output is correct |
19 |
Correct |
28 ms |
348 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |
21 |
Correct |
88 ms |
348 KB |
Output is correct |
22 |
Correct |
502 ms |
412 KB |
Output is correct |
23 |
Correct |
37 ms |
344 KB |
Output is correct |
24 |
Correct |
1409 ms |
412 KB |
Output is correct |
25 |
Correct |
871 ms |
412 KB |
Output is correct |
26 |
Execution timed out |
2021 ms |
344 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |