#include <iostream>
using namespace std;
const int N = 3e3 + 5;
int dp_orb [N][N];
int dp_ingot [N][N];
char g [N][N];
int main () {
int r, c;
cin >> r >> c;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> g[i][j];
}
}
for (int i = 0; i < r; i++) {
for (int j = c - 1; j >= 0; j--) {
dp_orb[i][j] = (g[i][j] == 'O');
if (j < c - 1) dp_orb[i][j] += dp_orb[i][j + 1];
}
}
for (int i = 0; i < c; i++) {
for (int j = r - 1; j >= 0; j--) {
dp_ingot[i][j] = (g[j][i] == 'I');
if (j < r - 1) dp_ingot[i][j] += dp_ingot[i][j + 1];
}
}
long long res = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (g[i][j] != 'J') continue;
int tot_orb = (j + 1 < c ? dp_orb[i][j + 1] : 0);
int tot_ingot = (i + 1 < r ? dp_ingot[j][i + 1] : 0);
res += tot_orb * tot_ingot;
}
}
cout << res << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
1536 KB |
Output is correct |
6 |
Correct |
6 ms |
1408 KB |
Output is correct |
7 |
Correct |
6 ms |
1408 KB |
Output is correct |
8 |
Correct |
7 ms |
1536 KB |
Output is correct |
9 |
Correct |
6 ms |
1408 KB |
Output is correct |
10 |
Correct |
6 ms |
1408 KB |
Output is correct |
11 |
Correct |
6 ms |
1408 KB |
Output is correct |
12 |
Correct |
6 ms |
1408 KB |
Output is correct |
13 |
Correct |
6 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
1536 KB |
Output is correct |
6 |
Correct |
6 ms |
1408 KB |
Output is correct |
7 |
Correct |
6 ms |
1408 KB |
Output is correct |
8 |
Correct |
7 ms |
1536 KB |
Output is correct |
9 |
Correct |
6 ms |
1408 KB |
Output is correct |
10 |
Correct |
6 ms |
1408 KB |
Output is correct |
11 |
Correct |
6 ms |
1408 KB |
Output is correct |
12 |
Correct |
6 ms |
1408 KB |
Output is correct |
13 |
Correct |
6 ms |
1536 KB |
Output is correct |
14 |
Correct |
25 ms |
7068 KB |
Output is correct |
15 |
Correct |
6 ms |
3324 KB |
Output is correct |
16 |
Correct |
18 ms |
5248 KB |
Output is correct |
17 |
Correct |
5 ms |
1536 KB |
Output is correct |
18 |
Correct |
30 ms |
8060 KB |
Output is correct |
19 |
Correct |
29 ms |
7808 KB |
Output is correct |
20 |
Correct |
29 ms |
7936 KB |
Output is correct |
21 |
Correct |
30 ms |
8064 KB |
Output is correct |
22 |
Correct |
28 ms |
7808 KB |
Output is correct |
23 |
Correct |
29 ms |
7936 KB |
Output is correct |
24 |
Correct |
30 ms |
8064 KB |
Output is correct |
25 |
Correct |
28 ms |
7808 KB |
Output is correct |
26 |
Correct |
29 ms |
7928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
6 ms |
1536 KB |
Output is correct |
6 |
Correct |
6 ms |
1408 KB |
Output is correct |
7 |
Correct |
6 ms |
1408 KB |
Output is correct |
8 |
Correct |
7 ms |
1536 KB |
Output is correct |
9 |
Correct |
6 ms |
1408 KB |
Output is correct |
10 |
Correct |
6 ms |
1408 KB |
Output is correct |
11 |
Correct |
6 ms |
1408 KB |
Output is correct |
12 |
Correct |
6 ms |
1408 KB |
Output is correct |
13 |
Correct |
6 ms |
1536 KB |
Output is correct |
14 |
Correct |
25 ms |
7068 KB |
Output is correct |
15 |
Correct |
6 ms |
3324 KB |
Output is correct |
16 |
Correct |
18 ms |
5248 KB |
Output is correct |
17 |
Correct |
5 ms |
1536 KB |
Output is correct |
18 |
Correct |
30 ms |
8060 KB |
Output is correct |
19 |
Correct |
29 ms |
7808 KB |
Output is correct |
20 |
Correct |
29 ms |
7936 KB |
Output is correct |
21 |
Correct |
30 ms |
8064 KB |
Output is correct |
22 |
Correct |
28 ms |
7808 KB |
Output is correct |
23 |
Correct |
29 ms |
7936 KB |
Output is correct |
24 |
Correct |
30 ms |
8064 KB |
Output is correct |
25 |
Correct |
28 ms |
7808 KB |
Output is correct |
26 |
Correct |
29 ms |
7928 KB |
Output is correct |
27 |
Correct |
853 ms |
86056 KB |
Output is correct |
28 |
Correct |
14 ms |
16768 KB |
Output is correct |
29 |
Correct |
69 ms |
17400 KB |
Output is correct |
30 |
Correct |
11 ms |
9728 KB |
Output is correct |
31 |
Correct |
619 ms |
72696 KB |
Output is correct |
32 |
Correct |
849 ms |
86904 KB |
Output is correct |
33 |
Correct |
851 ms |
87032 KB |
Output is correct |
34 |
Correct |
712 ms |
79480 KB |
Output is correct |
35 |
Correct |
865 ms |
86852 KB |
Output is correct |
36 |
Correct |
849 ms |
86904 KB |
Output is correct |
37 |
Correct |
882 ms |
87160 KB |
Output is correct |
38 |
Correct |
584 ms |
72416 KB |
Output is correct |
39 |
Correct |
598 ms |
72584 KB |
Output is correct |