-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathabc176_e.cpp
More file actions
executable file
·50 lines (41 loc) · 1.04 KB
/
abc176_e.cpp
File metadata and controls
executable file
·50 lines (41 loc) · 1.04 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
// Problem Code: abc176_e
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int bomber(int H, int W, int M, vector<int>& h, vector<int>& w) {
int max_bombs, max_row, max_col;
set<pair<int, int>> seen;
vector<int> candidate_rows, candidate_cols, rows(H), cols(W);
for (int i = 0; i < M; i++) {
rows[h[i]]++;
cols[w[i]]++;
seen.emplace(h[i], w[i]);
}
max_row = *max_element(rows.begin(), rows.end());
max_col = *max_element(cols.begin(), cols.end());
max_bombs = max_row + max_col - 1;
for (int i = 0; i < H; i++)
if (rows[i] == max_row)
candidate_rows.push_back(i);
for (int i = 0; i < W; i++)
if (cols[i] == max_col)
candidate_cols.push_back(i);
for (int& row: candidate_rows)
for (int& col: candidate_cols)
if (!seen.count({row, col}))
return 1 + max_bombs;
return max_bombs;
}
int main() {
int H, W, M;
cin >> H >> W >> M;
vector<int> h(M), w(M);
for (int i = 0; i < M; i++) {
cin >> h[i] >> w[i];
h[i]--, w[i]--;
}
cout << bomber(H, W, M, h, w);
return 0;
}