# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
830671 |
2023-08-19T09:09:03 Z |
vjudge1 |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
0 ms |
212 KB |
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL suff[200005],suff2[200005],suff3[200005];
int main()
{
LL n,k;
scanf("%lld %lld",&n,&k);
vector<LL>j,i;
string s;
cin>>s;
s=" "+s;
for(LL a=1;a<=n;a++)
{
if(s[a]=='J')
{
// printf("MASUK\n");
suff[a]++;
j.push_back(a);
}
else if(s[a]=='O')suff2[a]++;
else
{
i.push_back(a);
suff3[a]++;
}
}
for(LL a=n-1;a>=1;a--)
{
suff[a]+=suff[a+1];
suff2[a]+=suff2[a+1];
suff3[a]+=suff3[a+1];
}
LL left=-1;
for(LL a=k-1;a<j.size();a++)
{
// printf("j[%lld]=%lld\n",a,j[a]);
if(suff2[j[a]]>=k && suff3[j[a]]>=k)left=a;
else break;
}
// printf("left=%lld\n",left);
if(left==-1){
printf("-1\n");
exit(0);
}
reverse(i.begin(),i.end());
LL right=-1;
for(LL a=k-1;a<i.size();a++)
{
// printf("%lld-%lld \n",suff2[j[left]],suff2[i[a]]);
if(suff2[j[left]]-suff2[i[a]]>=k )right=a;
else break;
}
// printf("right=%lld\n",right);
if(right==-1)
{
printf("-1\n");
exit(0);
}
LL l=j[left-k+1],r=i[right-k+1];
// printf("r=%lld l=%lld\n",r,l);
printf("%lld\n",r-l+1-3*k);
// ambil 2 j yang paling kanan dan bisa membentuk JJOOII
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:36: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]
36 | for(LL a=k-1;a<j.size();a++)
| ~^~~~~~~~~
ho_t2.cpp:49: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]
49 | for(LL a=k-1;a<i.size();a++)
| ~^~~~~~~~~
ho_t2.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%lld %lld",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |