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>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 3005;
int n, m, cnti[N], cntRight[N][N], cntDown[N][N];
char a[N][N];
signed main() {
#ifdef BLU
in("blu.inp");
#endif
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
fw (i, 0, n) fw (j, 0, m) cin >> a[i][j];
fw (i, 0, n) fw (j, 0, m) {
if (a[i][j] == 'I') cnti[j]++;
}
fw (i, 0, n) {
int rowCntO = 0;
fw (j, 0, m) {
if (a[i][j] == 'O') rowCntO++;
}
fw (j, 0, m) {
if (a[i][j] == 'O') rowCntO--;
else if (a[i][j] == 'J') {
cntRight[i][j] = rowCntO;
}
}
fw (j, 0, m) {
if (a[i][j] == 'I') cnti[j]--;
if (a[i][j] == 'J') cntDown[i][j] = cnti[j];
}
}
long long ans = 0;
fw (i, 0, n) {
fw (j, 0, m) {
if (a[i][j] == 'J') ans += 1ll * cntDown[i][j] * cntRight[i][j];
}
}
cout << ans;
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... |