#include<bits/stdc++.h>
#define int long long
using namespace std;
const int sz = 3e3 + 9;
char a[sz][sz];
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int h, w;
cin >> h >> w;
map <int, vector <int>> os, is;
int r = 0;
for (int i = 1; i <= h; i ++) {
for (int j = 1; j <= w; j ++) {
cin >> a[i][j];
if ('O' == a[i][j]) {
os[i].push_back(j);
} else if ('I' == a[i][j]) {
is[j].push_back(i);
}
}
}
for (auto& i : os) {
sort(begin(i.second), end(i.second));
}
for (auto& i : is) {
sort(begin(i.second), end(i.second));
}
for (int i = 1; i <= h; i ++) {
for (int j = 1; j <= w; j ++) {
if ('J' == a[i][j]) {
int oc = os[i].end() - upper_bound(begin(os[i]), end(os[i]), j);
int ic = is[j].end() - upper_bound(begin(is[j]), end(is[j]), i);
r += oc * ic;
}
}
}
cout << r << '\n';
}
# |
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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
2592 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
2592 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
19 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
9 ms |
3676 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
26 ms |
5276 KB |
Output is correct |
19 |
Correct |
16 ms |
5208 KB |
Output is correct |
20 |
Correct |
13 ms |
4188 KB |
Output is correct |
21 |
Correct |
26 ms |
5272 KB |
Output is correct |
22 |
Correct |
17 ms |
4700 KB |
Output is correct |
23 |
Correct |
13 ms |
4324 KB |
Output is correct |
24 |
Correct |
28 ms |
4696 KB |
Output is correct |
25 |
Correct |
13 ms |
5212 KB |
Output is correct |
26 |
Correct |
13 ms |
4136 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
2592 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
19 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
9 ms |
3676 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
26 ms |
5276 KB |
Output is correct |
19 |
Correct |
16 ms |
5208 KB |
Output is correct |
20 |
Correct |
13 ms |
4188 KB |
Output is correct |
21 |
Correct |
26 ms |
5272 KB |
Output is correct |
22 |
Correct |
17 ms |
4700 KB |
Output is correct |
23 |
Correct |
13 ms |
4324 KB |
Output is correct |
24 |
Correct |
28 ms |
4696 KB |
Output is correct |
25 |
Correct |
13 ms |
5212 KB |
Output is correct |
26 |
Correct |
13 ms |
4136 KB |
Output is correct |
27 |
Execution timed out |
1075 ms |
77796 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |