Submission #560816

#TimeUsernameProblemLanguageResultExecution timeMemory
560816amunduzbaevCultivation (JOI17_cultivation)C++17
15 / 100
216 ms596 KiB
#include "bits/stdc++.h" using namespace std; #define ar array #define int long long 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 res = R + C; auto check = [&](int a, int c){ vector<vector<int>> row(R + 1); for(int i=0;i<n;i++){ //~ x[i] - a, x[i] + c int l = max(1ll, x[i] - a), r = min(R, x[i] + c); for(int j=l;j<=r;j++) row[j].push_back(y[i]); } int A = 0, B = 0, D = 0; for(int i=1;i<=R;i++){ if(row[i].empty()) return; sort(row[i].begin(), row[i].end()); for(int j=1;j<(int)row[i].size();j++){ D = max(D, row[i][j] - row[i][j-1] - 1); } A = max(A, row[i][0] - 1); B = max(B, C - row[i].back()); } res = min(res, a + c + max(A + B, D)); }; for(int a=0;a<R;a++){ for(int c=0;a+c<R;c++){ check(a, c); } } cout<<res<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...