#include <bits/stdc++.h>
#define fst first
#define snd second
#define pb push_back
#define forn(i,a,b) for(int i = a; i<b; i++)
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset(a,v,sizeof(a))
using namespace std;
typedef long long ll;
int main(){
ll n,m; cin>>n>>m;
vector<string> s(n); forn(i,0,n) cin>>s[i];
vector<vector<ll>> der(n,vector<ll>(m,0));
vector<vector<ll>> aba(n,vector<ll>(m,0));
forn(i,0,n){
for(int j = m-1; j>=0; j--){
der[i][j]=(j+1<m?der[i][j+1]:0);
der[i][j]+=(s[i][j]=='O');
}
}
forn(j,0,m){
for(int i = n-1; i>=0; i--){
aba[i][j]+=(i+1<n?aba[i+1][j]:0);
aba[i][j]+=(s[i][j]=='I');
}
}
/*forn(i,0,n){
forn(j,0,m){
cout<<der[i][j]<<" ";
} cout<<'\n';
}
forn(i,0,n){
forn(j,0,m){
cout<<aba[i][j]<<" ";
} cout<<'\n';
}
*/
ll res = 0;
forn(i,0,n){
forn(j,0,m){
if(s[i][j]=='J'){
//cout<<i<<" "<<j<<'\n';
res+=der[i][j]*aba[i][j];
}
}
}
cout<<res<<'\n';
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |