#include <bits/stdc++.h>
using namespace std;
#define rep(a) for(int i = 0;i<a;i++)
#define rep2(a) for(int j = 0;j<a;j++)
#define repm(a) for(int j = a-1;j>=0;j--)
int main()
{
int h,w;
cin>>h>>w;
int b[h][w];
rep(h)
{
string s;
cin>>s;
rep2(w)
{
if(s[j] == 'J')
{
b[i][j] = 0;
}
else if(s[j] == 'O')
{
b[i][j] = 1;
}
else
{
b[i][j] = 2;
}
}
}
int dp1[h][w];
int dp2[h][w];
rep(h)
{
dp1[i][w-1] = 0;
if(b[i][w-1] == 1)
{
dp1[i][w-1]++;
}
for(int j = w-2;j>=0;j--)
{
dp1[i][j] = dp1[i][j+1];
if(b[i][j] == 1)
{
dp1[i][j]++;
}
}
}
rep(w)
{
dp2[h-1][i] = 0;
if(b[h-1][i] == 2)
{
dp2[h-1][i]++;
}
for(int j = h-2;j>=0;j--)
{
dp2[j][i] = dp2[j+1][i];
if(b[j][i] == 2)
{
dp2[j][i]++;
}
}
}
long long ans = 0;
rep(h)
{
rep2(w)
{
if(b[i][j] == 0)
{
//cout<<dp2[i][j]<<" "<<dp1[i][j]<<"\n";
ans+=dp2[i][j]*dp1[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... |