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>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
long long n,m;
cin>>n>>m;
char mat[n][m];
long long ci[n];
long long cj[m];
long long posi[n][m];
long long posj[m][n];
memset(posi,0,sizeof posi);
memset(posj,0,sizeof posj);
memset(ci,0,sizeof ci);
memset(cj,0,sizeof cj);
vector<pair<long long,long long>>v;
for(long long i=0;i<n;i++)
{
for(long long j=0;j<m;j++)
{
cin>>mat[i][j];
if(j>0)
{
posi[i][j]=posi[i][j-1];
}
if(i>0)
{
posj[j][i]=posj[j][i-1];
}
if(mat[i][j]=='O')
{
ci[i]++;
posi[i][j]++;
}
if(mat[i][j]=='I')
{
cj[j]++;
posj[j][i]++;
}
if(mat[i][j]=='J')
{
v.push_back({i,j});
}
}
}
long long ans=0;
for(auto idx:v)
{
long long a=idx.first;
long long b=idx.second;
if(ci[a]-posi[a][b]>0 && cj[b]-posj[b][a]>0)
ans+=(ci[a]-posi[a][b])*(cj[b]-posj[b][a]);
}
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... |