#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin>>n>>m;
char a[n+1][m+1];
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
//! (i,j)='j',(i,l)='o',(k,j)='i'
int ans=0;
int sufo[n+1][m+2];
for(int i=0;i<=n;i++)for(int j=0;j<=m+1;j++)sufo[i][j]=0;
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
sufo[i][j]=sufo[i][j+1];
if(a[i][j]=='O')sufo[i][j]++;
}
}
int sufi[n+2][m+1];
for(int i=0;i<=n+1;i++)for(int j=0;j<=m;j++)sufi[i][j]=0;
for(int i=1;i<=m;i++){
for(int j=n;j>=1;j--){
sufi[j][i]=sufi[j+1][i];
if(a[j][i]=='I')sufi[j][i]++;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='J'){
/*
int r=0;
for(int k=j+1;k<=m;k++)if(a[i][k]=='O')r++;
int r1=0;
for(int k=i+1;k<=n;k++)if(a[k][j]=='I')r1++;
ans+=r*r1;*/
ans+=sufo[i][j+1]*sufi[i+1][j];
}
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
6 ms |
3672 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
4 ms |
2652 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
7 ms |
4696 KB |
Output is correct |
19 |
Correct |
6 ms |
4700 KB |
Output is correct |
20 |
Correct |
6 ms |
4700 KB |
Output is correct |
21 |
Correct |
7 ms |
4952 KB |
Output is correct |
22 |
Correct |
6 ms |
4700 KB |
Output is correct |
23 |
Correct |
6 ms |
4708 KB |
Output is correct |
24 |
Correct |
8 ms |
4648 KB |
Output is correct |
25 |
Correct |
6 ms |
4700 KB |
Output is correct |
26 |
Correct |
6 ms |
4768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
6 ms |
3672 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
4 ms |
2652 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
7 ms |
4696 KB |
Output is correct |
19 |
Correct |
6 ms |
4700 KB |
Output is correct |
20 |
Correct |
6 ms |
4700 KB |
Output is correct |
21 |
Correct |
7 ms |
4952 KB |
Output is correct |
22 |
Correct |
6 ms |
4700 KB |
Output is correct |
23 |
Correct |
6 ms |
4708 KB |
Output is correct |
24 |
Correct |
8 ms |
4648 KB |
Output is correct |
25 |
Correct |
6 ms |
4700 KB |
Output is correct |
26 |
Correct |
6 ms |
4768 KB |
Output is correct |
27 |
Correct |
332 ms |
146260 KB |
Output is correct |
28 |
Correct |
1 ms |
764 KB |
Output is correct |
29 |
Correct |
16 ms |
11612 KB |
Output is correct |
30 |
Correct |
1 ms |
1112 KB |
Output is correct |
31 |
Correct |
242 ms |
107604 KB |
Output is correct |
32 |
Correct |
361 ms |
154128 KB |
Output is correct |
33 |
Correct |
332 ms |
154192 KB |
Output is correct |
34 |
Correct |
272 ms |
124872 KB |
Output is correct |
35 |
Correct |
333 ms |
153824 KB |
Output is correct |
36 |
Correct |
334 ms |
154192 KB |
Output is correct |
37 |
Correct |
370 ms |
154856 KB |
Output is correct |
38 |
Correct |
216 ms |
107088 KB |
Output is correct |
39 |
Correct |
204 ms |
107352 KB |
Output is correct |