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 int long long
const int N = 3e3 + 5;
int n, m, arr[N][N];
vector<int> row[N][5], col[N][5];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char ch;
cin >> ch;
if (ch == 'J') arr[i][j] = 0;
else if (ch == 'O') arr[i][j] = 1;
else arr[i][j] = 2;
row[i][arr[i][j]].push_back(j);
col[j][arr[i][j]].push_back(i);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++) {
sort(row[i][j].begin(), row[i][j].end());
}
}
for (int j = 1; j <= m; j++) {
for (int i = 0; i < 3; i++) {
sort(col[j][i].begin(), col[j][i].end());
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (arr[i][j]) continue;
int cntO = row[i][1].end() - upper_bound(row[i][1].begin(), row[i][1].end(), j);
int cntI = col[j][2].end() - upper_bound(col[j][2].begin(), col[j][2].end(), i);
ans += cntO*cntI;
}
}
cout << ans << '\n';
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... |