#include <bits/stdc++.h>
#define int long long
using namespace std;
int a,b;
char z[5005][5005];
int cot[1000005];
int ans=0;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> b;
for (int i=1;i<=a;i++){
string s;
cin >> s;
for (int j=0;j<b;j++){
z[i][j+1]=s[j];
}
}
for (int i=1;i<=a;i++){
int prefix=0;
for (int j=b;j>=1;j--){
if (z[i][j]=='I'){
ans+=cot[j];
}else if (z[i][j]=='J'){
cot[j]+=prefix;
}else{
prefix++;
}
}
}
cout << ans << "\n";
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... |