Submission #1338559

#TimeUsernameProblemLanguageResultExecution timeMemory
1338559rafsanamin2020Gardening (RMI21_gardening)C++20
0 / 100
11 ms532 KiB
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
ll MOD = 1E9 + 7, MX = 1E6 + 2;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++)
  {
    int n, m, k;
    cin >> n >> m >> k;

    if (n % 2 == 0)
    {
      vector<vector<int>> g(m, vector<int>(m, 0));
      if ((n * n) / 4 == k)
      {
        cout << "YES\n";
        int strt = 1;

        int rev = 0;

        for (int i = 0; i < m; i++)
        {
          for (int j = 0; j < m; j++)
          {
            if ((j == m - 1) && (m % 2 > 0))
            {

              g[i][j] = strt + (j / 2) - 1;
            }
            else
            {
              g[i][j] = strt + (j / 2);
            }
          }

          if (rev)
          {
            reverse(g[i].begin(), g[i].end());
          }

          if (i % 2 == 1 && i != m - 2)
          {
            strt += (m / 2);
            rev ^= 1;
          }
          // cout << "\n";
        }

        map<int, int> mapping;

        int ans = (n * n) / 4;

        while (ans > 0)
        {
          if (ans < k)
          {
            k--;
          }
          mapping[ans] = k;

          ans--;
        }

        for (int i = 0; i < m; i++)
        {
          for (int j = 0; j < m; j++)
          {
            g[i][j] = mapping[g[i][j]];
          }
        }

        for (vector<int> x : g)
        {
          for (int y : x)
          {
            cout << y << " ";
          }
          cout << "\n";
        }
      }
      else if (n / 2 == k)
      {
        cout << "YES\n";
        for (int i = 0; i < m; i++)
        {
          for (int j = 0; j < m; j++)
          {
            g[i][j] = min(min(i, m - i - 1), min(j, m - j - 1));
            g[i][j]++;

            cout << g[i][j] << " ";
          }
          cout << "\n";
        }
      }
      else
      {
        cout << "NO\n";
      }
    }
    else
    {
      cout << "NO\n";
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...