Submission #996928

# Submission time Handle Problem Language Result Execution time Memory
996928 2024-06-11T12:43:51 Z giorgi_pkhaladze JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
0 ms 600 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second
using namespace std;
vector <int> j,o,i;
int n,m,k,ans,a[200001],ph[200001],sh[200001];
string s;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	cin>>s;
	s=' '+s;
	if(m*3>n){cout<<-1; return 0; }
	for(k=1; k<=n; k++){
		ph[k]=ph[k-1];
		if(s[k]=='J')ph[k]++,j.pb(k);
		if(s[k]=='I')i.pb(k);
		if(s[k]=='O')o.pb(k);
	}
	for(k=n; k>0; k--){
	    sh[k]=sh[k+1];
		if(s[k]=='I')sh[k]++;
	}
	if(j.size()<m && o.size()<m && i.size()<n){
		cout<<-1; return 0;
	}
	//cout<<"SABA"; return 0;
	int ans=100000000;
	for(k=0; k<=o.size()-m; k++){
	    //cout<<sh[o[k]]<<" "<<ph[o[k]]<<'\n';
		if(sh[o[k]]<m)break;
		if(ph[o[k]]>m)break;
		int pos1=lower_bound(j.begin(),j.end(),o[k])-1-j.begin();
		int pos2=lower_bound(i.begin(),i.end(),o[k])-i.begin();
		int sz=j[pos1]-j[pos1-m+1]-m; 
		if(pos1<m-1 || pos2>(int)i.size()-m)continue;
		//cout<<pos1+1<<" "<<pos2+1<<'\n';
		sz++; //cout<<sz<<'\n';
		sz+=i[pos2+m-1]-i[pos2]-m+1; //cout<<sz<<'\n';
		sz+=o[k+m-1]-o[k]-m+1; ans=min(ans,sz); //cout<<ans<<'\n'; 

	}
	if(ans==100000000)cout<<-1;
	else cout<<ans;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:30:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |  if(j.size()<m && o.size()<m && i.size()<n){
      |     ~~~~~~~~^~
ho_t2.cpp:30:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |  if(j.size()<m && o.size()<m && i.size()<n){
      |                   ~~~~~~~~^~
ho_t2.cpp:30:41: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |  if(j.size()<m && o.size()<m && i.size()<n){
      |                                 ~~~~~~~~^~
ho_t2.cpp:35:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(k=0; k<=o.size()-m; k++){
      |           ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -