Advertisement
Ankit_132

C

Sep 10th, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define pb     push_back
  9.  
  10.  
  11. int main()
  12. {
  13.     _test
  14.     {
  15.         int n, m;
  16.         cin>>n>>m;
  17.  
  18.         int maxMexPoss = min(n, m-1);
  19.  
  20.         vector<vector<int>> a(n, vector<int> (m));
  21.  
  22.         for(int i=0; i<n; i++)
  23.         {
  24.             for(int j=0; j<m; j++)
  25.                 a[i][j] = j;
  26.         }
  27.  
  28.         for(int i=1; i<maxMexPoss; i++)
  29.         {
  30.             for(int j=0; j<=maxMexPoss; j++)
  31.                 a[i][j] = a[i-1][(j+1)%(maxMexPoss+1)];
  32.         }
  33.  
  34.         for(int i=maxMexPoss; i<n; i++)
  35.             a[i] = a[0];
  36.  
  37.         cout<<maxMexPoss+1 - (m==1)<<"\n";
  38.         for(auto e: a)
  39.         {
  40.             for(auto f: e)
  41.                 cout<<f<<" ";
  42.             cout<<"\n";
  43.         }
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement