#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
using namespace std;
const ll INF = 1e18, mod = 1e9 + 7, N = 2e5 + 5;
ll gcd(ll a, ll b){
if(b == 0){
return a;
}
return gcd(b, a%b);
}
ll lcm(ll a, ll b){
return (a / gcd(a,b)) * b;
}
void solve(){
ll n,m;
cin >> n >> m;
char s[n + 1][m + 1];
//ll cnt = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> s[i][j];
}
}
vector<vector<ll>>v(n + 2, vector<ll>(m + 2 , 0));
vector<vector<ll>>v1(n + 2, vector<ll>(m + 2 , 0));
for(int i = 1; i <= n; i++){
for(int j = m; j >= 0; j--){
if(s[i][j] == 'O'){
// cout << "w" << endl;
v[i][j] = v[i][j + 1] + 1;
}
else{
v[i][j] = v[i][j + 1];
}
}
}
for(int j = 1; j <= m; j++){
for(int i =n; i >= 0; i--){
if(s[i][j] == 'I'){
v1[i][j] = v1[i + 1][j] + 1;
}
else{
v1[i][j] = v1[i + 1][j];
}
}
}
ll cnt = 0;
ll ans = 0;
for(int i = 1; i <= n; i++){
cnt = 0;
for(int j = 1; j <= m; j++){
if(s[i][j] == 'J'){
// cout << i << " " << j << " " << "O : " << v[i][j] << " " << "I : " << v1[i][j] << endl;
ans += (v1[i][j]) * v[i][j];
}
}
}
cout << ans << endl;
}
int main() {
fast;
ll t = 1;
// cin >> t;
while(t--){
solve();
}
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... |