#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void test_case() {
int n, m;
cin >> n >> m;
vector<string> a(n);
for (auto &x : a) cin >> x;
vector<vector<int>> suff(n, vector<int>(m));
for (int i = n-1; i >= 0; i--) {
for (int j = 0; j < m; j++) {
suff[i][j] = (a[i][j] == 'I') + (i+1 < n ? suff[i+1][j] : 0);
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = m-1; j >= 0; j--) {
if (a[i][j] == 'O') cnt++;
else if (a[i][j] == 'J') {
ans += cnt * suff[i][j];
}
}
}
cout << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) test_case();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
1884 KB |
Output is correct |
19 |
Correct |
2 ms |
1884 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
3 ms |
1864 KB |
Output is correct |
22 |
Correct |
2 ms |
1884 KB |
Output is correct |
23 |
Correct |
1 ms |
1880 KB |
Output is correct |
24 |
Correct |
3 ms |
1880 KB |
Output is correct |
25 |
Correct |
2 ms |
1884 KB |
Output is correct |
26 |
Correct |
1 ms |
1724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
1884 KB |
Output is correct |
19 |
Correct |
2 ms |
1884 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
3 ms |
1864 KB |
Output is correct |
22 |
Correct |
2 ms |
1884 KB |
Output is correct |
23 |
Correct |
1 ms |
1880 KB |
Output is correct |
24 |
Correct |
3 ms |
1880 KB |
Output is correct |
25 |
Correct |
2 ms |
1884 KB |
Output is correct |
26 |
Correct |
1 ms |
1724 KB |
Output is correct |
27 |
Correct |
80 ms |
47380 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
3 ms |
4188 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
60 ms |
35156 KB |
Output is correct |
32 |
Correct |
43 ms |
49744 KB |
Output is correct |
33 |
Correct |
39 ms |
50000 KB |
Output is correct |
34 |
Correct |
68 ms |
40576 KB |
Output is correct |
35 |
Correct |
45 ms |
49860 KB |
Output is correct |
36 |
Correct |
45 ms |
50068 KB |
Output is correct |
37 |
Correct |
81 ms |
50000 KB |
Output is correct |
38 |
Correct |
29 ms |
34644 KB |
Output is correct |
39 |
Correct |
28 ms |
34756 KB |
Output is correct |