Submission #560470

#TimeUsernameProblemLanguageResultExecution timeMemory
560470amunduzbaevCultivation (JOI17_cultivation)C++17
5 / 100
98 ms262144 KiB
#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 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...