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];
int ans=0;
int pref[n+1];
for(int i=0;i<=n;i++)pref[i]=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(a[i][j]=='I')pref[i]++;
}
}
int suf[n+1][m+2];
for(int i=0;i<=n;i++)for(int j=0;j<=m+1;j++)suf[i][j]=0;
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
suf[i][j]=suf[i][j+1];
if(a[i][j]=='O')suf[i][j]++;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='J'){
int Z=0;
int R=0;
for(int k=i+1;k<=n;k++){
if(a[k][j]=='I')Z++;
}
for(int k=j+1;k<=m;k++){
if(a[i][k]=='O')R++;
}
ans+=Z*R;
}
}
}
cout<<ans;
}
// bitset fora?
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |