This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
signed main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<vector<ll>> prefX(m + 1, vector<ll>(n)), prefY(n + 1, vector<ll>(m));
for (int i = n - 1; i > -1; --i) {
for (int j = m - 1; j > -1; --j) {
prefX[j][i] = prefX[j + 1][i] + (a[i][j] == 'O');
prefY[i][j] = prefY[i + 1][j] + (a[i][j] == 'I');
}
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] == 'J') {
ans += prefX[j + 1][i] * prefY[i + 1][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... |