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;
using ll = long long;
int main() {
int n, m;
cin >> n >> m;
vector <string> grid(n+1);
for (int i = 1; i <= n; i++) {
cin >> grid[i];
grid[i] = "0" + grid[i];
}
map <char, vector <vector <int>>> pfx;
pfx['O'] = pfx['I'] = vector <vector <int>> (n+1, vector <int> (m+1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (grid[i][j] != 'J')
pfx[grid[i][j]][i][j]++;
pfx['O'][i][j] += pfx['O'][i][j-1];
pfx['I'][i][j] += pfx['I'][i-1][j];
}
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (grid[i][j] != 'J')
continue;
ll a = pfx['O'][i][m] - pfx['O'][i][j];
ll b = pfx['I'][n][j] - pfx['I'][i][j];
ans += a * b;
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |