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>
using namespace std;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define bas(x) #x << ": " << x << " "
#define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl;
#define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl;
#define ppair(x) "(" << x.first << ", " << x.second << ")"
#define inside sl<=l&&r<=sr
#define outside sr<l||r<sl
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;
}
}
/*for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cout << dpo[i][j];
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cout << dpi[i][j];
}
cout << endl;
}
cout << endl;*/
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |