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 ll long long
#define fi first
#define se second
#define sz(a) (long long) a.size()
//#define endl '\n'
const long long INF = 1e18, MOD = 1e9+7;
void test_case() {
int n, m;
cin >> n >> m;
vector a(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
vector suff_row(n, vector<int>(m)), suff_col(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
suff_row[i][j] = (j != m - 1 ? suff_row[i][j + 1] : 0) + (a[i][j] == 'O');
}
}
for (int j = 0; j < m; j++) {
for (int i = n - 1; i >= 0; i--) {
suff_col[i][j] = (i != n - 1 ? suff_col[i + 1][j] : 0) + (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') continue;
ans += suff_row[i][j] * suff_col[i][j];
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
test_case();
}
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... |