This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Pantyhose(black) + glasses = infinity
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"
const int MAX_N = 3002;
int m, n;
char a[MAX_N][MAX_N];
int row[MAX_N][MAX_N], col[MAX_N][MAX_N];
void readInput() {
cin >> m >> n;
for (int i=1; i<=m; ++i) {
for (int j=1; j<=n; ++j)
cin >> a[i][j];
}
}
void solve() {
for (int i=1; i<=m; ++i) {
for (int j=n; j>=1; --j)
row[i][j] = row[i][j+1] + (a[i][j]=='O');
}
for (int j=1; j<=n; ++j) {
for (int i=m; i>=1; --i)
col[i][j] = col[i+1][j] + (a[i][j]=='I');
}
int64_t res = 0;
for (int i=1; i<=m; ++i) {
for (int j=1; j<=n; ++j) {
if (a[i][j]=='J')
res += row[i][j] * col[i][j];
}
}
cout << res;
}
int main() {
#ifdef GLASSES_GIRL
freopen(FILE_NAME".in", "r", stdin);
freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
readInput();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |