-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix trace.cpp
58 lines (47 loc) · 889 Bytes
/
Matrix trace.cpp
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
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int n;
const int MAXN = 4e2 + 5;
int a[MAXN][MAXN];
int trace() {
int ret = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
ret += a[i][j];
}
}
return ret;
}
int rows() {
int ret = 0;
for (int i = 0; i < n; i++) {
set < int > se;
for (int j = 0; j < n; j++) {
se.insert(a[i][j]);
}
if (se.size() < n)
++ret;
}
return ret;
}
int cols() {
int ret = 0;
for (int i = 0; i < n; i++) {
set < int > se;
for (int j = 0; j < n; j++) {
se.insert(a[j][i]);
}
if (se.size() < n)
++ret;
}
return ret;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> a[i][j];
cout << trace() << ' ' << rows() << ' ' << cols() << '\n';
}