Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- using namespace std;
- vector<set<int>> col;
- vector<bool> acol;
- int n, q;
- int main(){
- int x, sum, cntr, cntc;
- bool arow;
- scanf("%d", &q);
- for(int k = 1; k <= q; ++k){
- scanf("%d", &n);
- col.assign(n, set<int>());
- acol.assign(n, false);
- sum = 0;
- cntr = 0;
- cntc = 0;
- for(int i = 0; i < n; ++i){
- set<int> row;
- arow = false;
- for(int j = 0; j < n; ++j){
- scanf("%d", &x);
- /// Find trace
- if(i == j){
- sum += x;
- }
- /// Find duplicated numbers in row
- if(!arow){
- if(row.count(x) == 0){
- row.insert(x);
- } else {
- ++cntr;
- arow = true;
- }
- }
- /// Find duplicated numbers in col
- if(!acol[j]){
- if(col[j].count(x) == 0){
- col[j].insert(x);
- } else {
- ++cntc;
- acol[j] = true;
- }
- }
- }
- }
- cout << "Case #" << k << ": " << sum << " " << cntr << " " << cntc << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement