#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> mat(n);
for(auto &z : mat) cin >> z;
vector<vector<int>> ig(n, vector<int>(m, 0));
vector<vector<int>> o(n, vector<int>(m, 0));
for(int i = n-1; i >= 0; --i) {
for(int j = 0; j < m; ++j) {
ig[i][j] = (mat[i][j] == 'I');
if(i + 1 < n) {
ig[i][j] += ig[i+1][j];
}
}
}
for(int j = m-1; j >= 0; --j) {
for(int i = 0; i < n; ++i) {
o[i][j] = (mat[i][j] == 'O');
if(j + 1 < m) {
o[i][j] += o[i][j+1];
}
}
}
ll ans = 0;
for(int i = 0; i + 1 < n; ++i) {
for(int j = 0; j + 1 < m; ++j) {
if(mat[i][j] != 'J') continue;
ans += ig[i+1][j] * o[i][j+1];
}
}
cout << ans << '\n';
}
# |
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 |
328 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 |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 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 |
328 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 |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 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 |
3 ms |
2248 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
428 KB |
Output is correct |
18 |
Correct |
5 ms |
2772 KB |
Output is correct |
19 |
Correct |
3 ms |
2640 KB |
Output is correct |
20 |
Correct |
3 ms |
2772 KB |
Output is correct |
21 |
Correct |
4 ms |
2764 KB |
Output is correct |
22 |
Correct |
4 ms |
2740 KB |
Output is correct |
23 |
Correct |
3 ms |
2772 KB |
Output is correct |
24 |
Correct |
4 ms |
2772 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2772 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 |
328 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 |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 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 |
3 ms |
2248 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
1620 KB |
Output is correct |
17 |
Correct |
1 ms |
428 KB |
Output is correct |
18 |
Correct |
5 ms |
2772 KB |
Output is correct |
19 |
Correct |
3 ms |
2640 KB |
Output is correct |
20 |
Correct |
3 ms |
2772 KB |
Output is correct |
21 |
Correct |
4 ms |
2764 KB |
Output is correct |
22 |
Correct |
4 ms |
2740 KB |
Output is correct |
23 |
Correct |
3 ms |
2772 KB |
Output is correct |
24 |
Correct |
4 ms |
2772 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
3 ms |
2772 KB |
Output is correct |
27 |
Correct |
213 ms |
84484 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
8 ms |
6740 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
151 ms |
62340 KB |
Output is correct |
32 |
Correct |
195 ms |
89100 KB |
Output is correct |
33 |
Correct |
194 ms |
89420 KB |
Output is correct |
34 |
Correct |
173 ms |
72208 KB |
Output is correct |
35 |
Correct |
202 ms |
88984 KB |
Output is correct |
36 |
Correct |
198 ms |
89312 KB |
Output is correct |
37 |
Correct |
236 ms |
89640 KB |
Output is correct |
38 |
Correct |
131 ms |
61784 KB |
Output is correct |
39 |
Correct |
126 ms |
61948 KB |
Output is correct |