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;
typedef long long ll;
const int MX = 3005;
int N, M;
char grid[MX][MX];
vector<int> v[MX], vv[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> M;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
cin >> grid[i][j];
if(grid[i][j] == 'O') {
v[i].push_back(j);
}
if(grid[i][j] == 'I') {
vv[j].push_back(i);
}
}
}
ll ans = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(grid[i][j] != 'J') continue;
auto x = lower_bound(v[i].begin(), v[i].end(), j) - v[i].begin();
auto y = lower_bound(vv[j].begin(), vv[j].end(), i) - vv[j].begin();
ans += 1LL * (v[i].size() - x) * (vv[j].size() - y);
}
}
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... |