#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 5005;
char grid[maxn][maxn];
int ocnt[maxn][maxn], icnt[maxn][maxn];
int H, W;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> H >> W;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
cin >> grid[i][j];
}
}
for (int i = 1; i <= H; i++) {
for (int j = W; j >= 1; j--) {
ocnt[i][j] = ocnt[i][j+1];
if (grid[i][j] == 'O') ocnt[i][j]++;
}
}
for (int j = 1; j <= W; j++) {
for (int i = H; i >= 1; i--) {
icnt[i][j] = icnt[i+1][j];
if (grid[i][j] == 'I') icnt[i][j]++;
}
}
ll ans = 0;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
if (grid[i][j] != 'J') continue;
ans += 1LL * ocnt[i][j] * icnt[i][j];
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
1536 KB |
Output is correct |
6 |
Correct |
4 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
5 ms |
1664 KB |
Output is correct |
9 |
Correct |
5 ms |
1664 KB |
Output is correct |
10 |
Correct |
4 ms |
1536 KB |
Output is correct |
11 |
Correct |
4 ms |
1664 KB |
Output is correct |
12 |
Correct |
4 ms |
1664 KB |
Output is correct |
13 |
Correct |
4 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
1536 KB |
Output is correct |
6 |
Correct |
4 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
5 ms |
1664 KB |
Output is correct |
9 |
Correct |
5 ms |
1664 KB |
Output is correct |
10 |
Correct |
4 ms |
1536 KB |
Output is correct |
11 |
Correct |
4 ms |
1664 KB |
Output is correct |
12 |
Correct |
4 ms |
1664 KB |
Output is correct |
13 |
Correct |
4 ms |
1536 KB |
Output is correct |
14 |
Correct |
15 ms |
8064 KB |
Output is correct |
15 |
Correct |
7 ms |
5476 KB |
Output is correct |
16 |
Correct |
7 ms |
4608 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
17 ms |
8576 KB |
Output is correct |
19 |
Correct |
15 ms |
8448 KB |
Output is correct |
20 |
Correct |
14 ms |
8448 KB |
Output is correct |
21 |
Correct |
19 ms |
8548 KB |
Output is correct |
22 |
Correct |
15 ms |
8508 KB |
Output is correct |
23 |
Correct |
14 ms |
8448 KB |
Output is correct |
24 |
Correct |
22 ms |
8604 KB |
Output is correct |
25 |
Correct |
12 ms |
8576 KB |
Output is correct |
26 |
Correct |
21 ms |
8448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
1536 KB |
Output is correct |
6 |
Correct |
4 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
5 ms |
1664 KB |
Output is correct |
9 |
Correct |
5 ms |
1664 KB |
Output is correct |
10 |
Correct |
4 ms |
1536 KB |
Output is correct |
11 |
Correct |
4 ms |
1664 KB |
Output is correct |
12 |
Correct |
4 ms |
1664 KB |
Output is correct |
13 |
Correct |
4 ms |
1536 KB |
Output is correct |
14 |
Correct |
15 ms |
8064 KB |
Output is correct |
15 |
Correct |
7 ms |
5476 KB |
Output is correct |
16 |
Correct |
7 ms |
4608 KB |
Output is correct |
17 |
Correct |
3 ms |
512 KB |
Output is correct |
18 |
Correct |
17 ms |
8576 KB |
Output is correct |
19 |
Correct |
15 ms |
8448 KB |
Output is correct |
20 |
Correct |
14 ms |
8448 KB |
Output is correct |
21 |
Correct |
19 ms |
8548 KB |
Output is correct |
22 |
Correct |
15 ms |
8508 KB |
Output is correct |
23 |
Correct |
14 ms |
8448 KB |
Output is correct |
24 |
Correct |
22 ms |
8604 KB |
Output is correct |
25 |
Correct |
12 ms |
8576 KB |
Output is correct |
26 |
Correct |
21 ms |
8448 KB |
Output is correct |
27 |
Correct |
579 ms |
105592 KB |
Output is correct |
28 |
Correct |
30 ms |
28664 KB |
Output is correct |
29 |
Correct |
27 ms |
8832 KB |
Output is correct |
30 |
Correct |
4 ms |
640 KB |
Output is correct |
31 |
Correct |
432 ms |
81612 KB |
Output is correct |
32 |
Correct |
528 ms |
109060 KB |
Output is correct |
33 |
Correct |
560 ms |
109208 KB |
Output is correct |
34 |
Correct |
469 ms |
94700 KB |
Output is correct |
35 |
Correct |
569 ms |
109176 KB |
Output is correct |
36 |
Correct |
542 ms |
109260 KB |
Output is correct |
37 |
Correct |
588 ms |
109688 KB |
Output is correct |
38 |
Correct |
344 ms |
81272 KB |
Output is correct |
39 |
Correct |
377 ms |
81476 KB |
Output is correct |