Submission #1018489

# Submission time Handle Problem Language Result Execution time Memory
1018489 2024-07-10T06:16:16 Z vjudge1 Spirale (COCI18_spirale) C++17
80 / 80
43 ms 460 KB
#include <bits/stdc++.h>

using namespace std;

const int M = 50;

int n,m,ans[M][M],sz;

void mod(int x,int y,int val)
{
	if (x>=0 && x<n && y>=0 && y<m)
		ans[x][y]=min(ans[x][y],val);
}

void iter(int x,int y,int dx,int dy,int t)
{
	for (int i=0;i<t;i++)
		mod(x,y,sz++),x+=dx,y+=dy;
}

void spiral(int x,int y,int d)
{
	if (d)
	{
		sz=1;
		ans[x][y]=0;
		for (int del=1;del<max(n,m);del++)
		{
			iter(x-del,y+del-1,0,-1,del*2);
			iter(x-del+1,y-del,1,0,del*2);
			iter(x+del,y-del+1,0,1,del*2);
			iter(x+del-1,y+del,-1,0,del*2);
		}
	}
	else
	{
		sz=1;
		ans[x][y]=0;
		for (int del=1;del<max(n,m);del++)
		{
			iter(x-del,y-del+1,0,1,del*2);
			iter(x-del+1,y+del,1,0,del*2);
			iter(x+del,y+del-1,0,-1,del*2);
			iter(x+del-1,y-del,-1,0,del*2);
		}
	}
}

int main()
{
	int k;
	cin>>n>>m>>k;
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
			ans[i][j]=10000;
	for (int i=0;i<k;i++)
	{
		int x,y,d;
		cin>>x>>y>>d;
		x--,y--;
		spiral(x,y,d);
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
			cout<<ans[i][j]+1<<' ';
		cout<<endl;
	}
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 436 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 436 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 43 ms 460 KB Output is correct
10 Correct 1 ms 344 KB Output is correct