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(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin >> n >> m;
char arr[n+1][m+1];
int pref1[n+1][m+1];
int pref2[n+1][m+1];
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
pref1[i][j]=0;
pref2[i][j]=0;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> arr[i][j];
pref1[i][j]=pref1[i][j-1];
pref2[i][j]=pref2[i-1][j];
if(arr[i][j]=='O'){
pref1[i][j]=pref1[i][j-1]+1;
}
if(arr[i][j]=='I'){
pref2[i][j]=pref2[i-1][j]+1;
}
}
}
long long ans=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(arr[i][j]=='J'){
ans+=((pref1[i][m]-pref1[i][j])*(pref2[n][j]-pref2[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... |