//Coded by Chirath Nirodha
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const ll mod=1e9+7;
inline void io(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void solve(){
ll h,w;cin>>h>>w;
char arr[h][w];
for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>arr[i][j];
ll hor[h][w];
ll ver[h][w];
for(int i=0;i<h;i++){
if(arr[i][w-1]=='O')hor[i][w-1]=1;
else hor[i][w-1]=0;
for(int j=w-2;j>=0;j--){
hor[i][j]=hor[i][j+1];
if(arr[i][j]=='O')hor[i][j]++;
}
}
for(int j=0;j<w;j++){
if(arr[h-1][j]=='I')ver[h-1][j]=1;
else ver[h-1][j]=0;
for(int i=h-2;i>=0;i--){
ver[i][j]=ver[i+1][j];
if(arr[i][j]=='I')ver[i][j]++;
}
}
ll ans=0;
for(int i=0;i<h-1;i++){
for(int j=0;j<w-1;j++){
if(arr[i][j]!='J')continue;
ans+=hor[i][j+1]*ver[i+1][j];
}
}
cout<<ans<<endl;
}
int main(){
io();
solve();
//int t;cin>>t;for(int i=0;i<t;i++)solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
8 ms |
3656 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
2500 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
11 ms |
4712 KB |
Output is correct |
19 |
Correct |
11 ms |
4428 KB |
Output is correct |
20 |
Correct |
8 ms |
4556 KB |
Output is correct |
21 |
Correct |
10 ms |
4640 KB |
Output is correct |
22 |
Correct |
9 ms |
4420 KB |
Output is correct |
23 |
Correct |
8 ms |
4556 KB |
Output is correct |
24 |
Correct |
10 ms |
4716 KB |
Output is correct |
25 |
Correct |
8 ms |
4428 KB |
Output is correct |
26 |
Correct |
8 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
8 ms |
3656 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
2500 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
11 ms |
4712 KB |
Output is correct |
19 |
Correct |
11 ms |
4428 KB |
Output is correct |
20 |
Correct |
8 ms |
4556 KB |
Output is correct |
21 |
Correct |
10 ms |
4640 KB |
Output is correct |
22 |
Correct |
9 ms |
4420 KB |
Output is correct |
23 |
Correct |
8 ms |
4556 KB |
Output is correct |
24 |
Correct |
10 ms |
4716 KB |
Output is correct |
25 |
Correct |
8 ms |
4428 KB |
Output is correct |
26 |
Correct |
8 ms |
4556 KB |
Output is correct |
27 |
Correct |
446 ms |
149900 KB |
Output is correct |
28 |
Correct |
2 ms |
716 KB |
Output is correct |
29 |
Correct |
22 ms |
11676 KB |
Output is correct |
30 |
Correct |
1 ms |
588 KB |
Output is correct |
31 |
Correct |
324 ms |
110336 KB |
Output is correct |
32 |
Correct |
432 ms |
157632 KB |
Output is correct |
33 |
Correct |
427 ms |
158148 KB |
Output is correct |
34 |
Correct |
385 ms |
128076 KB |
Output is correct |
35 |
Correct |
437 ms |
157632 KB |
Output is correct |
36 |
Correct |
439 ms |
158204 KB |
Output is correct |
37 |
Correct |
488 ms |
158700 KB |
Output is correct |
38 |
Correct |
287 ms |
109484 KB |
Output is correct |
39 |
Correct |
298 ms |
109796 KB |
Output is correct |