Submission #217106

#TimeUsernameProblemLanguageResultExecution timeMemory
217106jamielimJJOOII 2 (JOI20_ho_t2)C++14
0 / 100
5 ms512 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	char str[n+5];
	scanf("%s",str);
	int joi[3];memset(joi,0,sizeof(joi));
	int ans=0;
	for(int i=0;i<n;i++){
		if(joi[0]<k){
			if(str[i]=='J'){
				joi[0]++;
			}else{
				if(joi[0]==0)continue;
				ans++;
			}
		}else if(joi[1]<k){
			if(str[i]=='O'){
				joi[1]++;
			}else{
				ans++;
			}
		}else if(joi[2]<k){
			if(str[i]=='I'){
				joi[2]++;
			}else{
				ans++;
			}
		}else break;
	}
	if(joi[0]!=k||joi[1]!=k||joi[2]!=k)printf("-1");
	else printf("%d",ans);
}

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:6:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s",str);
  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...