fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.  
  8.  
  9. int t;
  10. cin >> t;
  11.  
  12. while (t--) {
  13.  
  14. int n;
  15. cin >> n;
  16. int ar[100][100];
  17.  
  18.  
  19. for (int i = 0; i < n; ++i) {
  20. for (int j = 0; j < n; ++j) {
  21. cin >> ar[i][j];
  22. }
  23. }
  24.  
  25.  
  26. vector<vector<int> > matrix;
  27.  
  28. vector<int> temp1, temp2;
  29.  
  30. temp1.push_back(ar[0][0]);
  31.  
  32. for (int i = 1; i < n - 1; ++i) {
  33. temp1.push_back(ar[i][i]);
  34. temp2.push_back(ar[i][i]);
  35. }
  36. temp2.push_back(ar[n - 1][n - 1]);
  37.  
  38. matrix.push_back(temp1);
  39. matrix.push_back(temp2);
  40.  
  41. /*
  42.  
  43.   for (int i = 0; i < n; ++i) {
  44.   temp1.push_back(ar[i][i]);
  45.   }
  46.  
  47.   matrix.push_back(temp1);
  48. */
  49.  
  50. temp1.clear();
  51. temp2.clear();
  52.  
  53. int j = 0;
  54.  
  55. for (int i = 1; i < n; ++i) {
  56.  
  57. j = 0;
  58.  
  59. int t = i;
  60.  
  61. while (i < n && j < n) {
  62.  
  63. temp1.push_back(ar[i][j]);
  64. temp2.push_back(ar[j][i]);
  65. i++;
  66. j++;
  67.  
  68. }
  69. matrix.push_back(temp1);
  70. matrix.push_back(temp2);
  71. temp1.clear();
  72. temp2.clear();
  73.  
  74. i = t;
  75.  
  76. }
  77.  
  78. /* for (vector<int> temp: matrix) {
  79.   for (int i : temp)
  80.   cout << i << ", ";
  81.   cout << endl;
  82.   }*/
  83.  
  84.  
  85. vector<int> sum_ar;
  86.  
  87. int sum = 0;
  88. int ans = 0;
  89.  
  90. for (int i = 0; i < matrix.size(); i++) {
  91.  
  92. sum = 0;
  93.  
  94. for (int j = 0; j < matrix[i].size(); ++j) {
  95.  
  96. sum += matrix[i][j];
  97.  
  98. }
  99.  
  100. ans = max(ans, sum);
  101. }
  102.  
  103.  
  104. cout << ans << endl;
  105.  
  106. }
  107.  
  108.  
  109. return 0;
  110. }
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
Standard output is empty