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;
void solve(bool testCases = true) {
int T = 1;
if (testCases) cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int r[n][m] = {0};
memset(r, 0, sizeof(r));
for (int i = 0; i < n; i++) {
for (int j = m - 2; j >= 0; j--) {
r[i][j] += r[i][j + 1];
if (v[i][j + 1] == 'O') {
r[i][j]++;
}
}
}
int c[n][m] = {0};
memset(c, 0, sizeof(c));
for (int j = 0; j < m; j++) {
for (int i = n - 2; i >= 0; i--) {
c[i][j] += c[i + 1][j];
if (v[i + 1][j] == 'I') {
c[i][j]++;
}
}
}
long long int answer = 0;
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (v[i][j] == 'J') {
answer += (r[i][j] * 1LL * c[i][j]);
}
}
}
cout << answer;
cout << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve(false);
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... |