This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
}
auto check = [&](int a, int c, int b, int d){
vector<vector<int>> g(R + 1, vector<int>(C + 1));
for(int i=0;i<n;i++){
int lx = max(1, x[i] - a), rx = min(R, x[i] + c), ly = max(1, y[i] - b), ry = min(C, y[i] + d);
g[lx][ly]++;
if(ry < C) g[lx][ry+1]--;
if(rx < R) g[rx+1][ly]--;
if(rx < R && ry < C) g[rx+1][ry+1]++;
}
for(int i=1;i<=R;i++){
for(int j=1;j<=C;j++){
g[i][j] += g[i-1][j] + g[i][j-1] - g[i-1][j-1];
if(!g[i][j]) return false;
}
}
return true;
};
int res = R + C;
for(int a=0;a<R;a++){
for(int b=0;b<C;b++){
for(int c=0;a+c<R;c++){
for(int d=0;b+d<C;d++){
if(check(a, c, b, d)) res = min(res, a + b + c + d);
}
}
}
}
cout<<res<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |