# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
781503 |
2023-07-13T07:02:07 Z |
vjudge1 |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
0 ms |
212 KB |
#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long
#define pb push_back
#define N 2000005
int owo[N];
int main(){
lalala;
int n,k;cin>>n>>k;
string str;cin>>str;
vector<int>J,I,bir,iki;
for(int i=0;i<n;i++){
owo[i+1]+=owo[i];
if(str[i]=='O')owo[i+1]++;
if(str[i]=='J')J.pb(i+1);
if(str[i]=='I')I.pb(i+1);
}
if(J.size()<k||I.size()<k){
cout<<-1<<endl;
return 0;
}
int why=0;
for(int i=1;i<k;i++){
why+=J[i]-J[i-1]-1;
}
bir.pb(why);
for(int i=1;i<J.size()-k+1;i++){
if(k==1){
bir.pb(0);
continue;
}
why-=(J[i]-J[i-1]-1);
why+=(J[i+k-1]-J[i+k-2]-1);
bir.pb(why);
}
why=0;
for(int i=1;i<k;i++){
why+=I[i]-I[i-1]-1;
}
iki.pb(why);
for(int i=1;i<I.size()-k+1;i++){
if(k==1){
iki.pb(0);
continue;
}
why-=(I[i]-I[i-1]-1);
why+=(I[i+k-1]-I[i+k-2]-1);
iki.pb(why);
}
int ans=1000000000;
for(int i=0;i<bir.size();i++){
int yer=J[i],son=J[i+k-1];
int cur=bir[i];
int l=upper_bound(I.begin(),I.end(),son)-I.begin(), r=I.size()-1;
if(l==I.size())continue;
while(l<r){
int mid=(l+r)/2;
int m=I[mid];
if(owo[m]-owo[son]>=k){
r=mid;
}
else l=mid+1;
}
if(l>=iki.size())continue;
cur+=iki[l];
cur+=I[l]-son-1-k;
//cout<<yer<<" "<<son<<" "<<l<<" "<<I[l]<<" "<<i<<" "<<i+k-1<<endl;
//cout<<bir[i]<<" "<<iki[l]<<" "<<I[l]-son-1-k<<" "<<cur<<endl;
ans=min(ans,cur);
}
if(ans==1000000000)ans=-1;
cout<<ans<<endl;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:20:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | if(J.size()<k||I.size()<k){
| ~~~~~~~~^~
ho_t2.cpp:20:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
20 | if(J.size()<k||I.size()<k){
| ~~~~~~~~^~
ho_t2.cpp:29:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=1;i<J.size()-k+1;i++){
| ~^~~~~~~~~~~~~
ho_t2.cpp:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=1;i<I.size()-k+1;i++){
| ~^~~~~~~~~~~~~
ho_t2.cpp:54:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int i=0;i<bir.size();i++){
| ~^~~~~~~~~~~
ho_t2.cpp:58:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | if(l==I.size())continue;
| ~^~~~~~~~~~
ho_t2.cpp:67:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | if(l>=iki.size())continue;
| ~^~~~~~~~~~~~
ho_t2.cpp:55:7: warning: unused variable 'yer' [-Wunused-variable]
55 | int yer=J[i],son=J[i+k-1];
| ^~~
# |
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 |
- |