#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int h,w; cin>>h>>w;
vector<string> a;
for (int i=0; i<h; i++) {
string s; cin>>s;
a.push_back(s);
}
vector<vector<int>> osf(h,vector<int>(w,0));
for (int i=0; i<h; i++) {
if (a[i][w-1]=='O') osf[i][w-1]=1;
for (int j=w-2; j>=0; j--) {
if (a[i][j]=='O') osf[i][j]=osf[i][j+1]+1;
else osf[i][j]=osf[i][j+1];
}
}
vector<vector<int>> isf(h,vector<int>(w,0));
for (int j=0; j<w; j++) {
if (a[h-1][j]=='I') isf[h-1][j]=1;
for (int i=h-2; i>=0; i--) {
if (a[i][j]=='I') isf[i][j]=isf[i+1][j]+1;
else isf[i][j]=isf[i+1][j];
}
}
ll ans=0;
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
if (a[i][j]=='J') {
ans+=osf[i][j]*isf[i][j];
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
2140 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1588 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
9 ms |
2908 KB |
Output is correct |
19 |
Correct |
5 ms |
2652 KB |
Output is correct |
20 |
Correct |
5 ms |
2652 KB |
Output is correct |
21 |
Correct |
8 ms |
2712 KB |
Output is correct |
22 |
Correct |
6 ms |
2652 KB |
Output is correct |
23 |
Correct |
6 ms |
2652 KB |
Output is correct |
24 |
Correct |
7 ms |
2908 KB |
Output is correct |
25 |
Correct |
6 ms |
2652 KB |
Output is correct |
26 |
Correct |
5 ms |
2868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
6 ms |
2140 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
1588 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
9 ms |
2908 KB |
Output is correct |
19 |
Correct |
5 ms |
2652 KB |
Output is correct |
20 |
Correct |
5 ms |
2652 KB |
Output is correct |
21 |
Correct |
8 ms |
2712 KB |
Output is correct |
22 |
Correct |
6 ms |
2652 KB |
Output is correct |
23 |
Correct |
6 ms |
2652 KB |
Output is correct |
24 |
Correct |
7 ms |
2908 KB |
Output is correct |
25 |
Correct |
6 ms |
2652 KB |
Output is correct |
26 |
Correct |
5 ms |
2868 KB |
Output is correct |
27 |
Correct |
256 ms |
83932 KB |
Output is correct |
28 |
Correct |
2 ms |
860 KB |
Output is correct |
29 |
Correct |
13 ms |
6804 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
191 ms |
61776 KB |
Output is correct |
32 |
Correct |
214 ms |
88072 KB |
Output is correct |
33 |
Correct |
223 ms |
88816 KB |
Output is correct |
34 |
Correct |
212 ms |
71904 KB |
Output is correct |
35 |
Correct |
218 ms |
88088 KB |
Output is correct |
36 |
Correct |
258 ms |
88372 KB |
Output is correct |
37 |
Correct |
268 ms |
88656 KB |
Output is correct |
38 |
Correct |
146 ms |
61396 KB |
Output is correct |
39 |
Correct |
146 ms |
61524 KB |
Output is correct |