#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h, w;
cin >> h >> w;
string arr[h];
for(int i=0; i<h; i++){
cin >> arr[i];
}
int ingots[h][w];
for(int i=0; i<w; i++){
if(arr[h-1][i]=='I'){
ingots[h-1][i]=1;
}
else{
ingots[h-1][i]=0;
}
}
for(int i=h-2; i>=0; i--){
for(int j=0; j<w; j++){
ingots[i][j]=ingots[i+1][j];
if(arr[i][j]=='I'){
ingots[i][j]++;
}
}
}
int orbs[h][w];
for(int i=0; i<h; i++){
if(arr[i][w-1]=='O'){
orbs[i][w-1]=1;
}
else{
orbs[i][w-1]=0;
}
}
for(int i=0; i<h; i++){
for(int j=w-2; j>=0; j--){
orbs[i][j]=orbs[i][j+1];
if(arr[i][j]=='O'){
orbs[i][j]++;
}
}
}
long long finans = 0;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(arr[i][j]=='J'){
finans += (long long) (orbs[i][j]*ingots[i][j]);
}
}
}
cout << finans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
2124 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
1492 KB |
Output is correct |
17 |
Correct |
0 ms |
324 KB |
Output is correct |
18 |
Correct |
5 ms |
2792 KB |
Output is correct |
19 |
Correct |
3 ms |
2644 KB |
Output is correct |
20 |
Correct |
4 ms |
2632 KB |
Output is correct |
21 |
Correct |
5 ms |
2772 KB |
Output is correct |
22 |
Correct |
3 ms |
2596 KB |
Output is correct |
23 |
Correct |
3 ms |
2644 KB |
Output is correct |
24 |
Correct |
5 ms |
2772 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
4 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
4 ms |
2124 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
1492 KB |
Output is correct |
17 |
Correct |
0 ms |
324 KB |
Output is correct |
18 |
Correct |
5 ms |
2792 KB |
Output is correct |
19 |
Correct |
3 ms |
2644 KB |
Output is correct |
20 |
Correct |
4 ms |
2632 KB |
Output is correct |
21 |
Correct |
5 ms |
2772 KB |
Output is correct |
22 |
Correct |
3 ms |
2596 KB |
Output is correct |
23 |
Correct |
3 ms |
2644 KB |
Output is correct |
24 |
Correct |
5 ms |
2772 KB |
Output is correct |
25 |
Correct |
3 ms |
2644 KB |
Output is correct |
26 |
Correct |
4 ms |
2644 KB |
Output is correct |
27 |
Correct |
144 ms |
81844 KB |
Output is correct |
28 |
Correct |
1 ms |
584 KB |
Output is correct |
29 |
Correct |
6 ms |
6716 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
121 ms |
61844 KB |
Output is correct |
32 |
Correct |
95 ms |
85768 KB |
Output is correct |
33 |
Correct |
93 ms |
86232 KB |
Output is correct |
34 |
Correct |
130 ms |
70632 KB |
Output is correct |
35 |
Correct |
100 ms |
85836 KB |
Output is correct |
36 |
Correct |
86 ms |
86144 KB |
Output is correct |
37 |
Correct |
151 ms |
86424 KB |
Output is correct |
38 |
Correct |
66 ms |
61232 KB |
Output is correct |
39 |
Correct |
61 ms |
61408 KB |
Output is correct |