This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
int v[3002][3002];
int dp[3002][3002];
int dp2[3002][3002];
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
int H, W; cin >> H >> W;
for(int i=1;i<=H;i++)
{
string s; cin >> s;
for(int j=1;j<=W;j++)
{
if(s[j-1] == 'J') v[i][j] = 1;
if(s[j-1] == 'O') v[i][j] = 2;
if(s[j-1] == 'I') v[i][j] = 3;
}
}
for(int i=1;i<=H;i++)
{
for(int j=W;j>=1;j--)
{
dp[i][j] = dp[i][j+1];
if(v[i][j] == 2) dp[i][j]++;
}
}
for(int j=1;j<=W;j++)
{
for(int i=H;i>=1;i--)
{
dp2[i][j] = dp2[i+1][j];
if(v[i][j] == 3) dp2[i][j]++;
}
}
long long int ans = 0;
for(int i=1;i<=H;i++)
{
for(int j=1;j<=W;j++)
{
if(v[i][j] == 1) ans += dp[i][j] * dp2[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... |