#include "bits/stdc++.h"
using namespace std;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int R, C; cin>>R>>C;
int n; cin>>n;
vector<int> x(n), y(n);
for(int i=0;i<n;i++){
cin>>x[i]>>y[i];
}
int N = 2 * R, M = 2 * C;
auto check = [&](int a, int b){
vector<vector<int>> g(N + 1, vector<int>(M + 1));
vector<vector<int>> t(N + 1, vector<int>(M + 1));
for(int i=0;i<n;i++){
g[x[i]][y[i]]++;
g[x[i] + a][y[i]]--;
g[x[i]][y[i] + b]--;
g[x[i] + a][y[i] + b]++;
}
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
g[i][j] += g[i-1][j] + g[i][j-1] - g[i-1][j-1];
if(g[i][j]) t[i][j] = 1;
t[i][j] += t[i-1][j] + t[i][j-1] - t[i-1][j-1];
}
}
//~ cout<<a<<" "<<b<<"\n";
//~ for(int i=1;i<=N;i++){
//~ for(int j=1;j<=M;j++){
//~ cout<<(g[i][j] > 0)<<" ";
//~ } cout<<"\n";
//~ } cout<<"\n";
for(int i=R;i<=N;i++){
for(int j=C;j<=M;j++){
int cnt = t[i][j] - t[i-R][j] - t[i][j-C] + t[i-R][j-C];
if(cnt == R * C){
return true;
}
}
}
return false;
};
int res = R + C;
for(int a=1;a<=R;a++){
for(int b=1;b<=C;b++){
if(check(a, b)) res = min(res, a + b - 2);
}
}
cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
324 KB |
Output is correct |
19 |
Correct |
41 ms |
352 KB |
Output is correct |
20 |
Correct |
5 ms |
212 KB |
Output is correct |
21 |
Incorrect |
32 ms |
340 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
324 KB |
Output is correct |
19 |
Correct |
41 ms |
352 KB |
Output is correct |
20 |
Correct |
5 ms |
212 KB |
Output is correct |
21 |
Incorrect |
32 ms |
340 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
98 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
98 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
324 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 |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
324 KB |
Output is correct |
19 |
Correct |
41 ms |
352 KB |
Output is correct |
20 |
Correct |
5 ms |
212 KB |
Output is correct |
21 |
Incorrect |
32 ms |
340 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |