#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll h, w;
cin >> h >> w;
vector<string> board(h+5);
for(ll i = 0; i < h; i++){
cin >> board[i];
}
ll ans=0;
vector<ll> col(w+5, 0);
vector<ll> suf(w+5, 0);
for(ll i=0;i<h;i++)
{
for(ll j=0;j<w;j++)
{
if(board[i][j]=='I')
{
col[j]++;
}
}
}
for(ll i=0;i<h;i++)
{
for(ll j=0;j<w;j++)
{
if(board[i][j]=='I')
{
col[j]--;
}
}
suf[w] = 0;
for(ll j=w-1;j>=0;j--)
{
suf[j] = suf[j+1] + (board[i][j]=='O');
}
for(ll j=0;j<w;j++)
{
if(board[i][j]=='J')
{
ans += col[j] * suf[j+1];
}
}
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |