#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 |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1484 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1484 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
8 ms |
7512 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
5 ms |
4308 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
10 ms |
8012 KB |
Output is correct |
19 |
Correct |
9 ms |
7876 KB |
Output is correct |
20 |
Correct |
11 ms |
7824 KB |
Output is correct |
21 |
Correct |
11 ms |
7988 KB |
Output is correct |
22 |
Correct |
11 ms |
7884 KB |
Output is correct |
23 |
Correct |
9 ms |
7756 KB |
Output is correct |
24 |
Correct |
11 ms |
8016 KB |
Output is correct |
25 |
Correct |
9 ms |
7884 KB |
Output is correct |
26 |
Correct |
9 ms |
7764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
1484 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1356 KB |
Output is correct |
8 |
Correct |
1 ms |
1484 KB |
Output is correct |
9 |
Correct |
1 ms |
1484 KB |
Output is correct |
10 |
Correct |
1 ms |
1356 KB |
Output is correct |
11 |
Correct |
1 ms |
1484 KB |
Output is correct |
12 |
Correct |
1 ms |
1484 KB |
Output is correct |
13 |
Correct |
1 ms |
1356 KB |
Output is correct |
14 |
Correct |
8 ms |
7512 KB |
Output is correct |
15 |
Correct |
3 ms |
4940 KB |
Output is correct |
16 |
Correct |
5 ms |
4308 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
10 ms |
8012 KB |
Output is correct |
19 |
Correct |
9 ms |
7876 KB |
Output is correct |
20 |
Correct |
11 ms |
7824 KB |
Output is correct |
21 |
Correct |
11 ms |
7988 KB |
Output is correct |
22 |
Correct |
11 ms |
7884 KB |
Output is correct |
23 |
Correct |
9 ms |
7756 KB |
Output is correct |
24 |
Correct |
11 ms |
8016 KB |
Output is correct |
25 |
Correct |
9 ms |
7884 KB |
Output is correct |
26 |
Correct |
9 ms |
7764 KB |
Output is correct |
27 |
Correct |
343 ms |
87988 KB |
Output is correct |
28 |
Correct |
14 ms |
26052 KB |
Output is correct |
29 |
Correct |
16 ms |
7756 KB |
Output is correct |
30 |
Correct |
1 ms |
588 KB |
Output is correct |
31 |
Correct |
242 ms |
72512 KB |
Output is correct |
32 |
Correct |
318 ms |
88376 KB |
Output is correct |
33 |
Correct |
326 ms |
88188 KB |
Output is correct |
34 |
Correct |
293 ms |
84144 KB |
Output is correct |
35 |
Correct |
322 ms |
88348 KB |
Output is correct |
36 |
Correct |
306 ms |
88108 KB |
Output is correct |
37 |
Correct |
383 ms |
88404 KB |
Output is correct |
38 |
Correct |
221 ms |
72436 KB |
Output is correct |
39 |
Correct |
223 ms |
72256 KB |
Output is correct |