#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ld long double
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> A(n);
for (int i = 0; i < n; i++) cin >> A[i];
int ans = 0;
vector<vector<int>> suf_o(n + 1, vector<int>(m+1));
vector<vector<int>> stolb_i(n + 1, vector<int>(m+1));
for (int i = 0; i < n; i++) {
suf_o[i][m-1] = (A[i][m-1] == 'O');
for (int j = m - 2; j >= 0; j--) {
suf_o[i][j] = (A[i][j]=='O') + suf_o[i][j+1];
}
}
for (int j = 0; j < m; j++) {
stolb_i[n-1][j] = (A[n-1][j] == 'I');
for (int i = n - 2; i >= 0; i--) {
stolb_i[i][j] = stolb_i[i+1][j] + (A[i][j] == 'I');
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (A[i][j] == 'J') {
ans += suf_o[i][j+1] * stolb_i[i+1][j];
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
9 ms |
3832 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
7 ms |
2680 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
10 ms |
4748 KB |
Output is correct |
19 |
Correct |
10 ms |
4600 KB |
Output is correct |
20 |
Correct |
11 ms |
4728 KB |
Output is correct |
21 |
Correct |
10 ms |
4856 KB |
Output is correct |
22 |
Correct |
9 ms |
4600 KB |
Output is correct |
23 |
Correct |
10 ms |
4728 KB |
Output is correct |
24 |
Correct |
12 ms |
4760 KB |
Output is correct |
25 |
Correct |
9 ms |
4600 KB |
Output is correct |
26 |
Correct |
9 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
504 KB |
Output is correct |
9 |
Correct |
5 ms |
504 KB |
Output is correct |
10 |
Correct |
5 ms |
504 KB |
Output is correct |
11 |
Correct |
5 ms |
504 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
9 ms |
3832 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
7 ms |
2680 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
10 ms |
4748 KB |
Output is correct |
19 |
Correct |
10 ms |
4600 KB |
Output is correct |
20 |
Correct |
11 ms |
4728 KB |
Output is correct |
21 |
Correct |
10 ms |
4856 KB |
Output is correct |
22 |
Correct |
9 ms |
4600 KB |
Output is correct |
23 |
Correct |
10 ms |
4728 KB |
Output is correct |
24 |
Correct |
12 ms |
4760 KB |
Output is correct |
25 |
Correct |
9 ms |
4600 KB |
Output is correct |
26 |
Correct |
9 ms |
4728 KB |
Output is correct |
27 |
Correct |
321 ms |
151288 KB |
Output is correct |
28 |
Correct |
6 ms |
1144 KB |
Output is correct |
29 |
Correct |
18 ms |
11896 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
243 ms |
111224 KB |
Output is correct |
32 |
Correct |
331 ms |
158968 KB |
Output is correct |
33 |
Correct |
335 ms |
159608 KB |
Output is correct |
34 |
Correct |
283 ms |
129016 KB |
Output is correct |
35 |
Correct |
333 ms |
158968 KB |
Output is correct |
36 |
Correct |
318 ms |
159608 KB |
Output is correct |
37 |
Correct |
380 ms |
160184 KB |
Output is correct |
38 |
Correct |
223 ms |
110328 KB |
Output is correct |
39 |
Correct |
220 ms |
110840 KB |
Output is correct |