#include <iostream>
#include <vector>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<vector<int>> grid;
for (int i = 0; i < H; ++i) {
string st;
cin >> st;
vector<int> row;
for (int j = 0; j < W; ++j) {
if (st[j] == 'J')
row.push_back(0);
else if (st[j] == 'O')
row.push_back(1);
else if (st[j] == 'I')
row.push_back(2);
}
grid.push_back(row);
}
vector<vector<int>> grido(H + 1, vector<int>(W + 1, 0));
vector<vector<int>> gridi(H + 1, vector<int>(W + 1, 0));
// Calculate 'o' values
for (int row = 0; row < H; ++row) {
for (int col = W - 1; col >= 0; --col) {
int num = (grid[row][col] == 1);
grido[row][col] = grido[row][col + 1] + num;
}
}
// Calculate 'i' values
for (int col = 0; col < W; ++col) {
for (int row = H - 1; row >= 0; --row) {
int num = (grid[row][col] == 2);
gridi[row][col] = gridi[row + 1][col] + num;
}
}
long long ans = 0;
for (int row = 0; row < H; ++row) {
for (int col = 0; col < W; ++col) {
if (grid[row][col] == 0) {
ans += grido[row][col + 1] * gridi[row + 1][col];
}
}
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
2516 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1748 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
9 ms |
3284 KB |
Output is correct |
19 |
Correct |
7 ms |
3156 KB |
Output is correct |
20 |
Correct |
7 ms |
3156 KB |
Output is correct |
21 |
Correct |
11 ms |
3244 KB |
Output is correct |
22 |
Correct |
7 ms |
3156 KB |
Output is correct |
23 |
Correct |
7 ms |
3156 KB |
Output is correct |
24 |
Correct |
10 ms |
3284 KB |
Output is correct |
25 |
Correct |
7 ms |
3108 KB |
Output is correct |
26 |
Correct |
7 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
7 ms |
2516 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
1748 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
9 ms |
3284 KB |
Output is correct |
19 |
Correct |
7 ms |
3156 KB |
Output is correct |
20 |
Correct |
7 ms |
3156 KB |
Output is correct |
21 |
Correct |
11 ms |
3244 KB |
Output is correct |
22 |
Correct |
7 ms |
3156 KB |
Output is correct |
23 |
Correct |
7 ms |
3156 KB |
Output is correct |
24 |
Correct |
10 ms |
3284 KB |
Output is correct |
25 |
Correct |
7 ms |
3108 KB |
Output is correct |
26 |
Correct |
7 ms |
3156 KB |
Output is correct |
27 |
Correct |
405 ms |
100472 KB |
Output is correct |
28 |
Correct |
2 ms |
852 KB |
Output is correct |
29 |
Correct |
17 ms |
8532 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
309 ms |
80064 KB |
Output is correct |
32 |
Correct |
355 ms |
114340 KB |
Output is correct |
33 |
Correct |
360 ms |
114816 KB |
Output is correct |
34 |
Correct |
337 ms |
92928 KB |
Output is correct |
35 |
Correct |
358 ms |
114424 KB |
Output is correct |
36 |
Correct |
344 ms |
114808 KB |
Output is correct |
37 |
Correct |
435 ms |
115192 KB |
Output is correct |
38 |
Correct |
249 ms |
79504 KB |
Output is correct |
39 |
Correct |
258 ms |
79836 KB |
Output is correct |