Task: | Ruudukko |
Sender: | Sisuaski |
Submission time: | 2025-09-27 06:07:36 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:12:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses] 12 | if (n==2 && m==2 || n==1 && m==2 || n==1 && m==3) { | ~~~~~^~~~~~~ input/code.cpp:12:58: warning: suggest parentheses around '&&' within '||' [-Wparentheses] 12 | if (n==2 && m==2 || n==1 && m==2 || n==1 && m==3) { | ~~~~~^~~~~~~
Code
#include <iostream> #include <cstring> using namespace std; int res[12][12]; int main() { int t;cin>>t; while(t--){ memset(res,0,sizeof(res)); int n,m;cin>>n>>m; bool s=0; if (n>m) swap(n,m),s=1; if (n==2 && m==2 || n==1 && m==2 || n==1 && m==3) { cout<<"NO\n"; continue; } int c=1; for(int i=1; i<n*m; i+=2) res[i/m][i%m]=c++; for(int i=0; i<n*m; i+=2) res[i/m][i%m]=c++; cout<<"YES\n"; if (s) { for(int i=0; i<n; ++i) for(int j=i+1; j<m; ++j) swap(res[i][j],res[j][i]); swap(n,m); } for(int i=0; i<n; ++i) { for(int j=0; j<m; ++j) cout<<res[i][j]<<' '; cout<<'\n'; } } }