#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define t3i tuple<long long, long long, long long>
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
vector<vector<int>> os(n, vector<int>(m + 1)), is(n + 1, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
os[i][j] = os[i][j + 1] + (a[i][j] == 'O');
}
}
for (int j = 0; j < m; j++) {
for (int i = n - 1; i >= 0; i--) {
is[i][j] = is[i + 1][j] + (a[i][j] == 'I');
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == 'J') {
ans += os[i][j] * is[i][j];
}
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
3672 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
4904 KB |
Output is correct |
19 |
Correct |
5 ms |
4700 KB |
Output is correct |
20 |
Correct |
6 ms |
4700 KB |
Output is correct |
21 |
Correct |
6 ms |
4812 KB |
Output is correct |
22 |
Correct |
4 ms |
4700 KB |
Output is correct |
23 |
Correct |
8 ms |
4696 KB |
Output is correct |
24 |
Correct |
5 ms |
4700 KB |
Output is correct |
25 |
Correct |
7 ms |
4696 KB |
Output is correct |
26 |
Correct |
5 ms |
4836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
5 ms |
3672 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
4904 KB |
Output is correct |
19 |
Correct |
5 ms |
4700 KB |
Output is correct |
20 |
Correct |
6 ms |
4700 KB |
Output is correct |
21 |
Correct |
6 ms |
4812 KB |
Output is correct |
22 |
Correct |
4 ms |
4700 KB |
Output is correct |
23 |
Correct |
8 ms |
4696 KB |
Output is correct |
24 |
Correct |
5 ms |
4700 KB |
Output is correct |
25 |
Correct |
7 ms |
4696 KB |
Output is correct |
26 |
Correct |
5 ms |
4836 KB |
Output is correct |
27 |
Correct |
211 ms |
150356 KB |
Output is correct |
28 |
Correct |
1 ms |
1116 KB |
Output is correct |
29 |
Correct |
13 ms |
11704 KB |
Output is correct |
30 |
Correct |
1 ms |
860 KB |
Output is correct |
31 |
Correct |
175 ms |
110676 KB |
Output is correct |
32 |
Correct |
208 ms |
158032 KB |
Output is correct |
33 |
Correct |
205 ms |
158548 KB |
Output is correct |
34 |
Correct |
180 ms |
128340 KB |
Output is correct |
35 |
Correct |
220 ms |
158268 KB |
Output is correct |
36 |
Correct |
217 ms |
158664 KB |
Output is correct |
37 |
Correct |
223 ms |
159096 KB |
Output is correct |
38 |
Correct |
155 ms |
109908 KB |
Output is correct |
39 |
Correct |
139 ms |
110416 KB |
Output is correct |