Submission #953447

#TimeUsernameProblemLanguageResultExecution timeMemory
953447Darren0724Cultivation (JOI17_cultivation)C++17
0 / 100
54 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define LCBorz ios_base::sync_with_stdio(false); cin.tie(0); #define all(x) x.begin(), x.end() #define endl '\n' const int N=200005; const int INF=1e9; int32_t main() { LCBorz; int r,c;cin>>r>>c; int n;cin>>n; vector dis(r+2,vector(c+2,INF)); vector<int> a(n),b(n); for(int i=0;i<n;i++){ cin>>a[i]>>b[i]; dis[a[i]][b[i]]=0; } vector<int> dx={1,-1,0,0},dy={0,0,1,-1}; queue<pair<int,int>> q; auto check=[&](int a,int b){ return (a>0&&a<=r&&b>0&&b<=r&&dis[a][b]==INF); }; int ans=0; for(int k=0;k<4;k++){ for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ if(dis[i][j]!=INF){ dis[i][j]=0; q.push({i,j}); } } } int mx=0; while(q.size()){ auto [a,b]=q.front(); q.pop(); mx=max(mx,dis[a][b]); int c=a+dx[k]; int d=b+dy[k]; if(check(c,d)){ dis[c][d]=dis[a][b]+1; q.push({c,d}); } } ans+=mx; } cout<<ans<<endl; return 0; }
#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...