#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3+10;
char mat[maxn][maxn];
long long prefi[maxn][maxn], prefo[maxn][maxn];
int main(){
int h, w;
cin >> h >> w;
for(int i=1; i<=h; i++){
for(int j=1; j<=w; j++){
cin >> mat[i][j];
}
}
for(int i=1; i<=h; i++){
for(int j=w; j>=1; j--){
if(mat[i][j]=='O')prefo[i][j]=1;
prefo[i][j]+=prefo[i][j+1];
}
}
for(int i=h; i>=1; i--){
for(int j=1; j<=w; j++){
if(mat[i][j]=='I')prefi[i][j]=1;
prefi[i][j]+=prefi[i+1][j];
}
}
long long ans=0;
for(int i=1; i<=h; i++){
for(int j=1; j<=w; j++){
if(mat[i][j]=='J'){
ans+=prefi[i][j]*prefo[i][j];
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
1664 KB |
Output is correct |
6 |
Correct |
4 ms |
1536 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
4 ms |
1536 KB |
Output is correct |
10 |
Correct |
4 ms |
1408 KB |
Output is correct |
11 |
Correct |
4 ms |
1664 KB |
Output is correct |
12 |
Correct |
4 ms |
1536 KB |
Output is correct |
13 |
Correct |
4 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
1664 KB |
Output is correct |
6 |
Correct |
4 ms |
1536 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
4 ms |
1536 KB |
Output is correct |
10 |
Correct |
4 ms |
1408 KB |
Output is correct |
11 |
Correct |
4 ms |
1664 KB |
Output is correct |
12 |
Correct |
4 ms |
1536 KB |
Output is correct |
13 |
Correct |
4 ms |
1536 KB |
Output is correct |
14 |
Correct |
23 ms |
8832 KB |
Output is correct |
15 |
Correct |
6 ms |
4992 KB |
Output is correct |
16 |
Correct |
13 ms |
5248 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
30 ms |
9848 KB |
Output is correct |
19 |
Correct |
33 ms |
9720 KB |
Output is correct |
20 |
Correct |
30 ms |
9728 KB |
Output is correct |
21 |
Correct |
28 ms |
9856 KB |
Output is correct |
22 |
Correct |
24 ms |
9700 KB |
Output is correct |
23 |
Correct |
28 ms |
9720 KB |
Output is correct |
24 |
Correct |
30 ms |
9948 KB |
Output is correct |
25 |
Correct |
24 ms |
9720 KB |
Output is correct |
26 |
Correct |
29 ms |
9724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
1664 KB |
Output is correct |
6 |
Correct |
4 ms |
1536 KB |
Output is correct |
7 |
Correct |
4 ms |
1536 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
4 ms |
1536 KB |
Output is correct |
10 |
Correct |
4 ms |
1408 KB |
Output is correct |
11 |
Correct |
4 ms |
1664 KB |
Output is correct |
12 |
Correct |
4 ms |
1536 KB |
Output is correct |
13 |
Correct |
4 ms |
1536 KB |
Output is correct |
14 |
Correct |
23 ms |
8832 KB |
Output is correct |
15 |
Correct |
6 ms |
4992 KB |
Output is correct |
16 |
Correct |
13 ms |
5248 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
30 ms |
9848 KB |
Output is correct |
19 |
Correct |
33 ms |
9720 KB |
Output is correct |
20 |
Correct |
30 ms |
9728 KB |
Output is correct |
21 |
Correct |
28 ms |
9856 KB |
Output is correct |
22 |
Correct |
24 ms |
9700 KB |
Output is correct |
23 |
Correct |
28 ms |
9720 KB |
Output is correct |
24 |
Correct |
30 ms |
9948 KB |
Output is correct |
25 |
Correct |
24 ms |
9720 KB |
Output is correct |
26 |
Correct |
29 ms |
9724 KB |
Output is correct |
27 |
Correct |
799 ms |
150748 KB |
Output is correct |
28 |
Correct |
28 ms |
26336 KB |
Output is correct |
29 |
Correct |
54 ms |
13432 KB |
Output is correct |
30 |
Correct |
5 ms |
768 KB |
Output is correct |
31 |
Correct |
612 ms |
125620 KB |
Output is correct |
32 |
Correct |
718 ms |
150904 KB |
Output is correct |
33 |
Correct |
707 ms |
150296 KB |
Output is correct |
34 |
Correct |
668 ms |
145892 KB |
Output is correct |
35 |
Correct |
742 ms |
150776 KB |
Output is correct |
36 |
Correct |
756 ms |
150264 KB |
Output is correct |
37 |
Correct |
715 ms |
150744 KB |
Output is correct |
38 |
Correct |
517 ms |
124920 KB |
Output is correct |
39 |
Correct |
453 ms |
125140 KB |
Output is correct |