Submission #1018548

#TimeUsernameProblemLanguageResultExecution timeMemory
1018548vjudge1Spirale (COCI18_spirale)C++17
80 / 80
19 ms496 KiB
#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 timeMemoryGrader output
Fetching results...