#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3005;
int H , W;
string s[N];
int Jo[N][N] , Ji[N][N];
ll solve(){
for(int i = 0; i < H; ++i){
int cntO = 0;
for(int j = W - 1; j >= 0; --j){
if(s[i][j] == 'O') ++cntO;
if(s[i][j] == 'J') Jo[i][j] = cntO;
}
}
for(int i = 0; i < W; ++i){
int cntI = 0;
for(int j = H - 1; j>= 0; --j){
if(s[j][i] == 'I') ++cntI;
if(s[j][i] == 'J') Ji[j][i] = cntI;
}
}/*
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; ++j) cout << Jo[i][j] << " "; cout << endl;
}cerr << endl;
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; ++j) cout << Ji[i][j] << " "; cout << endl;
}cerr << endl;
*/
ll ans = 0;
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; ++j){
//cerr << Jo[i][j] * Ji[i][j] << endl;
ans += 1LL*Jo[i][j] * Ji[i][j];
}
}
return ans;
}
int main (){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> H >> W;
for(int i = 0; i < H; ++i) cin >> s[i];
cout << solve() << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
6 ms |
1280 KB |
Output is correct |
9 |
Correct |
5 ms |
1280 KB |
Output is correct |
10 |
Correct |
6 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1280 KB |
Output is correct |
12 |
Correct |
5 ms |
1280 KB |
Output is correct |
13 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
6 ms |
1280 KB |
Output is correct |
9 |
Correct |
5 ms |
1280 KB |
Output is correct |
10 |
Correct |
6 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1280 KB |
Output is correct |
12 |
Correct |
5 ms |
1280 KB |
Output is correct |
13 |
Correct |
5 ms |
1280 KB |
Output is correct |
14 |
Correct |
11 ms |
6144 KB |
Output is correct |
15 |
Correct |
6 ms |
3584 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
18 |
Correct |
12 ms |
6656 KB |
Output is correct |
19 |
Correct |
8 ms |
5632 KB |
Output is correct |
20 |
Correct |
8 ms |
5248 KB |
Output is correct |
21 |
Correct |
12 ms |
6656 KB |
Output is correct |
22 |
Correct |
12 ms |
6080 KB |
Output is correct |
23 |
Correct |
8 ms |
5248 KB |
Output is correct |
24 |
Correct |
11 ms |
6656 KB |
Output is correct |
25 |
Correct |
8 ms |
5632 KB |
Output is correct |
26 |
Correct |
8 ms |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
1152 KB |
Output is correct |
8 |
Correct |
6 ms |
1280 KB |
Output is correct |
9 |
Correct |
5 ms |
1280 KB |
Output is correct |
10 |
Correct |
6 ms |
1152 KB |
Output is correct |
11 |
Correct |
5 ms |
1280 KB |
Output is correct |
12 |
Correct |
5 ms |
1280 KB |
Output is correct |
13 |
Correct |
5 ms |
1280 KB |
Output is correct |
14 |
Correct |
11 ms |
6144 KB |
Output is correct |
15 |
Correct |
6 ms |
3584 KB |
Output is correct |
16 |
Correct |
7 ms |
3200 KB |
Output is correct |
17 |
Correct |
5 ms |
512 KB |
Output is correct |
18 |
Correct |
12 ms |
6656 KB |
Output is correct |
19 |
Correct |
8 ms |
5632 KB |
Output is correct |
20 |
Correct |
8 ms |
5248 KB |
Output is correct |
21 |
Correct |
12 ms |
6656 KB |
Output is correct |
22 |
Correct |
12 ms |
6080 KB |
Output is correct |
23 |
Correct |
8 ms |
5248 KB |
Output is correct |
24 |
Correct |
11 ms |
6656 KB |
Output is correct |
25 |
Correct |
8 ms |
5632 KB |
Output is correct |
26 |
Correct |
8 ms |
5248 KB |
Output is correct |
27 |
Correct |
272 ms |
82748 KB |
Output is correct |
28 |
Correct |
13 ms |
18048 KB |
Output is correct |
29 |
Correct |
11 ms |
5376 KB |
Output is correct |
30 |
Correct |
5 ms |
768 KB |
Output is correct |
31 |
Correct |
203 ms |
71928 KB |
Output is correct |
32 |
Correct |
161 ms |
75256 KB |
Output is correct |
33 |
Correct |
175 ms |
66296 KB |
Output is correct |
34 |
Correct |
229 ms |
83448 KB |
Output is correct |
35 |
Correct |
184 ms |
78968 KB |
Output is correct |
36 |
Correct |
172 ms |
66296 KB |
Output is correct |
37 |
Correct |
287 ms |
89440 KB |
Output is correct |
38 |
Correct |
101 ms |
57592 KB |
Output is correct |
39 |
Correct |
111 ms |
49400 KB |
Output is correct |