#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct T{
int x=0,y=0;
};
int H,W;
T V[3001][3001];
set<pair<int,int>> st;
char c;
T* tmp;
string s[3001];
int main() {
cin>>H>>W;
for(int i=0;i<H;i++)cin>>s[i];
for(int i=0;i<H;i++){
int cnt=0;
for(int j=W-1;j>=0;j--)
switch(s[i][j]){
case 'O':cnt++;break;
case 'J':V[i][j].x=cnt;st.insert({i,j});break;
}
}
for(int i=0;i<W;i++){
int cnt=0;
for(int j=H-1;j>=0;j--)
switch(s[j][i]){
case 'I':cnt++;break;
case 'J':V[j][i].y=cnt; st.insert({j,i}); break;
}
}
ll sm=0;
for(auto it:st)sm+=(V[it.first][it.second].x*V[it.first][it.second].y);
cout<<sm;
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... |