#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=3005;
ll cnti[N][N],cnto[N][N];
int main(){
int h,w;cin>>h>>w;
vector<string>g(h);
for(int i=0;i<h;i++)cin>>g[i];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(g[i][j]=='I'){
cnti[i][j]++;
}else if(g[i][j]=='O'){
cnto[i][j]++;
}
}
}
ll ans=0;
for(int j=w-1;j>=0;j--){
for(int i=h-2;i>=0;i--){
cnti[i][j]+=cnti[i+1][j];
}
}
for(int i=0;i<h;i++){
for(int j=w-2;j>=0;j--){
cnto[i][j]+=cnto[i][j+1];
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(g[i][j]!='J')continue;
if(cnti[i][j]>0&&cnto[i][j]>0){
ans+=cnti[i][j]*cnto[i][j];
}
}
}
cout<<ans<<endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |