#include<bits/stdc++.h>
using namespace std;
const int maxn=3000+10;
char all[maxn][maxn];
int dp1[maxn][maxn],dp2[maxn][maxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>all[i][j];
}
}
for(int j=0;j<m;j++){
for(int i=n-1;i>=0;i--){
dp1[i][j]+=dp1[i+1][j];
if(all[i+1][j]=='I'){
dp1[i][j]++;
}
}
}
for(int i=0;i<n;i++){
for(int j=m-1;j>=0;j--){
dp2[i][j]+=dp2[i][j+1];
if(all[i][j+1]=='O'){
dp2[i][j]++;
}
}
}
long long res=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(all[i][j]=='J'){
res+=1ll*dp1[i][j]*dp2[i][j];
}
}
}
cout<<res<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3288 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3288 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3288 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3288 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
7 ms |
10076 KB |
Output is correct |
15 |
Correct |
2 ms |
7772 KB |
Output is correct |
16 |
Correct |
4 ms |
5724 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
8 ms |
10588 KB |
Output is correct |
19 |
Correct |
6 ms |
10588 KB |
Output is correct |
20 |
Correct |
8 ms |
10588 KB |
Output is correct |
21 |
Correct |
8 ms |
10572 KB |
Output is correct |
22 |
Correct |
7 ms |
10588 KB |
Output is correct |
23 |
Correct |
6 ms |
10564 KB |
Output is correct |
24 |
Correct |
8 ms |
10588 KB |
Output is correct |
25 |
Correct |
7 ms |
10588 KB |
Output is correct |
26 |
Correct |
7 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
1 ms |
3288 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3288 KB |
Output is correct |
9 |
Correct |
1 ms |
3160 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3420 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
1 ms |
3164 KB |
Output is correct |
14 |
Correct |
7 ms |
10076 KB |
Output is correct |
15 |
Correct |
2 ms |
7772 KB |
Output is correct |
16 |
Correct |
4 ms |
5724 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
8 ms |
10588 KB |
Output is correct |
19 |
Correct |
6 ms |
10588 KB |
Output is correct |
20 |
Correct |
8 ms |
10588 KB |
Output is correct |
21 |
Correct |
8 ms |
10572 KB |
Output is correct |
22 |
Correct |
7 ms |
10588 KB |
Output is correct |
23 |
Correct |
6 ms |
10564 KB |
Output is correct |
24 |
Correct |
8 ms |
10588 KB |
Output is correct |
25 |
Correct |
7 ms |
10588 KB |
Output is correct |
26 |
Correct |
7 ms |
10588 KB |
Output is correct |
27 |
Correct |
229 ms |
88148 KB |
Output is correct |
28 |
Correct |
9 ms |
27484 KB |
Output is correct |
29 |
Correct |
12 ms |
9180 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
152 ms |
73652 KB |
Output is correct |
32 |
Correct |
220 ms |
88752 KB |
Output is correct |
33 |
Correct |
187 ms |
88660 KB |
Output is correct |
34 |
Correct |
182 ms |
85312 KB |
Output is correct |
35 |
Correct |
200 ms |
88760 KB |
Output is correct |
36 |
Correct |
184 ms |
88508 KB |
Output is correct |
37 |
Correct |
230 ms |
88660 KB |
Output is correct |
38 |
Correct |
122 ms |
73708 KB |
Output is correct |
39 |
Correct |
123 ms |
73296 KB |
Output is correct |