#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int maxn = 310, maxc = 42;
int n, r, c;
int used[4 * maxc][4 * maxc];
int x[maxn], y[maxn];
void solve()
{
cin >> r >> c;
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> x[i] >> y[i];
int ans = r + c - 2;
for (int h = 1; h <= r * 2; h ++)
for (int w = 1; w <= c * 2; w ++)
{
for (int i = 0; i < 4 * maxc; i ++)
for (int j = 0; j < 4 * maxc; j ++)
used[i][j] = 0;
for (int i = 1; i <= n; i ++)
{
for (int dx = x[i]; dx < x[i] + h; dx ++)
for (int dy = y[i]; dy < y[i] + w; dy ++)
{
///assert(dx < 2 * maxc && dy < 2 * maxc);
used[dx][dy] = 1;
}
}
bool done = false;
for (int sx = 0; sx < 2 * maxc && !done; sx ++)
for (int sy = 0; sy < 2 * maxc; sy ++)
{
bool tf = true;
for (int i = sx; i < sx + r && tf; i ++)
for (int j = sy; j < sy + c; j ++)
{
///assert(i < 2 * maxc && j <2 * maxc);
if (used[i][j] == 0)
{
//if (h == 25 && w == 29)
//cout << sx << " : " << sy << " " << i << " " << j << endl;
tf = false;
break;
}
}
if (tf)
{
done = true;
break;
}
}
/*if (h == 3 && w == 2)
{
for (int i = 1; i <= 8; i ++, cout << endl)
for (int j = 1; j <= 8; j ++)
cout << used[i][j] << " ";
}*/
/**cout <<"------------------------------" << endl;
if (h == 2)
exit(0);
for (int i = 0; i < 2 * r; i ++, cout << endl)
for (int j = 0; j < 2 * c; j ++)
cout << used[i][j] << " ";*/
if (done)
{
///cout << h << " : " << w << endl;
//exit(0);
ans = min(ans, h + w - 2);
break;
}
}
cout << ans << 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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
540 KB |
Output is correct |
19 |
Correct |
101 ms |
516 KB |
Output is correct |
20 |
Correct |
5 ms |
536 KB |
Output is correct |
21 |
Correct |
146 ms |
516 KB |
Output is correct |
22 |
Correct |
27 ms |
344 KB |
Output is correct |
23 |
Correct |
625 ms |
524 KB |
Output is correct |
24 |
Correct |
22 ms |
344 KB |
Output is correct |
25 |
Correct |
31 ms |
348 KB |
Output is correct |
26 |
Correct |
34 ms |
348 KB |
Output is correct |
27 |
Correct |
12 ms |
348 KB |
Output is correct |
28 |
Correct |
38 ms |
348 KB |
Output is correct |
29 |
Correct |
7 ms |
548 KB |
Output is correct |
30 |
Correct |
20 ms |
440 KB |
Output is correct |
31 |
Correct |
10 ms |
348 KB |
Output is correct |
32 |
Correct |
12 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
540 KB |
Output is correct |
19 |
Correct |
101 ms |
516 KB |
Output is correct |
20 |
Correct |
5 ms |
536 KB |
Output is correct |
21 |
Correct |
146 ms |
516 KB |
Output is correct |
22 |
Correct |
27 ms |
344 KB |
Output is correct |
23 |
Correct |
625 ms |
524 KB |
Output is correct |
24 |
Correct |
22 ms |
344 KB |
Output is correct |
25 |
Correct |
31 ms |
348 KB |
Output is correct |
26 |
Correct |
34 ms |
348 KB |
Output is correct |
27 |
Correct |
12 ms |
348 KB |
Output is correct |
28 |
Correct |
38 ms |
348 KB |
Output is correct |
29 |
Correct |
7 ms |
548 KB |
Output is correct |
30 |
Correct |
20 ms |
440 KB |
Output is correct |
31 |
Correct |
10 ms |
348 KB |
Output is correct |
32 |
Correct |
12 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
540 KB |
Output is correct |
19 |
Correct |
101 ms |
516 KB |
Output is correct |
20 |
Correct |
5 ms |
536 KB |
Output is correct |
21 |
Correct |
146 ms |
516 KB |
Output is correct |
22 |
Correct |
27 ms |
344 KB |
Output is correct |
23 |
Correct |
625 ms |
524 KB |
Output is correct |
24 |
Correct |
22 ms |
344 KB |
Output is correct |
25 |
Correct |
31 ms |
348 KB |
Output is correct |
26 |
Correct |
34 ms |
348 KB |
Output is correct |
27 |
Correct |
12 ms |
348 KB |
Output is correct |
28 |
Correct |
38 ms |
348 KB |
Output is correct |
29 |
Correct |
7 ms |
548 KB |
Output is correct |
30 |
Correct |
20 ms |
440 KB |
Output is correct |
31 |
Correct |
10 ms |
348 KB |
Output is correct |
32 |
Correct |
12 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |