Advertisement
mickypinata

GCJ2020-Q1: Vestigium

Apr 3rd, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. using namespace std;
  5.  
  6. vector<set<int>> col;
  7. vector<bool> acol;
  8. int n, q;
  9.  
  10. int main(){
  11.  
  12.     int x, sum, cntr, cntc;
  13.     bool arow;
  14.  
  15.     scanf("%d", &q);
  16.     for(int k = 1; k <= q; ++k){
  17.         scanf("%d", &n);
  18.         col.assign(n, set<int>());
  19.         acol.assign(n, false);
  20.         sum = 0;
  21.         cntr = 0;
  22.         cntc = 0;
  23.         for(int i = 0; i < n; ++i){
  24.             set<int> row;
  25.             arow = false;
  26.             for(int j = 0; j < n; ++j){
  27.                 scanf("%d", &x);
  28.  
  29.                 /// Find trace
  30.                 if(i == j){
  31.                     sum += x;
  32.                 }
  33.  
  34.                 /// Find duplicated numbers in row
  35.                 if(!arow){
  36.                     if(row.count(x) == 0){
  37.                         row.insert(x);
  38.                     } else {
  39.                         ++cntr;
  40.                         arow = true;
  41.                     }
  42.                 }
  43.  
  44.                 /// Find duplicated numbers in col
  45.                 if(!acol[j]){
  46.                     if(col[j].count(x) == 0){
  47.                         col[j].insert(x);
  48.                     } else {
  49.                         ++cntc;
  50.                         acol[j] = true;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.         cout << "Case #" << k << ": " << sum << " " << cntr << " " << cntc << "\n";
  56.     }
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement