fork download
  1. #include <iostream>
  2. using namespace std;
  3. typedef long long ll;
  4. int main(){
  5. int t, n, m;
  6. cin >> t;
  7. while (t--){
  8. cin >> n >> m;
  9. if (m >= 2 * n) cout << "No\n";
  10. else{
  11. cout << "Yes\n";
  12. for (int i = 0; i < 2 * n; ++i){
  13. for (int j = 0; j < m; ++j) cout << (j + i) / 2 % n + 1 << " ";
  14. cout << "\n";
  15. }
  16. }
  17. }
  18. }
Success #stdin #stdout 0.01s 5268KB
stdin
1
4 6
stdout
Yes
1 1 2 2 3 3 
1 2 2 3 3 4 
2 2 3 3 4 4 
2 3 3 4 4 1 
3 3 4 4 1 1 
3 4 4 1 1 2 
4 4 1 1 2 2 
4 1 1 2 2 3