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<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN=3005;
int n,m;
string s[MAXN];
int pref[2][MAXN][MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++)
{
cin>>s[i];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(j>0) pref[0][i][j]=pref[0][i][j-1];
if(s[i][j]=='O') pref[0][i][j]++;
}
}
for(int j=0;j<m;j++)
{
for(int i=0;i<n;i++)
{
if(i>0) pref[1][i][j]=pref[1][i-1][j];
if(s[i][j]=='I') pref[1][i][j]++;
}
}
long long ans=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='J') ans+=(pref[0][i][m-1]-(j>0 ? pref[0][i][j-1] : 0)) * (pref[1][n-1][j]-(i>0 ? pref[1][i-1][j] : 0));
}
}
cout<<ans<<endl;
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... |