#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=3005;
char a[N][N];
int cntO[N][N],cntI[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int h,w;
cin>>h>>w;
char a[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>a[i][j];
}
}
for(int i=0;i<h;i++){
int cnt=0;
for(int j=w-1;j>=0;j--){
if(a[i][j]=='O')cnt++;
cntO[i][j]=cnt;
}
}
for(int i=0;i<w;i++){
int cnt=0;
for(int j=h-1;j>=0;j--){
if(a[j][i]=='I')cnt++;
cntI[j][i]=cnt;
}
}
int ans=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(a[i][j]=='J')ans+=cntI[i][j]*cntO[i][j];
}
}
cout<<ans<<"\n";
}
/*
3 4
JOIJ
JIOO
IIII
4 4
JJOO
JJOO
IIJO
IIIJ
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
4436 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
6568 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
4436 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
6568 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
11 ms |
27736 KB |
Output is correct |
15 |
Correct |
3 ms |
22876 KB |
Output is correct |
16 |
Correct |
6 ms |
15048 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
12 ms |
27560 KB |
Output is correct |
19 |
Correct |
9 ms |
27480 KB |
Output is correct |
20 |
Correct |
9 ms |
25436 KB |
Output is correct |
21 |
Correct |
10 ms |
27484 KB |
Output is correct |
22 |
Correct |
10 ms |
27408 KB |
Output is correct |
23 |
Correct |
9 ms |
25432 KB |
Output is correct |
24 |
Correct |
10 ms |
27568 KB |
Output is correct |
25 |
Correct |
9 ms |
27484 KB |
Output is correct |
26 |
Correct |
9 ms |
25436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
4436 KB |
Output is correct |
5 |
Correct |
2 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8540 KB |
Output is correct |
7 |
Correct |
2 ms |
6488 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
6568 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
6488 KB |
Output is correct |
14 |
Correct |
11 ms |
27736 KB |
Output is correct |
15 |
Correct |
3 ms |
22876 KB |
Output is correct |
16 |
Correct |
6 ms |
15048 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
12 ms |
27560 KB |
Output is correct |
19 |
Correct |
9 ms |
27480 KB |
Output is correct |
20 |
Correct |
9 ms |
25436 KB |
Output is correct |
21 |
Correct |
10 ms |
27484 KB |
Output is correct |
22 |
Correct |
10 ms |
27408 KB |
Output is correct |
23 |
Correct |
9 ms |
25432 KB |
Output is correct |
24 |
Correct |
10 ms |
27568 KB |
Output is correct |
25 |
Correct |
9 ms |
27484 KB |
Output is correct |
26 |
Correct |
9 ms |
25436 KB |
Output is correct |
27 |
Correct |
310 ms |
158720 KB |
Output is correct |
28 |
Correct |
14 ms |
111196 KB |
Output is correct |
29 |
Correct |
17 ms |
16220 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
201 ms |
133884 KB |
Output is correct |
32 |
Correct |
292 ms |
159548 KB |
Output is correct |
33 |
Correct |
283 ms |
159712 KB |
Output is correct |
34 |
Correct |
245 ms |
154300 KB |
Output is correct |
35 |
Correct |
278 ms |
159568 KB |
Output is correct |
36 |
Correct |
312 ms |
159828 KB |
Output is correct |
37 |
Correct |
306 ms |
159568 KB |
Output is correct |
38 |
Correct |
185 ms |
133712 KB |
Output is correct |
39 |
Correct |
181 ms |
131668 KB |
Output is correct |