#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define _ << " " <<
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fasterAndfaster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9+7;
const ll INF = 1e9;
void solve() {
ll i, j, cnt = 0, sum = 0, ans = 0;
string ug, ug1, ug2;
char useg = 'a';
ll h, w;
cin >> h >> w;
vector<string> g(h);
for(auto &x: g) cin >> x;
vector<vector<ll>> cntRowSuf(h, vector<ll>(w, 0));
vector<vector<ll>> cntColSuf(h, vector<ll>(w, 0));
for(i = h - 1; i >= 0; i--) {
for(j = w - 1; j >= 0; j--) {
cntRowSuf[i][j] = (g[i][j] == 'O') + (j + 1 < w ? cntRowSuf[i][j + 1] : 0);
cntColSuf[i][j] = (g[i][j] == 'I') + (i + 1 < h ? cntColSuf[i + 1][j] : 0);
}
}
for(i = 0; i < h; i++) {
for(j = 0; j < w; j++) {
if(g[i][j] == 'J') {
cnt += cntRowSuf[i][j] * cntColSuf[i][j];
}
}
}
cout << cnt << '\n';
}
int main(){
fasterAndfaster;
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... |