#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define PB push_back
#define PPB pop_back
#define all(x) (x).begin(), (x).end()
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
const int MAXN = 47;
const int logo = 21;
const int off = 1 << logo;
const int trsz = off << 1;
const int mod = 1e9 + 7;
const int inf = mod;
vii inp;
int pf[MAXN][MAXN];
int n, r, c;
int check(int a, int b, int e){
for(int i=1; i<=r; i++) for(int j=1; j<=c; j++) pf[i][j] = 0;
for(auto &x : inp){
int up = max(1, x.X - a);
int dwn = min(r, x.X + b);
int le = max(1, x.Y - e);
int ri = x.Y;
pf[up][le]++;
if(ri != c) pf[up][ri + 1]--;
if(dwn != r){
pf[dwn + 1][le]--;
if(ri != c) pf[dwn + 1][ri + 1]++;
}
}
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
pf[i][j] += pf[i - 1][j];
}
}
for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
pf[i][j] += pf[i][j - 1];
}
}
int ret = 0;
for(int i=1; i<=r; i++){
int ls = -1;
for(int j=1; j<=c; j++){
if(pf[i][j] == 0 and ls == -1) ret = inf;
if(pf[i][j] == 0) ret = max(ret, j - ls);
else ls = j;
}
}
return ret;
}
void solve(){
cin >> r >> c >> n;
for(int i=1; i<=n; i++){
int x, y;
cin >> x >> y;
inp.PB({x, y});
}
int ans = inf;
for(int i=0; i<=r; i++){
for(int j=0; j<=r; j++){
for(int k=0; k<=c; k++){
ans = min(ans, i + j + k + check(i, j, k));
}
}
}
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tt = 1;
//cin >> t;
while(tt--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
31 ms |
460 KB |
Output is correct |
19 |
Correct |
200 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
163 ms |
444 KB |
Output is correct |
22 |
Correct |
292 ms |
440 KB |
Output is correct |
23 |
Correct |
299 ms |
444 KB |
Output is correct |
24 |
Correct |
302 ms |
348 KB |
Output is correct |
25 |
Correct |
294 ms |
348 KB |
Output is correct |
26 |
Correct |
324 ms |
348 KB |
Output is correct |
27 |
Correct |
323 ms |
452 KB |
Output is correct |
28 |
Correct |
282 ms |
348 KB |
Output is correct |
29 |
Correct |
260 ms |
600 KB |
Output is correct |
30 |
Correct |
331 ms |
348 KB |
Output is correct |
31 |
Correct |
333 ms |
348 KB |
Output is correct |
32 |
Correct |
321 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
31 ms |
460 KB |
Output is correct |
19 |
Correct |
200 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
163 ms |
444 KB |
Output is correct |
22 |
Correct |
292 ms |
440 KB |
Output is correct |
23 |
Correct |
299 ms |
444 KB |
Output is correct |
24 |
Correct |
302 ms |
348 KB |
Output is correct |
25 |
Correct |
294 ms |
348 KB |
Output is correct |
26 |
Correct |
324 ms |
348 KB |
Output is correct |
27 |
Correct |
323 ms |
452 KB |
Output is correct |
28 |
Correct |
282 ms |
348 KB |
Output is correct |
29 |
Correct |
260 ms |
600 KB |
Output is correct |
30 |
Correct |
331 ms |
348 KB |
Output is correct |
31 |
Correct |
333 ms |
348 KB |
Output is correct |
32 |
Correct |
321 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
348 KB |
Output is correct |
18 |
Correct |
31 ms |
460 KB |
Output is correct |
19 |
Correct |
200 ms |
348 KB |
Output is correct |
20 |
Correct |
6 ms |
348 KB |
Output is correct |
21 |
Correct |
163 ms |
444 KB |
Output is correct |
22 |
Correct |
292 ms |
440 KB |
Output is correct |
23 |
Correct |
299 ms |
444 KB |
Output is correct |
24 |
Correct |
302 ms |
348 KB |
Output is correct |
25 |
Correct |
294 ms |
348 KB |
Output is correct |
26 |
Correct |
324 ms |
348 KB |
Output is correct |
27 |
Correct |
323 ms |
452 KB |
Output is correct |
28 |
Correct |
282 ms |
348 KB |
Output is correct |
29 |
Correct |
260 ms |
600 KB |
Output is correct |
30 |
Correct |
331 ms |
348 KB |
Output is correct |
31 |
Correct |
333 ms |
348 KB |
Output is correct |
32 |
Correct |
321 ms |
348 KB |
Output is correct |
33 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |