#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN=3005;
int n,m;
string s[MAXN];
int pref[2][MAXN][MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>s[i];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(j>0) pref[0][i][j]=pref[0][i][j-1];
if(s[i][j]=='O') pref[0][i][j]++;
}
}
for(int j=0;j<m;j++)
{
for(int i=0;i<n;i++)
{
if(i>0) pref[1][i][j]=pref[1][i-1][j];
if(s[i][j]=='I') pref[1][i][j]++;
}
}
long long ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='J') ans+=(pref[0][i][m-1]-(j>0 ? pref[0][i][j-1] : 0)) * (pref[1][n-1][j]-(i>0 ? pref[1][i-1][j] : 0));
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
1236 KB |
Output is correct |
6 |
Correct |
1 ms |
1236 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1236 KB |
Output is correct |
9 |
Correct |
1 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1236 KB |
Output is correct |
12 |
Correct |
1 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
1236 KB |
Output is correct |
6 |
Correct |
1 ms |
1236 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1236 KB |
Output is correct |
9 |
Correct |
1 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1236 KB |
Output is correct |
12 |
Correct |
1 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
7 ms |
6352 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
3 ms |
3684 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
6784 KB |
Output is correct |
19 |
Correct |
5 ms |
6740 KB |
Output is correct |
20 |
Correct |
5 ms |
6640 KB |
Output is correct |
21 |
Correct |
6 ms |
6868 KB |
Output is correct |
22 |
Correct |
5 ms |
6740 KB |
Output is correct |
23 |
Correct |
5 ms |
6680 KB |
Output is correct |
24 |
Correct |
6 ms |
6836 KB |
Output is correct |
25 |
Correct |
5 ms |
6712 KB |
Output is correct |
26 |
Correct |
5 ms |
6700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
416 KB |
Output is correct |
5 |
Correct |
1 ms |
1236 KB |
Output is correct |
6 |
Correct |
1 ms |
1236 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1236 KB |
Output is correct |
9 |
Correct |
1 ms |
1236 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1236 KB |
Output is correct |
12 |
Correct |
1 ms |
1236 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
7 ms |
6352 KB |
Output is correct |
15 |
Correct |
2 ms |
3796 KB |
Output is correct |
16 |
Correct |
3 ms |
3684 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
6 ms |
6784 KB |
Output is correct |
19 |
Correct |
5 ms |
6740 KB |
Output is correct |
20 |
Correct |
5 ms |
6640 KB |
Output is correct |
21 |
Correct |
6 ms |
6868 KB |
Output is correct |
22 |
Correct |
5 ms |
6740 KB |
Output is correct |
23 |
Correct |
5 ms |
6680 KB |
Output is correct |
24 |
Correct |
6 ms |
6836 KB |
Output is correct |
25 |
Correct |
5 ms |
6712 KB |
Output is correct |
26 |
Correct |
5 ms |
6700 KB |
Output is correct |
27 |
Correct |
229 ms |
88476 KB |
Output is correct |
28 |
Correct |
9 ms |
19284 KB |
Output is correct |
29 |
Correct |
8 ms |
7812 KB |
Output is correct |
30 |
Correct |
1 ms |
692 KB |
Output is correct |
31 |
Correct |
177 ms |
71956 KB |
Output is correct |
32 |
Correct |
215 ms |
89264 KB |
Output is correct |
33 |
Correct |
203 ms |
89184 KB |
Output is correct |
34 |
Correct |
185 ms |
83376 KB |
Output is correct |
35 |
Correct |
210 ms |
89324 KB |
Output is correct |
36 |
Correct |
204 ms |
89128 KB |
Output is correct |
37 |
Correct |
245 ms |
89488 KB |
Output is correct |
38 |
Correct |
150 ms |
71868 KB |
Output is correct |
39 |
Correct |
131 ms |
71552 KB |
Output is correct |