This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define yn ynnnnnn
using namespace std;
const int INF = 1000000007;
const int N = 3005;
int dpi[N][N], dpo[N][N];
char a[N][N];
int h, w;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> h >> w;
for(int i = 1; i <= h; i++) {
for(int j = 1; j <= w; j++) {
cin >> a[i][j];
}
}
for(int j = 1; j <= w; j++) {
for(int i = 1; i <= h; i++) {
if(a[i][j] == 'I') {
dpi[i][j] = dpi[i-1][j] + 1;
} else {
dpi[i][j] = dpi[i-1][j];
}
}
}
for(int i = 1; i <= h; i++) {
for(int j = 1; j <= w; j++) {
if(a[i][j] == 'O') {
dpo[i][j] = dpo[i][j-1] + 1;
} else {
dpo[i][j] = dpo[i][j-1];
}
}
}
int ansi, anso;
ll res = 0;
for(int i = 1; i <= h; i++) {
for(int j = 1; j <= w; j++) {
if(a[i][j] == 'J') {
ansi = dpi[h][j] - dpi[i-1][j];
anso = dpo[i][w] - dpo[i][j-1];
//cout << ansi << " " << anso << endl;
res += 1ll * ansi * anso;
}
}
}
cout << res << endl;
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... |