Advertisement
Naxocist

Vestigium

Apr 19th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 105;
  5.  
  6.  
  7. int main(){
  8.     ios_base::sync_with_stdio(false); cin.tie(nullptr);
  9.  
  10.     int t; scanf("%d", &t);
  11.  
  12.     for(int i=1; i<=t; ++i){
  13.         printf("Case #%d: ", i);
  14.         int ar[N][N], n; scanf("%d", &n);
  15.  
  16.         int k = 0, r = 0, c = 0;
  17.  
  18.         for(int j=0; j<n; ++j){
  19.             for(int h=0; h<n; ++h) {
  20.                 int x; scanf("%d", &x);
  21.                 ar[j][h] = x;
  22.                 if(j == h) k += x;
  23.             }
  24.         }
  25.  
  26.         for(int j=0; j<n; ++j){
  27.             unordered_map<int, int> cr, cc;
  28.             bool br=false, bc=false;
  29.             for(int h=0; h<n; ++h) {
  30.                 if(cc.find(ar[h][j]) != cc.end() && !bc) c++, bc=true;
  31.                 if(cr.find(ar[j][h]) != cr.end() && !br) r++, br=true;
  32.                 cc[ar[h][j]] += 1;
  33.                 cr[ar[j][h]] += 1;
  34.             }
  35.         }
  36.  
  37.         printf("%d %d %d\n", k, r, c);
  38.     }    
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement