Submission #655411

# Submission time Handle Problem Language Result Execution time Memory
655411 2022-11-04T09:45:37 Z Warinchai JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
vector<int>v[3];
int n,k;
string s;
int main(){
	cin>>n>>k;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='J'){
			v[0].push_back(i);
		}else if(s[i]=='O'){
			v[1].push_back(i);
		}else{
			v[2].push_back(i);
		}
	}
	int x=-1;
	int min=INT_MAX;
	for(int i=k-1;i<v[0].size();i++){
		int comp=v[0][i];
		int st=0,en=v[1].size()-1;
		while(st<=en){
			int mid=(st+en)/2;
			if(v[1][mid]>comp){
				en=mid-1;
				x=mid;
			}else{
				st=mid+1;
			}
		}
		if(x==-1){
			break;
		}
		x+=k-1;
		if(x>=v[1].size()){
			break;
		}
		int y=0;
		comp=v[1][x];
		st=0,en=v[2].size()-1;
		while(st<=en){
			int mid=(st+en)/2;
			if(v[2][mid]>comp){
				en=mid-1;
				x=mid;
				y=1;
			}else{
				st=mid+1;
			}
		}
		if(y!=1){
			break;
		}
		x+=k-1;
		if(x>=v[2].size()){
			break;
		}
		int ans=v[2][x]-(v[0][i-k+1])+1-3*k;
		if(ans<min){
			//cout<<v[2][x]<<" "<<(v[0][i-k+1])<<endl;
			min=ans;
		}
	}
	if(min!=INT_MAX){
		cout<<min;
	}else{
		cout<<"-1";
	}
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=k-1;i<v[0].size();i++){
      |                ~^~~~~~~~~~~~
ho_t2.cpp:36:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   if(x>=v[1].size()){
      |      ~^~~~~~~~~~~~~
ho_t2.cpp:56:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   if(x>=v[2].size()){
      |      ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -