답안 #1018548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018548 2024-07-10T06:42:16 Z vjudge1 Spirale (COCI18_spirale) C++17
80 / 80
19 ms 496 KB
#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;
}
# 결과 실행 시간 메모리 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