forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisa.cpp
82 lines (70 loc) · 1.63 KB
/
misa.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <vector>
using namespace std;
int check(int i, int j, vector<vector<char>> v) {
int handshakes = 0;
if(v[i+1][j+1] == 'o') {
handshakes++;
}
if(v[i+1][j] == 'o') {
handshakes++;
}
if(v[i+1][j-1] == 'o') {
handshakes++;
}
if(v[i][j+1] == 'o') {
handshakes++;
}
if(v[i][j-1] == 'o') {
handshakes++;
}
if(v[i-1][j+1] == 'o') {
handshakes++;
}
if(v[i-1][j] == 'o') {
handshakes++;
}
if(v[i-1][j-1] == 'o') {
handshakes++;
}
return handshakes;
}
int main() {
int r, s;
cin >> r >> s;
vector<vector<char>> v;
v.resize(r+2, vector<char>(s+2, '.'));
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= s; j++) {
cin >> v[i][j];
}
}
int handshakes = 0;
// Add current handshakes
for(int i = 0; i <= r; i++) {
for(int j = 0; j <= s; j++) {
if(v[i][j] == 'o' && v[i+1][j] == 'o') {
handshakes++;
}
if(v[i][j] == 'o' && v[i][j+1] == 'o') {
handshakes++;
}
if(v[i][j] == 'o' && v[i+1][j+1] == 'o') {
handshakes++;
}
if(v[i][j] == 'o' && v[i-1][j+1] == 'o') {
handshakes++;
}
}
}
int extra= 0;
// Add new handshakes if more
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= s; j++) {
if(v[i][j] == '.') {
extra = max(extra, check(i, j, v));
}
}
}
cout << handshakes + extra << endl;
}