#include<bits/stdc++.h>
using namespace std ;
//type 0 -> orb
//type 1 -> ingot
const int maxN = 3e3 + 5 ;
int SIZ[maxN][2] ;
vector<pair<int,int> > jewels ;
vector<int> mine[maxN][2] ;
long long bs(int low , int high , int type , int val , int par)
{
if(high<low) return 0 ;
int N = high + 1 ;
while(low<high)
{
int mid = (low+high)/2 ;
if(mine[par][type][mid]>val) high = mid ;
else low = mid + 1 ;
}
if(mine[par][type][low]<=val) return 0 ;
else return N - low ;
}
int main()
{
char s[maxN][maxN] ;
int H , W ;
long long ans = 0 ;
scanf("%d%d",&H,&W) ;
for(int i = 0 ; i < H ; ++i)
{
for(int j = 0 ; j < W ; ++j)
{
scanf(" %c",&s[i][j]) ;
}
}
for(int i = 0 ; i < H ; ++i)
{
for(int j = 0 ; j < W ; ++j)
{
if(s[i][j]=='J') jewels.push_back({i,j}) ;
else if(s[i][j]=='O') mine[i][0].push_back(j) ;
else mine[j][1].push_back(i) ;
}
}
for(int i = 0 ; i < maxN ; ++i)
{
if(!mine[i][0].empty())
{
sort(mine[i][0].begin(),mine[i][0].end()) ;
SIZ[i][0] = mine[i][0].size() ;
}
if(!mine[i][1].empty())
{
sort(mine[i][1].begin(),mine[i][1].end()) ;
SIZ[i][1] = mine[i][1].size() ;
}
}
for(pair<int,int> p : jewels)
{
int i = p.first , j = p.second ;
ans += (bs(0,SIZ[i][0]-1,0,j,i)*bs(0,SIZ[j][1]-1,1,i,j)) ;
}
printf("%lld\n",ans) ;
return 0 ;
}
Compilation message
joi2019_ho_t1.cpp: In function 'int main()':
joi2019_ho_t1.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
34 | scanf("%d%d",&H,&W) ;
| ~~~~~^~~~~~~~~~~~~~
joi2019_ho_t1.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
39 | scanf(" %c",&s[i][j]) ;
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
876 KB |
Output is correct |
6 |
Correct |
1 ms |
876 KB |
Output is correct |
7 |
Correct |
1 ms |
748 KB |
Output is correct |
8 |
Correct |
2 ms |
876 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
876 KB |
Output is correct |
6 |
Correct |
1 ms |
876 KB |
Output is correct |
7 |
Correct |
1 ms |
748 KB |
Output is correct |
8 |
Correct |
2 ms |
876 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
14 |
Correct |
23 ms |
3300 KB |
Output is correct |
15 |
Correct |
2 ms |
1772 KB |
Output is correct |
16 |
Correct |
12 ms |
2152 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
31 ms |
3940 KB |
Output is correct |
19 |
Correct |
20 ms |
3304 KB |
Output is correct |
20 |
Correct |
21 ms |
3300 KB |
Output is correct |
21 |
Correct |
30 ms |
3940 KB |
Output is correct |
22 |
Correct |
24 ms |
3704 KB |
Output is correct |
23 |
Correct |
21 ms |
3300 KB |
Output is correct |
24 |
Correct |
30 ms |
3556 KB |
Output is correct |
25 |
Correct |
20 ms |
3304 KB |
Output is correct |
26 |
Correct |
24 ms |
3300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
876 KB |
Output is correct |
6 |
Correct |
1 ms |
876 KB |
Output is correct |
7 |
Correct |
1 ms |
748 KB |
Output is correct |
8 |
Correct |
2 ms |
876 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
2 ms |
748 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
14 |
Correct |
23 ms |
3300 KB |
Output is correct |
15 |
Correct |
2 ms |
1772 KB |
Output is correct |
16 |
Correct |
12 ms |
2152 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
31 ms |
3940 KB |
Output is correct |
19 |
Correct |
20 ms |
3304 KB |
Output is correct |
20 |
Correct |
21 ms |
3300 KB |
Output is correct |
21 |
Correct |
30 ms |
3940 KB |
Output is correct |
22 |
Correct |
24 ms |
3704 KB |
Output is correct |
23 |
Correct |
21 ms |
3300 KB |
Output is correct |
24 |
Correct |
30 ms |
3556 KB |
Output is correct |
25 |
Correct |
20 ms |
3304 KB |
Output is correct |
26 |
Correct |
24 ms |
3300 KB |
Output is correct |
27 |
Execution timed out |
1096 ms |
64164 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |