#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pll pair<int, int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define endl '\n'
#define maxn 100005
#define maxc 1e15
#define iii tuple<int,int,int>
signed main(){
int h,w;cin>>h>>w;
vector<vector<char>> mat(h+1, vector<char>(w+1));
vector<vector<int>> ssi(h+1, vector<int>(w+1, 0)),sso(h+1, vector<int>(w+1, 0));
int ans=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>mat[i][j];
}
}
for(int i=0;i<h;i++){
for(int j=w-1;j>=0;j--){
sso[i][j]=sso[i][j+1]+(mat[i][j]=='O'?1:0);
}
}
for(int j=0;j<w;j++){
for(int i=h-1;i>=0;i--){
ssi[i][j]=ssi[i+1][j]+(mat[i][j]=='I'?1:0);
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(mat[i][j]!='J')continue;
ans+=ssi[i][j]*sso[i][j];
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |