Submission details
Task:Ruudukko
Sender:jubidubi
Submission time:2025-09-28 16:17:34 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.01 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 101;
int grid[N][N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int ttt;
  cin >> ttt;
  while (ttt--) {
    int h, w;
    cin >> h >> w;

    if (h <= 2 && w <= 2) {
      cout << "NO" << endl;
      continue;
    }

    if (min(h, w) == 1 && max(h, w) <= 3) {
      cout << "NO" << endl;
      continue;
    }

    if (w == 1 && h == 4) {
      cout << "YES" << endl;
      cout << "2\n4\n1\n3" << endl;
      continue;
    }

    if (w == 4 && h == 1) {
      cout << "YES" << endl;
      cout << "2 4 1 3" << endl;
      continue;
    }

    if (w == 2 && h == 3) {
      cout << "YES" << endl;
      cout << "2 4" << endl;
      cout << "6 1" << endl;
      cout << "3 5" << endl;
      continue;
    }

    if (w == 3 && h == 2) {
      cout << "YES" << endl;
      cout << "4 1 5" << endl;
      cout << "2 6 3" << endl;
      continue;
    }

    int val = 1;
    for (int d = 0; d < w + h; ++d) {
      if (w > h) {
        int x = 0;
        int y = d;
        while (y >= 0) {
          if (x < w && y < h) {
            grid[y][x] = val;
            val += 2;
            if (val > w * h) val = 2;
          }
          y -= 1;
          x += 1;
        }
      } else {
        int x = d;
        int y = 0;
        while (x >= 0) {
          if (x < w && y < h) {
            grid[y][x] = val;
            val += 2;
            if (val > w * h) val = 2;
          }
          y += 1;
          x -= 1;
        }
      }
    }
    cout << "YES" << endl;
    for (int y = 0; y < h; ++y) {
      for (int x = 0; x < w; ++x) cout << grid[y][x] << " ";
      cout << endl;
    }
  }
}

Test details

Test 1

Verdict:

input
100
1 1
1 2
2 1
1 3
...

correct output
YES
1
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...