#include <bits/stdc++.h>
int main() {
int n, m, k;
std::cin >> n >> m >> k;
std::vector<std::vector<int>> a(n + 1, std::vector<int>(m + 1));
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
char x;
std::cin >> x;
if(x == 'A') {
a[i][j] = 0;
}
else if(x == 'C') {
a[i][j] = 1;
}
else {
a[i][j] = 2;
}
}
}
std::vector<std::vector<int>> cnt(n + 1, std::vector<int>(n + 1));
std::vector<int> idx[3];
for(int j = 1; j <= n; j++) {
for(int i = 1; i <= n; i++) {
idx[a[i][j]].push_back(i);
}
for(int x1 = 0; x1 < 3; x1++) {
for(int x2 = x1 + 1; x2 < 3; x2++) {
for(int x = 0; x < idx[x1].size(); x++) {
for(int y = 0; y < idx[x2].size(); y++) {
cnt[idx[x1][x]][idx[x2][y]] += 1;
cnt[idx[x2][y]][idx[x1][x]] += 1;
}
}
}
}
for(int i = 0; i < 3; i++) {
idx[i].clear();
}
}
int ans = - 1;
for(int i = 1; i <= n; i++) {
int ok = 1;
for(int j = 1; j <= n; j++) {
if(i == j) {
continue;
}
ok &= (cnt[i][j] == k);
}
if(ok) {
ans = i;
}
}
std::cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |