# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35365 | pedro_sponchiado | Cultivation (JOI17_cultivation) | C++14 | 0 ms | 2084 KiB |
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;
const int maxn=310;
const int INF=2000000010;
int n, x[maxn], y[maxn], r, c, a, b;
int y_x[maxn];
int x_x[maxn];
vector<pair<int, int> > comp_x;
int marc[maxn][50];
int main(){
scanf("%d %d %d", &r, &c, &n);
for(int i=1; i<=n; i++){
scanf("%d %d", &a, &b);
comp_x.push_back(make_pair(b, a));
}
sort(comp_x.begin(), comp_x.end());
for(int i=0; i<comp_x.size(); i++){
x[i+1]=comp_x[i].first;
y[i+1]=comp_x[i].second;
// printf("%d %d\n", x[i+1], y[i+1]);
}
int resp=INF+10;
for(int cima=0; cima<=r; cima++){
for(int baixo=0; baixo<=r; baixo++){
for(int i=1; i<=n; i++){
for(int j=1; j<=r; j++){
marc[i][j]=0;
}
}
for(int i=1; i<=n; i++){
for(int j=0; j<=cima; j++){
if(y[i]+j<=r) marc[i][y[i]+j]=1;
}
for(int j=1; j<=baixo; j++){
if(y[i]-j>=0) marc[i][y[i]-j]=1;
}
}
/*for(int i=1; i<=r; i++){
for(int j=1; j<=c; j++){
printf("%d ", marc[j][i]);
}
printf("\n");
}
printf("\n");*/
int maxi=0;
int maxi_c=0;
int maxi_f=0;
int t=0;
for(int j=1; j<=r; j++){
int acumulado=0;
for(int i=1; i<=n; i++){
if(marc[i][j]==0) acumulado+=x[i]-x[i-1];
else if(marc[i][j]==1){
acumulado+=x[i]-x[i-1]-1;
if(i==1) maxi_c=max(maxi_c, x[i]-1);
else if(i==n) maxi_f=max(maxi_f, c-x[i]);
else maxi=max(maxi, acumulado);
}
}
if(acumulado==c){
t=1;
break;
}
}
if(t) break;
resp=min(resp, cima+baixo+max(maxi, maxi_c+maxi_f));
}
}
printf("%d\n", resp);
return 0;
}
Compilation message (stderr)
# | 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... |