| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1018554 | vjudge1 | Spirale (COCI18_spirale) | C++17 | 57 ms | 572 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;
vector<vector<int> > create(int n)
{
  int c = n / 2;
  vector<vector<int> > ans(n, vector<int> (n));
  vector<pair<int,int> > moves(n * n + 1, {2, 2});
  for(int i = 1; i <= n; i += 2)
    moves[i * i] = {-1, 0}, moves[i * i + 1] = {0, 1};
  for(int i = 2; i <= n; i += 2)
    moves[i * i] = {1, 0}, moves[i * i + 1] = {0, -1};
  for(int i = 1; i < n; i ++)
    {
      int idx = (i * i + (i + 1) * (i + 1) + 1) / 2;
      if(i % 2 == 1)
	moves[idx] = {1, 0};
      else
	moves[idx] = {-1, 0};
    }
  for(int i = 1; i <= n * n; i ++)
    if(moves[i].first == 2) moves[i] = moves[i - 1];
  int x = c, y = c;
  for(int i = 1; i <= n * n; i++)
    {
      ans[x][y] = i;
      x += moves[i].first;
      y += moves[i].second;
      
    }
  return ans; 
}
int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  int ans[n][m];
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m ; j ++)
      ans[i][j] = 1e8;
  
  while(k--)
    {
      int x, y, d;
      cin >> x >> y >> d;
      x--, y--; // how much row and cols do we need
      int sz = max(max(x, n - x - 1), max(y, m - y - 1)) * 2 + 1;
      
      vector<vector<int> > grid = create(sz);
      if(d)
	for(vector<int> &vec : grid)
	  reverse(vec.begin(), vec.end());
      for(int i = 0; i < n; i ++)
	for(int j = 0; j < m; j ++)
	  {
	    int x1 = i - x + sz / 2, y1 = j - y + sz / 2;
	    ans[i][j] = min(ans[i][j], grid[x1][y1]);
	  }
    }
  
  
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m; j ++)
      cout << ans[i][j] << " \n"[j == m - 1];
  return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
