# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1018548 | vjudge1 | Spirale (COCI18_spirale) | C++17 | 19 ms | 496 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;
#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 |
---|---|---|---|---|
Fetching results... |