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 int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin>>n>>m;
char a[n+1][m+1];
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
//! (i,j)='j',(i,l)='o',(k,j)='i'
int ans=0;
int sufo[n+1][m+2];
for(int i=0;i<=n;i++)for(int j=0;j<=m+1;j++)sufo[i][j]=0;
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
sufo[i][j]=sufo[i][j+1];
if(a[i][j]=='O')sufo[i][j]++;
}
}
int sufi[n+2][m+1];
for(int i=0;i<=n+1;i++)for(int j=0;j<=m;j++)sufi[i][j]=0;
for(int i=1;i<=m;i++){
for(int j=n;j>=1;j--){
sufi[j][i]=sufi[j+1][i];
if(a[j][i]=='I')sufi[j][i]++;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='J'){
/*
int r=0;
for(int k=j+1;k<=m;k++)if(a[i][k]=='O')r++;
int r1=0;
for(int k=i+1;k<=n;k++)if(a[k][j]=='I')r1++;
ans+=r*r1;*/
ans+=sufo[i][j+1]*sufi[i+1][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... |