#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> cntI(n, vector<int>(m)), cntO(n, vector<int>(m));
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
cntI[i][j] += (i + 1 < n ? cntI[i + 1][j] : 0) + (a[i][j] == 'I');
cntO[i][j] += (j + 1 < m ? cntO[i][j + 1] : 0) + (a[i][j] == 'O');
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m - 1; j++) {
if (a[i][j] == 'J') ans += 1LL * cntO[i][j] * cntI[i][j];
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
1880 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
3 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
3 ms |
2904 KB |
Output is correct |
21 |
Correct |
4 ms |
3024 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2904 KB |
Output is correct |
24 |
Correct |
3 ms |
2904 KB |
Output is correct |
25 |
Correct |
3 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
1880 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
3 ms |
2904 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
3 ms |
2904 KB |
Output is correct |
21 |
Correct |
4 ms |
3024 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
2 ms |
2904 KB |
Output is correct |
24 |
Correct |
3 ms |
2904 KB |
Output is correct |
25 |
Correct |
3 ms |
2648 KB |
Output is correct |
26 |
Correct |
2 ms |
2908 KB |
Output is correct |
27 |
Correct |
86 ms |
84508 KB |
Output is correct |
28 |
Correct |
1 ms |
1112 KB |
Output is correct |
29 |
Correct |
5 ms |
6744 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
63 ms |
62292 KB |
Output is correct |
32 |
Correct |
69 ms |
88900 KB |
Output is correct |
33 |
Correct |
70 ms |
89424 KB |
Output is correct |
34 |
Correct |
74 ms |
72324 KB |
Output is correct |
35 |
Correct |
73 ms |
89104 KB |
Output is correct |
36 |
Correct |
67 ms |
89424 KB |
Output is correct |
37 |
Correct |
97 ms |
89680 KB |
Output is correct |
38 |
Correct |
53 ms |
61816 KB |
Output is correct |
39 |
Correct |
48 ms |
62132 KB |
Output is correct |