# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
672110 |
2022-12-14T19:16:34 Z |
sofija6 |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
11 ms |
3660 KB |
#include <bits/stdc++.h>
#define ll long long
#define MAXN 200010
#define llinf 1000000000
using namespace std;
vector<ll> posj,poso,posi,mino,mini;
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,k;
string s;
cin >> n >> k >> s;
for (ll i=0;i<n;i++)
{
if (s[i]=='J')
posj.push_back(i);
else if (s[i]=='O')
poso.push_back(i);
else
posi.push_back(i);
}
mino.resize(poso.size()+1,llinf);
mini.resize(posi.size()+1,llinf);
for (ll i=posi.size()-1;i>=0;i--)
{
if (i+k-1>=posi.size())
continue;
if (i+1<posi.size())
mini[i]=min(mini[i+1]+posi[i+1]-posi[i],posi[i+k-1]-posi[i]-k+1);
else
mini[i]=posi[i+k-1]-posi[i]-k+1;
}
for (ll i=poso.size()-1;i>=0;i--)
{
if (i+k-1>=poso.size())
continue;
auto it=lower_bound(posi.begin(),posi.end(),poso[i+k-1]);
if (it==posi.end())
continue;
if (i+1<poso.size())
mino[i]=min(mino[i+1]+poso[i+1]-poso[i],mini[it-posi.begin()]+posi[it-posi.begin()]-poso[i]-k);
else
mino[i]=mini[it-posi.begin()]+posi[it-posi.begin()]-poso[i]-k;
}
ll ans=llinf;
for (ll i=0;i+k-1<posj.size();i++)
{
auto it=lower_bound(poso.begin(),poso.end(),posj[i+k-1]);
if (it==poso.end())
break;
ans=min(ans,mino[it-poso.begin()]+poso[it-poso.begin()]-posj[i]-k);
}
cout << (ans>=llinf?-1 : ans);
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if (i+k-1>=posi.size())
| ~~~~~^~~~~~~~~~~~~
ho_t2.cpp:28:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (i+1<posi.size())
| ~~~^~~~~~~~~~~~
ho_t2.cpp:35:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (i+k-1>=poso.size())
| ~~~~~^~~~~~~~~~~~~
ho_t2.cpp:40:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if (i+1<poso.size())
| ~~~^~~~~~~~~~~~
ho_t2.cpp:46:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (ll i=0;i+k-1<posj.size();i++)
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
248 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
320 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
316 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
248 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
320 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
316 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
9 ms |
3388 KB |
Output is correct |
37 |
Correct |
11 ms |
3392 KB |
Output is correct |
38 |
Correct |
10 ms |
3368 KB |
Output is correct |
39 |
Correct |
10 ms |
3196 KB |
Output is correct |
40 |
Correct |
9 ms |
3532 KB |
Output is correct |
41 |
Correct |
10 ms |
3520 KB |
Output is correct |
42 |
Correct |
10 ms |
3392 KB |
Output is correct |
43 |
Correct |
6 ms |
2460 KB |
Output is correct |
44 |
Correct |
6 ms |
2888 KB |
Output is correct |
45 |
Correct |
8 ms |
3452 KB |
Output is correct |
46 |
Correct |
8 ms |
3452 KB |
Output is correct |
47 |
Correct |
8 ms |
3556 KB |
Output is correct |
48 |
Correct |
8 ms |
3492 KB |
Output is correct |
49 |
Correct |
5 ms |
2496 KB |
Output is correct |
50 |
Correct |
8 ms |
3492 KB |
Output is correct |
51 |
Correct |
9 ms |
3660 KB |
Output is correct |
52 |
Correct |
5 ms |
3392 KB |
Output is correct |
53 |
Correct |
6 ms |
3388 KB |
Output is correct |
54 |
Correct |
5 ms |
3420 KB |
Output is correct |
55 |
Correct |
4 ms |
3420 KB |
Output is correct |
56 |
Correct |
3 ms |
3396 KB |
Output is correct |