#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000000
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int h, w;
cin>>h>>w;
char mat[h+1][w+1];
int preo[h+1][w+1];
int prer[h+1][w+1];
for(int i = 1;i<=h;i++) for(int j = 1;j<=w;j++) preo[i][j] = prer[i][j] = 0;
for(int i = 1;i<=h;i++){
string s;
cin>>s;
for(int j = 1;j<=w;j++){
mat[i][j] = s[j-1];
}
}
int cnt = 0;
for(int i = 1;i<=h;i++){
preo[i][w] = (mat[i][w]=='O');
for(int j = w-1;j>=1;j--){
preo[i][j] = preo[i][j+1] + (mat[i][j]=='O');
}
}
for(int j = 1;j<=w;j++){
prer[h][j] = (mat[h][j] == 'I');
for(int i = h-1;i>=1;i--){
prer[i][j] = prer[i+1][j] + (mat[i][j]=='I');
}
}
for(int i = 1;i<h;i++){
for(int j = 1;j<w;j++){
if(mat[i][j] == 'J') cnt += (preo[i][j+1] * prer[i+1][j]);
}
}
cout<<cnt<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
560 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
560 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
10 ms |
3712 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
2560 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
10 ms |
4736 KB |
Output is correct |
19 |
Correct |
9 ms |
4608 KB |
Output is correct |
20 |
Correct |
10 ms |
4608 KB |
Output is correct |
21 |
Correct |
11 ms |
4736 KB |
Output is correct |
22 |
Correct |
9 ms |
4608 KB |
Output is correct |
23 |
Correct |
10 ms |
4608 KB |
Output is correct |
24 |
Correct |
10 ms |
4736 KB |
Output is correct |
25 |
Correct |
9 ms |
4608 KB |
Output is correct |
26 |
Correct |
10 ms |
4608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
560 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
10 ms |
3712 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
7 ms |
2560 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
10 ms |
4736 KB |
Output is correct |
19 |
Correct |
9 ms |
4608 KB |
Output is correct |
20 |
Correct |
10 ms |
4608 KB |
Output is correct |
21 |
Correct |
11 ms |
4736 KB |
Output is correct |
22 |
Correct |
9 ms |
4608 KB |
Output is correct |
23 |
Correct |
10 ms |
4608 KB |
Output is correct |
24 |
Correct |
10 ms |
4736 KB |
Output is correct |
25 |
Correct |
9 ms |
4608 KB |
Output is correct |
26 |
Correct |
10 ms |
4608 KB |
Output is correct |
27 |
Correct |
346 ms |
150136 KB |
Output is correct |
28 |
Correct |
5 ms |
768 KB |
Output is correct |
29 |
Correct |
16 ms |
11776 KB |
Output is correct |
30 |
Correct |
5 ms |
768 KB |
Output is correct |
31 |
Correct |
253 ms |
110456 KB |
Output is correct |
32 |
Correct |
330 ms |
157816 KB |
Output is correct |
33 |
Correct |
336 ms |
158456 KB |
Output is correct |
34 |
Correct |
277 ms |
128124 KB |
Output is correct |
35 |
Correct |
331 ms |
157816 KB |
Output is correct |
36 |
Correct |
325 ms |
158328 KB |
Output is correct |
37 |
Correct |
362 ms |
158968 KB |
Output is correct |
38 |
Correct |
217 ms |
109560 KB |
Output is correct |
39 |
Correct |
232 ms |
109944 KB |
Output is correct |