This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
void solve(){
int n, m;
cin >> n >> m;
vector<string> s(n+1);
for(int i = 1; i <= n; i++){
cin >> s[i];
s[i] = ' ' + s[i];
}
vector<vector<ll>> orb(n+2, vector<ll>(m+2, 0)), ingot(n+2, vector<ll>(m+2, 0));
for(int i = 1; i <= n; i++){
for(int j = m; j >= 1; j--){
orb[i][j] = orb[i][j+1];
if(s[i][j] == 'O') orb[i][j]++;
}
}
for(int j = 1; j <= m; j++){
for(int i = n; i >= 1; i--){
ingot[i][j] = ingot[i+1][j];
if(s[i][j] == 'I') ingot[i][j]++;
}
}
ll ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(s[i][j] == 'J'){
ans += orb[i][j+1]*ingot[i+1][j];
}
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |