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 N = 3e3;
const int MOD = 1e9 + 7;
const ll oo = 1e18;
int n,m;
char a[N + 5][N + 5];
int bit[2][N + 5][N + 5];
vector <int> cntJ[N + 5];
void upd(int x, int tp, int z)
{
for (; x <= N; x += x & -x) bit[z][tp][x]++;
}
int get(int x, int tp, int z)
{
int ans = 0;
while (x > 0) {
ans += bit[z][tp][x];
x -= x & -x;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
for (int j = 1; j <= m; ++j) {
a[i][j] = s[j - 1];
if (a[i][j] == 'O') upd(j,i,0);
else if (a[i][j] == 'I') upd(i,j,1);
else cntJ[j].push_back(i);
}
}
ll ans = 0;
for (int j = 1; j <= m; ++j) {
for (int i : cntJ[j]) {
ll tmpI = get(n,j,1) - get(i,j,1);
ll tmpO = get(m,i,0) - get(j,i,0);
//cout << j << ' ' << i << ' ' << tmpI << ' ' << tmpO << '\n';
ans = ans + tmpI * tmpO;
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |