#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 3005;
int main(){
int h, w;
ll sum = 0;
ll zerocount, onecount;
vector<string> grid;
string input;
ll pref0[N][N], pref1[N][N];
cin >> h >> w;
for(int i = 0; i < h; i++){
cin >> input;
grid.push_back(input);
}
for(int i = 0; i < N-2; i++){
for(int j = 0; j < N-2; j++){
pref1[i][j] = 0;
pref0[i][j] = 0;
}
}
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(grid[i][j] == 'O'){
pref0[i][j]++;
}
else if(grid[i][j] == 'I'){
pref1[i][j]++;
}
}
}
for(int i = 0; i < h; i++){
for(int j = 1; j < w; j++){
pref0[i][j] += pref0[i][j-1];
}
}
for(int i = 1; i < h; i++){
for(int j = 0; j < w; j++){
pref1[i][j] += pref1[i-1][j];
}
}
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
if(grid[i][j] == 'J'){
// cout << i << " " << j << endl;
zerocount = pref0[i][w-1] - pref0[i][j];
onecount = pref1[h-1][j] - pref1[i][j];
sum += zerocount*onecount;
}
}
}
cout << sum << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
141632 KB |
Output is correct |
2 |
Correct |
63 ms |
141676 KB |
Output is correct |
3 |
Correct |
60 ms |
141608 KB |
Output is correct |
4 |
Correct |
61 ms |
141528 KB |
Output is correct |
5 |
Correct |
59 ms |
141564 KB |
Output is correct |
6 |
Correct |
64 ms |
141604 KB |
Output is correct |
7 |
Correct |
63 ms |
141552 KB |
Output is correct |
8 |
Correct |
60 ms |
141612 KB |
Output is correct |
9 |
Correct |
63 ms |
141580 KB |
Output is correct |
10 |
Correct |
63 ms |
141624 KB |
Output is correct |
11 |
Correct |
60 ms |
141656 KB |
Output is correct |
12 |
Correct |
57 ms |
141552 KB |
Output is correct |
13 |
Correct |
65 ms |
141620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
141632 KB |
Output is correct |
2 |
Correct |
63 ms |
141676 KB |
Output is correct |
3 |
Correct |
60 ms |
141608 KB |
Output is correct |
4 |
Correct |
61 ms |
141528 KB |
Output is correct |
5 |
Correct |
59 ms |
141564 KB |
Output is correct |
6 |
Correct |
64 ms |
141604 KB |
Output is correct |
7 |
Correct |
63 ms |
141552 KB |
Output is correct |
8 |
Correct |
60 ms |
141612 KB |
Output is correct |
9 |
Correct |
63 ms |
141580 KB |
Output is correct |
10 |
Correct |
63 ms |
141624 KB |
Output is correct |
11 |
Correct |
60 ms |
141656 KB |
Output is correct |
12 |
Correct |
57 ms |
141552 KB |
Output is correct |
13 |
Correct |
65 ms |
141620 KB |
Output is correct |
14 |
Correct |
78 ms |
141860 KB |
Output is correct |
15 |
Correct |
57 ms |
141552 KB |
Output is correct |
16 |
Correct |
64 ms |
141784 KB |
Output is correct |
17 |
Correct |
58 ms |
141640 KB |
Output is correct |
18 |
Correct |
66 ms |
141892 KB |
Output is correct |
19 |
Correct |
59 ms |
141900 KB |
Output is correct |
20 |
Correct |
60 ms |
141852 KB |
Output is correct |
21 |
Correct |
66 ms |
141856 KB |
Output is correct |
22 |
Correct |
64 ms |
141912 KB |
Output is correct |
23 |
Correct |
63 ms |
141900 KB |
Output is correct |
24 |
Correct |
71 ms |
141816 KB |
Output is correct |
25 |
Correct |
62 ms |
141868 KB |
Output is correct |
26 |
Correct |
65 ms |
141792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
141632 KB |
Output is correct |
2 |
Correct |
63 ms |
141676 KB |
Output is correct |
3 |
Correct |
60 ms |
141608 KB |
Output is correct |
4 |
Correct |
61 ms |
141528 KB |
Output is correct |
5 |
Correct |
59 ms |
141564 KB |
Output is correct |
6 |
Correct |
64 ms |
141604 KB |
Output is correct |
7 |
Correct |
63 ms |
141552 KB |
Output is correct |
8 |
Correct |
60 ms |
141612 KB |
Output is correct |
9 |
Correct |
63 ms |
141580 KB |
Output is correct |
10 |
Correct |
63 ms |
141624 KB |
Output is correct |
11 |
Correct |
60 ms |
141656 KB |
Output is correct |
12 |
Correct |
57 ms |
141552 KB |
Output is correct |
13 |
Correct |
65 ms |
141620 KB |
Output is correct |
14 |
Correct |
78 ms |
141860 KB |
Output is correct |
15 |
Correct |
57 ms |
141552 KB |
Output is correct |
16 |
Correct |
64 ms |
141784 KB |
Output is correct |
17 |
Correct |
58 ms |
141640 KB |
Output is correct |
18 |
Correct |
66 ms |
141892 KB |
Output is correct |
19 |
Correct |
59 ms |
141900 KB |
Output is correct |
20 |
Correct |
60 ms |
141852 KB |
Output is correct |
21 |
Correct |
66 ms |
141856 KB |
Output is correct |
22 |
Correct |
64 ms |
141912 KB |
Output is correct |
23 |
Correct |
63 ms |
141900 KB |
Output is correct |
24 |
Correct |
71 ms |
141816 KB |
Output is correct |
25 |
Correct |
62 ms |
141868 KB |
Output is correct |
26 |
Correct |
65 ms |
141792 KB |
Output is correct |
27 |
Correct |
279 ms |
150136 KB |
Output is correct |
28 |
Correct |
64 ms |
141772 KB |
Output is correct |
29 |
Correct |
90 ms |
142184 KB |
Output is correct |
30 |
Correct |
76 ms |
141600 KB |
Output is correct |
31 |
Correct |
222 ms |
147880 KB |
Output is correct |
32 |
Correct |
245 ms |
150476 KB |
Output is correct |
33 |
Correct |
227 ms |
150608 KB |
Output is correct |
34 |
Correct |
257 ms |
148892 KB |
Output is correct |
35 |
Correct |
285 ms |
150468 KB |
Output is correct |
36 |
Correct |
231 ms |
150584 KB |
Output is correct |
37 |
Correct |
303 ms |
150644 KB |
Output is correct |
38 |
Correct |
196 ms |
147856 KB |
Output is correct |
39 |
Correct |
189 ms |
147864 KB |
Output is correct |