#include<bits/stdc++.h>
using namespace std;
#define int short int
#define fi first
#define se second
#define pb push_back
#define ins insert
#define er erase
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
int n, r, c, s[305], e[305], pref[45][45], ans = 10005;
bool ck(int up, int left, int down, int right){
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++) pref[i][j] = 0;
}
for(int i = 1; i <= n; i++){
pref[max(1, s[i] - up)][max(1, e[i] - left)]++;
pref[min(r + 1, s[i] + down + 1)][max(1, e[i] - left)]--;
pref[max(1, s[i] - up)][min(c + 1, e[i] + right + 1)]--;
pref[min(r + 1, s[i] + down + 1)][min(c + 1, e[i] + right + 1)]++;
//cout << max(1, s[i] - up) << " " << max(1, e[i] - left) << " " << min(r + 1, s[i] + down + 1) << " " << min(c + 1, e[i] + right) << "\n";
}
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++) pref[i][j] += pref[i][j - 1];
}
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
pref[i][j] += pref[i - 1][j];
if(!pref[i][j]) return 0;
}
}
return 1;
}
int mini(int a, int b){
return ((a < b) ? a : b);
}
signed main(){
//freopen("cultivation.inp", "r", stdin);
//freopen("cultivation.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> r >> c >> n;
for(int i = 1; i <= n; i++) cin >> s[i] >> e[i];
//cout << ck(0, 1, 2, 2) << "\n";
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
int itr = c - 1, temp = i + j - 1;
for(int k = 0; k <= r - 1; k++){
while(itr >= 0 && ck(i, j, k, itr)) --itr;
++itr;
++temp;
//cout << i << " " << j << " " << k << " " << itr << " " << temp + itr << "\n";
if(ck(i, j, k, itr)) ans = mini(ans, temp + itr);
}
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
14 ms |
384 KB |
Output is correct |
18 |
Correct |
154 ms |
384 KB |
Output is correct |
19 |
Correct |
1065 ms |
504 KB |
Output is correct |
20 |
Correct |
43 ms |
384 KB |
Output is correct |
21 |
Correct |
847 ms |
388 KB |
Output is correct |
22 |
Correct |
1743 ms |
504 KB |
Output is correct |
23 |
Correct |
1737 ms |
504 KB |
Output is correct |
24 |
Correct |
1799 ms |
504 KB |
Output is correct |
25 |
Correct |
1826 ms |
504 KB |
Output is correct |
26 |
Execution timed out |
2051 ms |
384 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
14 ms |
384 KB |
Output is correct |
18 |
Correct |
154 ms |
384 KB |
Output is correct |
19 |
Correct |
1065 ms |
504 KB |
Output is correct |
20 |
Correct |
43 ms |
384 KB |
Output is correct |
21 |
Correct |
847 ms |
388 KB |
Output is correct |
22 |
Correct |
1743 ms |
504 KB |
Output is correct |
23 |
Correct |
1737 ms |
504 KB |
Output is correct |
24 |
Correct |
1799 ms |
504 KB |
Output is correct |
25 |
Correct |
1826 ms |
504 KB |
Output is correct |
26 |
Execution timed out |
2051 ms |
384 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
14 ms |
384 KB |
Output is correct |
18 |
Correct |
154 ms |
384 KB |
Output is correct |
19 |
Correct |
1065 ms |
504 KB |
Output is correct |
20 |
Correct |
43 ms |
384 KB |
Output is correct |
21 |
Correct |
847 ms |
388 KB |
Output is correct |
22 |
Correct |
1743 ms |
504 KB |
Output is correct |
23 |
Correct |
1737 ms |
504 KB |
Output is correct |
24 |
Correct |
1799 ms |
504 KB |
Output is correct |
25 |
Correct |
1826 ms |
504 KB |
Output is correct |
26 |
Execution timed out |
2051 ms |
384 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |