Submission details
Task:Ruudukko
Sender:Lieska
Submission time:2025-09-26 18:43:20 +0300
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.00 sdetails

Code

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

typedef long long ll;

int t[11][11];


void test(){
    int n, m;
    cin >> n >> m;
    
    if ((n==1 && m<= 3) || (n <= 3 && m==1) || (n==2 && m==2) ) {
        cout << "NO\n";
        return;
    }
    
    cout << "YES\n";
    
    if (m >= 3) {
        int a = 1, b = n*m/2+1;
        bool nexta = false;
        
        // The following works if n>=3 and m >= 2.
        for (int i=1; i<=n; ++i){
            for (int j=1; j<=m; ++j){
                if (nexta){
                    cout << a << " ";
                    a++;
                }
                else {
                    cout << b << " ";
                    b++;
                }
                nexta = 1 - nexta;
            }
            cout << "\n";
        }
    }
    else {
        int a = 1, b = n*m/2+1;
        bool nexta = false;
        
        // The following works if n>=3 and m >= 2.
        for (int j=1; j<=m; ++j){
            for (int i=1; i<=n; ++i){
                if (nexta){
                    t[i][j] = a;
                    a++;
                }
                else {
                    t[i][j] = b;
                    b++;
                }
                nexta = 1 - nexta;
            }
        }
            
        for (int i=1; i<=n; ++i){
            for (int j=1; j<=m; ++j){
                cout << t[i][j] << " ";
            }
            cout << "\n";
        }
    }
}

int main(){
    int t;
    cin >> t;
    for (int i=0; i<t; ++i){
        test();
    }
    
}

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
...