fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. int n,k;
  7. int cnt[3010][3010];
  8. int cur;
  9.  
  10. int main(){
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13. //freopen("DIVGROUP.INP","r",stdin);
  14. //freopen("DIVGROUP.OUT","w",stdout);
  15. cin >> n >> k;
  16. for(int i = 0; i < k;i++){
  17. cnt[i+1][i+1] = n*n - i;
  18. }
  19. cur = n*n - k;
  20. for(int i = 1; i <= n; i++){
  21. for(int j = 1; j <= n; j++){
  22. if(i == j && i <= k) continue;
  23. else cnt[i][j] = cur--;
  24. }
  25. }
  26. for(int i = 1; i <= n; i++){
  27. for(int j = 1; j <= n; j++){
  28. cout << cnt[i][j] << " ";
  29. }
  30. cout << endl;
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 5320KB
stdin
3 2
stdout
9 7 6 
5 8 4 
3 2 1