| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 239563 | MrRobot_28 | Spirale (COCI18_spirale) | C++17 | 41 ms | 384 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 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 | 
|---|---|---|---|---|
| Fetching results... | ||||
