diff options
author | Santo Cariotti <dcariotti24@gmail.com> | 2020-04-04 19:16:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-04 19:16:54 +0200 |
commit | 8ec666796065d5669690ab4da8f809213308e84e (patch) | |
tree | 002356d11e2b8dc2d21fd139778946df673dd980 /cpp | |
parent | 3d8dca4e262d647da3069bb70215d7e68ee1525d (diff) |
Create vestigium.cc
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/vestigium.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/cpp/vestigium.cc b/cpp/vestigium.cc new file mode 100644 index 0000000..16beec7 --- /dev/null +++ b/cpp/vestigium.cc @@ -0,0 +1,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; +} |