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;
// #define int long long
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int r,c,n;
cin >> r >> c >> n;
vector<pair<int,int>> points(n);
for(auto&[a,b]:points)cin>>a>>b;
int minX = 1e9;
int minY = 1e9;
for(auto&[a,b]:points) {
minX=min(a,minX);
minY=min(b,minY);
}
minX=minY=50;
int tar = r*c;
auto check = [&](int chosenR,int chosenC){
vector grid(101,vector(101,0));
for(auto&[x,y]:points) {
grid[x][y]++;
grid[x+chosenR][y]--;
grid[x][y+chosenC]--;
grid[x+chosenR][y+chosenC]++;
}
for(int i=1;i<=100;i++) {
for(int j=1;j<=100;j++) {
grid[i][j]+=grid[i][j-1];
}
}
for(int i=1;i<=100;i++) {
for(int j=1;j<=100;j++) {
grid[j][i]+=grid[j-1][i];
}
}
for(int i=1;i<=100;i++) {
for(int j=1;j<=100;j++) {
grid[i][j]=min(1,grid[i][j])+grid[i-1][j]+grid[i][j-1]-grid[i-1][j-1];
}
}
auto get = [&](int x1,int y1,int x2,int y2) {
return grid[x2][y2]-grid[x1-1][y2]-grid[x2][y1-1]+grid[x1-1][y1-1];
};
for(int i=1;i<minX+chosenR;i++) {
for(int j=1;j<minY+chosenC;j++) {
if(get(i,j,i+r-1,j+c-1)==tar)return true;
}
}
return false;
};
int ans = r+c-2;
for(int R=1;R<=r;R++) {
for(int C=1;C<=c;C++) {
if(check(R,C)) {
ans=min(ans,R+C-2);
}
}
}
cout << ans << '\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... |