forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
56 lines (49 loc) · 1.75 KB
/
A.cpp
File metadata and controls
56 lines (49 loc) · 1.75 KB
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
#include<bits/stdc++.h>
#define DEBUG(X) { auto _X = (X); std::cerr << "L" << __LINE__ << ": " << #X << " = " << (_X) << std::endl; }
#define PR0(A, n) { std::cerr << "L" << __LINE__ << ": " << #A << " = "; for(size_t i = 0, _n = n; i < _n; i++) std::cerr << A[i] << ' '; std::cerr << std::endl; }
using Row = std::vector<int>;
using Matrix = std::vector<Row>;
int main() {
std::ios::sync_with_stdio(0); std::cin.tie(0);
size_t nRow, nCol;
std::cin >> nRow >> nCol;
// Bug: swap nRow and nCol
std::swap(nRow, nCol);
Matrix a(nRow, Row(nCol));
for (size_t i = 0; i < nRow; i++) {
for (size_t j = 0; j < nCol; j++) {
std::cin >> a[i][j];
}
}
Row maxRow(nRow), cntMaxRow(nRow);
Row minCol(nCol, std::numeric_limits<int>::max()), cntMinCol(nCol);
for (size_t i = 0; i < nRow; i++) {
for (size_t j = 0; j < nCol; j++) {
maxRow[i] = std::max(maxRow[i], a[i][j]);
minCol[j] = std::min(minCol[j], a[i][j]);
}
}
for (size_t i = 0; i < nRow; i++) {
for (size_t j = 0; j < nCol; j++) {
if (a[i][j] == maxRow[i]) {
++cntMaxRow[i];
}
if (a[i][j] == minCol[j]) {
++cntMinCol[j];
}
}
}
for (size_t i = 0; i < nRow; i++) {
for (size_t j = 0; j < nCol; j++) {
if (a[i][j] == minCol[j]
&& cntMinCol[j] == 1
&& a[i][j] == maxRow[i]
&& cntMaxRow[i] == 1) {
std::cout << i + 1 << ' ' << j + 1 << std::endl;
return 0;
}
}
}
// No answer.
std::cout << 0 << ' ' << 0 << std::endl;
}