#include <bits/stdc++.h>
using namespace std;
#define int long long
main(){
int n, m; cin >> n >> m;
char arr[n][m];
for (int x = n-1; x > -1; x--){
for (int y = 0; y < m; y++) cin >> arr[x][y];
}
int OpsumHori[n][m], OpsumVert[n][m], IpsumHori[n][m], IpsumVert[n][m];
for (int x = 0; x < n; x++){
OpsumHori[x][m-1] = (arr[x][m-1] == 'O');
IpsumHori[x][m-1] = (arr[x][m-1] == 'I');
for (int y = m-2; y > -1; y--){
OpsumHori[x][y] = OpsumHori[x][y+1] + (arr[x][y] == 'O');
IpsumHori[x][y] = IpsumHori[x][y+1] + (arr[x][y] == 'I');
}
}
for (int y = 0; y < m; y++){
OpsumVert[0][y] = (arr[0][y] == 'O');
IpsumVert[0][y] = (arr[0][y] == 'I');
for (int x = 1; x < n; x++){
OpsumVert[x][y] = OpsumVert[x-1][y] + (arr[x][y] == 'O');
IpsumVert[x][y] = IpsumVert[x-1][y] + (arr[x][y] == 'I');
}
}
int ans = 0;
for (int x = 0; x < n; x++){
for (int y = 0; y < m; y++){
if (arr[x][y] == 'J') ans += OpsumHori[x][y] * IpsumVert[x][y];
}
}
cout << ans;
}
Compilation message
joi2019_ho_t1.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
500 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
500 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
21 ms |
6440 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
11 ms |
4384 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
24 ms |
8276 KB |
Output is correct |
19 |
Correct |
21 ms |
8060 KB |
Output is correct |
20 |
Correct |
21 ms |
8148 KB |
Output is correct |
21 |
Correct |
20 ms |
8344 KB |
Output is correct |
22 |
Correct |
18 ms |
7948 KB |
Output is correct |
23 |
Correct |
22 ms |
8084 KB |
Output is correct |
24 |
Correct |
21 ms |
8276 KB |
Output is correct |
25 |
Correct |
18 ms |
7948 KB |
Output is correct |
26 |
Correct |
22 ms |
8084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
500 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
21 ms |
6440 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
11 ms |
4384 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
24 ms |
8276 KB |
Output is correct |
19 |
Correct |
21 ms |
8060 KB |
Output is correct |
20 |
Correct |
21 ms |
8148 KB |
Output is correct |
21 |
Correct |
20 ms |
8344 KB |
Output is correct |
22 |
Correct |
18 ms |
7948 KB |
Output is correct |
23 |
Correct |
22 ms |
8084 KB |
Output is correct |
24 |
Correct |
21 ms |
8276 KB |
Output is correct |
25 |
Correct |
18 ms |
7948 KB |
Output is correct |
26 |
Correct |
22 ms |
8084 KB |
Output is correct |
27 |
Runtime error |
552 ms |
274432 KB |
Execution killed with signal 9 |
28 |
Halted |
0 ms |
0 KB |
- |