#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=55;
int const mod=1e9+7;
int n,m,k;
vector<pair<int,int>> clo;
vector<pair<int,int>> ani;
int ans[N][N];
int solve(int x,int y,int r,int c){
r-=x;
c-=y;
if(c>r){//even
int d=max(abs(r),abs(c));
int v=((d*2)-1)*((d*2)-1);
v+=c+r+2*d;
return v;
}
else{//odd
int d=max(abs(r),abs(c));
int v=(d*2)*(d*2);
v+=(d+1)-c;
v+=d-r;
return v;
}
}
int main(){
cin>>n>>m>>k;
for (int i = 0; i < k; ++i)
{
int x,y,t;
cin>>x>>y>>t;
if(t==0)
clo.push_back({x,y});
else
ani.push_back({x,y});
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ans[i][j]=1e9;
for(auto [x,y]:clo)
ans[i][j]=min(ans[i][j],solve(x,y,i,j));
for(auto [x,y]:ani)
ans[i][j]=min(ans[i][j],solve(x,y,i,(y*2)-j));
cout<<ans[i][j]<<' ';
}
cout<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
19 ms |
496 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |