#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int h,w;
cin >> h >> w;
vector<int> J[h], O[h],I[w];
for (int i = 0; i < h; i++)
{
string s;
cin >> s;
for (int j = 0; j < w; j++)
{
if (s[j] == 'J')
{
J[i].push_back(j);
}
else if (s[j] == 'O')
{
O[i].push_back(j);
}
else
{
I[j].push_back(i);
}
}
sort(O[i].begin(),O[i].end());
}
for(int i=0;i<w;i++)
{
sort(I[i].begin(),I[i].end());
}
long long ans=0;
for(int i=0;i<h;i++)
{
for(int j=0;j<J[i].size();j++)
{
int res=O[i].size();
int l1=0,r1=O[i].size()-1;
while(l1<=r1)
{
int m=(l1+r1)/2;
if(O[i][m]>J[i][j])
{
res=m;
r1=m-1;
}
else
{
l1=m+1;
}
}
int temp=I[J[i][j]].size();
int l=0,r=I[J[i][j]].size()-1;
while(l<=r)
{
int m=(l+r)/2;
if(I[J[i][j]][m]>i)
{
temp=m;
r=m-1;
}
else
{
l=m+1;
}
}
ans+=(O[i].size()-res)*(I[J[i][j]].size()-temp);
}
}
cout<<ans;
return 0;
}
Compilation message
joi2019_ho_t1.cpp: In function 'int main()':
joi2019_ho_t1.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int j=0;j<J[i].size();j++)
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
8 ms |
1620 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1060 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
11 ms |
2260 KB |
Output is correct |
19 |
Correct |
4 ms |
1868 KB |
Output is correct |
20 |
Correct |
4 ms |
1620 KB |
Output is correct |
21 |
Correct |
11 ms |
2260 KB |
Output is correct |
22 |
Correct |
5 ms |
1876 KB |
Output is correct |
23 |
Correct |
4 ms |
1620 KB |
Output is correct |
24 |
Correct |
11 ms |
1960 KB |
Output is correct |
25 |
Correct |
4 ms |
1876 KB |
Output is correct |
26 |
Correct |
4 ms |
1620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 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 |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
8 ms |
1620 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
1060 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
11 ms |
2260 KB |
Output is correct |
19 |
Correct |
4 ms |
1868 KB |
Output is correct |
20 |
Correct |
4 ms |
1620 KB |
Output is correct |
21 |
Correct |
11 ms |
2260 KB |
Output is correct |
22 |
Correct |
5 ms |
1876 KB |
Output is correct |
23 |
Correct |
4 ms |
1620 KB |
Output is correct |
24 |
Correct |
11 ms |
1960 KB |
Output is correct |
25 |
Correct |
4 ms |
1876 KB |
Output is correct |
26 |
Correct |
4 ms |
1620 KB |
Output is correct |
27 |
Correct |
432 ms |
48868 KB |
Output is correct |
28 |
Correct |
1 ms |
596 KB |
Output is correct |
29 |
Correct |
11 ms |
4848 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
299 ms |
38552 KB |
Output is correct |
32 |
Correct |
172 ms |
57976 KB |
Output is correct |
33 |
Correct |
211 ms |
57500 KB |
Output is correct |
34 |
Correct |
361 ms |
43452 KB |
Output is correct |
35 |
Correct |
243 ms |
59588 KB |
Output is correct |
36 |
Correct |
211 ms |
57504 KB |
Output is correct |
37 |
Correct |
502 ms |
71628 KB |
Output is correct |
38 |
Correct |
106 ms |
40012 KB |
Output is correct |
39 |
Correct |
141 ms |
46608 KB |
Output is correct |