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 <bits/stdc++.h>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define inside sl<=l&&r<=sr
#define outside sr<l||r<sl
using namespace std;
typedef long long ll;
int n, m;
int dpo[3003][3003];
int dpi[3003][3003];
char mat[3003][3003];
int main(){
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
cin.tie(0); ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> mat[i][j];
}
}
for (int i = 0; i < n; i++){
int sum = 0;
for (int j = m-1; j >= 0; j--){
sum += mat[i][j] == 'O';
dpo[i][j] = sum;
}
}
for (int j = 0; j < m; j++){
int sum = 0;
for (int i = n-1; i >= 0; i--){
sum += mat[i][j] == 'I';
dpi[i][j] = sum;
}
}
ll ans = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (mat[i][j] == 'J') ans += (ll)dpi[i][j]*(ll)dpo[i][j];
}
}
cout << ans << endl;
}
//by ekrem
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |