summaryrefslogtreecommitdiff
path: root/cpp/vestigium.cc
blob: 16beec799802f8d24cd72bf0a647f01aa91cff46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Google Code Jam 2020
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int get_trace(const vector<vector<int>>& m) {
    int sum{};
    for(int i = 0; i < m.size(); ++i) {
        sum += m.at(i).at(i);
    }

    return sum;
}

int get_dupl_row(const vector<vector<int>>& m) {
    int nums{};
    vector<int> elem;
    for(int i = 0; i < m.size(); ++i) {
        elem.clear();
        for(int j = 0; j < m.size(); ++j) {
            if(find(begin(elem), end(elem), m[i][j]) == elem.end()) {
                elem.push_back(m[i][j]);
            } else {
                nums++;
                break;
            }
        }
    }
    return nums;
}

int get_dupl_column(const vector<vector<int>>& m) {
    int nums{};
    vector<int> elem;
    for(int i = 0; i < m.size(); ++i) {
        elem.clear();
        for(int j = 0; j < m.size(); ++j) {
            if(find(begin(elem), end(elem), m[j][i]) == elem.end()) {
                elem.push_back(m[j][i]);
            } else {
                nums++;
                break;
            }
        }
    }
    return nums;
}

int main() {
    int T;
    cin >> T;

    for(int _ = 0; _ < T; ++_) {
        int N;
        cin >> N;
        vector<vector<int>> matrix;
        for(int i = 0; i < N; ++i) {
            matrix.push_back(vector<int>{});
            int elem;
            for(int j = 0; j < N; ++j) {
                cin >> elem;
                matrix.at(i).push_back(elem);
            }
        }
        cout << "Case #"<< _+1<<": " <<  get_trace(matrix) << ' ' << get_dupl_row(matrix) << ' ' << get_dupl_column(matrix) << endl;
    }

    return 0;
}