Submission #239563

# Submission time Handle Problem Language Result Execution time Memory
239563 2020-06-16T11:23:23 Z MrRobot_28 Spirale (COCI18_spirale) C++17
80 / 80
41 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
//	ios_base::sync_with_stdio(false);
//	cin.tie(NULL);
//	cout.tie(NULL);
	int n, m, k;
	cin >> n >> m >> k;
	vector <vector <int> > mat(n, vector <int> (m, 1e18));
	for(int i = 0; i < k; i++) 
	{
		int x, y, t;
		cin >> x >> y >> t;
		x--;
		y--;
		if(t == 0)
		{
		for(int s1 = 0; s1 < n; s1++)
		{
			for(int s2 = 0; s2 < m; s2++){
				
				if(s1 == x && s2 == y)
				{
					mat[s1][s2] = 1;
					continue;
				}
				int e = max(abs(s1 - x) - 1, abs(s2 - y) - 1);
				int sq = (e * 2 + 1) * (e * 2 + 1);
				if(x - e - 1 == s1 && s2 >= y - e)
				{
					mat[s1][s2] = min(mat[s1][s2], sq + 1 + s2 - (y - e));
				}
				else if(y + e + 1 == s2 && s1 >= x - e - 1)
				{
					mat[s1][s2] = min(mat[s1][s2], sq + 2 + 2 * e + s1 - (x - e - 1));
				}
				else if(x + e + 1 == s1 && s2 <= y + e + 1)
				{
					mat[s1][s2] = min(mat[s1][s2], sq + 4 * e + 4 + (y + e + 1 - s2));
				}
				else
				{
					mat[s1][s2] = min(mat[s1][s2], sq + 6 * e + 6 + (x + 1 + e - s1));
				}
			}
		}
		}
		else
		{
			for(int s1 = 0; s1 < n; s1++)
			{
				for(int s2 = 0; s2 < m; s2++)
				{
					if(s1 == x && s2 == y)
					{
						mat[s1][s2] = 1;
						continue;
					}
					int e = max(abs(s1 - x), abs(s2 - y)) - 1;
					int sq = (2 * e + 1) * (2 * e + 1);
					if(s1 == x + e + 1 && s2 <= y + e + 1)
					{
						mat[s1][s2] = min(mat[s1][s2], sq + 4 * e + 4 + (s2 - (y - e - 1)));
					}
					else if(s2 == y - e - 1 && s1 <= x + e + 1)
					{
						mat[s1][s2] = min(mat[s1][s2], sq + 2 * e + 2 + (s1 - (x - e - 1)));
					}
					else if(s1 == x - e - 1 && s2 <= y + e)
					{
						mat[s1][s2] = min(mat[s1][s2], sq + 1 + (y + e - s2));
					}
					else
					{
						mat[s1][s2] = min(mat[s1][s2], sq + 6 * e + 6 + (x + e + 1 - s1));
					}
				}
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			cout << mat[i][j] << " ";
		}
		cout << "\n";
	}
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 41 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct