#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 - 1][j] + 1;
} else {
dpo[i][j] = dpo[i-1][j];
}
}
}
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[w-1][j] - dpi[i-1][j];
anso = dpo[i][h-1] - dpo[i][j-1];
//cout << ansi << " " << anso << endl;
res += ansi * anso * 1ll;
}
}
}
cout << res << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |