#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long h,w;cin >> h >> w;
vector<vector<char>> g(h,vector<char>(w));
for(int i = 0;i<h;i++){
for(int j = 0;j<w;j++){
char c;cin >> c;
g[i][j] = c;
}
}
vector<long long> prefixsum(w);
//prefixsum[i][j] = prefixsum at row i starting from column j
long long ans = 0;
for(int i = 1;i<h;i++){
long long trackO = 0;
long long total = 0;
for(int j = w-1;j>=0;j--){
if (g[i-1][j] == 'O'){
trackO += 1;
}
else if (g[i-1][j] == 'J'){
prefixsum[j] += trackO;
}
else{
prefixsum[j] += 0;
}
}
for(int j = 0;j<w;j++){
if (g[i][j] == 'I'){
ans += prefixsum[j];
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |