#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn=3e3+5;
int n,m;
char c[maxn][maxn];
int dp[2][maxn][maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
cin >> c[i][j];
dp[0][i][j] = dp[0][i - 1][j] + (c[i][j] == 'I');
dp[1][i][j] = dp[1][i][j - 1] + (c[i][j] == 'O');
}
}
ll ans = 0;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
if(c[i][j] != 'J') continue;
// cout<<i<<' '<<j<<' '<<dp[0][n][j]<<' '<<dp[0][i][j]<<' '<<dp[1][i][m]<<' '<<dp[1][i][j]<<'\n';
ans += (dp[0][n][j] - dp[0][i][j]) * (dp[1][i][m] - dp[1][i][j]);
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1476 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1412 KB |
Output is correct |
9 |
Correct |
1 ms |
1472 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1476 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1476 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1412 KB |
Output is correct |
9 |
Correct |
1 ms |
1472 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1476 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
14 |
Correct |
6 ms |
7400 KB |
Output is correct |
15 |
Correct |
3 ms |
4936 KB |
Output is correct |
16 |
Correct |
4 ms |
4264 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
8 ms |
8012 KB |
Output is correct |
19 |
Correct |
7 ms |
7864 KB |
Output is correct |
20 |
Correct |
8 ms |
7760 KB |
Output is correct |
21 |
Correct |
9 ms |
8012 KB |
Output is correct |
22 |
Correct |
7 ms |
7884 KB |
Output is correct |
23 |
Correct |
10 ms |
7760 KB |
Output is correct |
24 |
Correct |
9 ms |
7996 KB |
Output is correct |
25 |
Correct |
7 ms |
7884 KB |
Output is correct |
26 |
Correct |
7 ms |
7740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1476 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1412 KB |
Output is correct |
9 |
Correct |
1 ms |
1472 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1476 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
14 |
Correct |
6 ms |
7400 KB |
Output is correct |
15 |
Correct |
3 ms |
4936 KB |
Output is correct |
16 |
Correct |
4 ms |
4264 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
8 ms |
8012 KB |
Output is correct |
19 |
Correct |
7 ms |
7864 KB |
Output is correct |
20 |
Correct |
8 ms |
7760 KB |
Output is correct |
21 |
Correct |
9 ms |
8012 KB |
Output is correct |
22 |
Correct |
7 ms |
7884 KB |
Output is correct |
23 |
Correct |
10 ms |
7760 KB |
Output is correct |
24 |
Correct |
9 ms |
7996 KB |
Output is correct |
25 |
Correct |
7 ms |
7884 KB |
Output is correct |
26 |
Correct |
7 ms |
7740 KB |
Output is correct |
27 |
Correct |
170 ms |
88024 KB |
Output is correct |
28 |
Correct |
13 ms |
25932 KB |
Output is correct |
29 |
Correct |
17 ms |
7748 KB |
Output is correct |
30 |
Correct |
1 ms |
588 KB |
Output is correct |
31 |
Correct |
128 ms |
72560 KB |
Output is correct |
32 |
Correct |
159 ms |
88416 KB |
Output is correct |
33 |
Correct |
156 ms |
88196 KB |
Output is correct |
34 |
Correct |
161 ms |
84108 KB |
Output is correct |
35 |
Correct |
157 ms |
88504 KB |
Output is correct |
36 |
Correct |
173 ms |
88160 KB |
Output is correct |
37 |
Correct |
186 ms |
88528 KB |
Output is correct |
38 |
Correct |
118 ms |
72536 KB |
Output is correct |
39 |
Correct |
140 ms |
72264 KB |
Output is correct |