#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()
template<class S, class T>
bool chmin(S &a, const T &b) {
return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 1e9 + 7;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m; cin >> n >> m;
string s[n];
for (int i = 0; i < n; ++i) cin >> s[i];
int prefi[n][m], prefj[n][m];
for (int i = 0; i < n; ++i) {
prefi[i][0] = s[i][0] == 'O';
for (int j = 1; j < m; ++j) {
prefi[i][j] = prefi[i][j - 1] + (s[i][j] == 'O');
}
}
for (int j = 0; j < m; ++j) {
prefj[0][j] = s[0][j] == 'I';
for (int i = 1; i < n; ++i) {
prefj[i][j] = prefj[i - 1][j] + (s[i][j] == 'I');
}
}
int res = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (s[i][j] == 'J')
res += (prefi[i][m - 1] - prefi[i][j]) * (prefj[n - 1][j] - prefj[i][j]);
}
}
cout << res;
}
# |
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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
3420 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
4444 KB |
Output is correct |
19 |
Correct |
4 ms |
4444 KB |
Output is correct |
20 |
Correct |
4 ms |
4440 KB |
Output is correct |
21 |
Correct |
4 ms |
4488 KB |
Output is correct |
22 |
Correct |
3 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
4440 KB |
Output is correct |
24 |
Correct |
4 ms |
4444 KB |
Output is correct |
25 |
Correct |
4 ms |
4444 KB |
Output is correct |
26 |
Correct |
4 ms |
4444 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 |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
3420 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
5 ms |
4444 KB |
Output is correct |
19 |
Correct |
4 ms |
4444 KB |
Output is correct |
20 |
Correct |
4 ms |
4440 KB |
Output is correct |
21 |
Correct |
4 ms |
4488 KB |
Output is correct |
22 |
Correct |
3 ms |
4444 KB |
Output is correct |
23 |
Correct |
3 ms |
4440 KB |
Output is correct |
24 |
Correct |
4 ms |
4444 KB |
Output is correct |
25 |
Correct |
4 ms |
4444 KB |
Output is correct |
26 |
Correct |
4 ms |
4444 KB |
Output is correct |
27 |
Correct |
250 ms |
142700 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
10 ms |
11704 KB |
Output is correct |
30 |
Correct |
1 ms |
1108 KB |
Output is correct |
31 |
Correct |
184 ms |
111024 KB |
Output is correct |
32 |
Correct |
248 ms |
158844 KB |
Output is correct |
33 |
Correct |
255 ms |
159312 KB |
Output is correct |
34 |
Correct |
206 ms |
128852 KB |
Output is correct |
35 |
Correct |
245 ms |
158836 KB |
Output is correct |
36 |
Correct |
233 ms |
159168 KB |
Output is correct |
37 |
Correct |
280 ms |
159944 KB |
Output is correct |
38 |
Correct |
158 ms |
110240 KB |
Output is correct |
39 |
Correct |
159 ms |
110420 KB |
Output is correct |