#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long ll;
char mp[3010][3010];
ll rw[3010][3010],col[3010][3010];
int main() {
speed;
int h,w;
cin>>h>>w;
for (int i=1;i<=h;i++) {
for (int j=1;j<=w;j++) {
cin>>mp[i][j];
}
}
memset(rw,0,sizeof(rw));
memset(col,0,sizeof(col));
for (int i=h;i>=1;i--) {
for (int j=w;j>=1;j--) {
rw[i][j]=rw[i][j+1];
col[i][j]=col[i+1][j];
if (mp[i][j]=='O') rw[i][j]++;
else if (mp[i][j]=='I') col[i][j]++;
}
}
ll ans=0;
for (int i=1;i<=h;i++) {
for (int j=1;j<=w;j++) {
ans+=(mp[i][j]=='J'?col[i][j]*rw[i][j]:0);
}
}
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... |