Submission #702082

# Submission time Handle Problem Language Result Execution time Memory
702082 2023-02-22T17:22:49 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
685 ms 2876 KB
//~ #pragma GCC optimize("Ofast,unroll-loops")
//~ #pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fi first
#define se second
#define space " "
#define endl "\n"
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define md 1000000007
#define inf 1000000000
#define li 500005
#define lo long long
using namespace std;
int T,Q,n,m,k,a[li],mn=inf;
string s,t;
vector<int> v[10];
map<char,int> harf;
vector<pair<int,int> > vv[10];
int main(){
	fast;
	cin>>n>>k>>s;
	harf['J']=1;
	harf['O']=2;
	harf['I']=3;
	for(int i=0;i<n;i++){
		int son=i+1;
		while(son<n && s[son]==s[i]) son++;
		son--;
		v[harf[s[i]]].pb(i);
		vv[harf[s[i]]].pb(mp(i,son));
		i=son;
	}
	//~ for(int i=1;i<=3;i++){
		//~ for(int j=0;j<(int)v[i].size();j++){
			//~ printf("NICE %d %d %d\n",i,j,v[i][j]);
		//~ }
	//~ }
	int sum=0,son=0;
	for(int i=0;i<(int)vv[2].size();i++){
		while(son<(int)vv[2].size() && sum<k){
			sum+=vv[2][son].se-vv[2][son].fi+1;
			son++;
		}
		if(sum<k) break;
		//~ printf("DEBUG %d\n",son);
		//~ printf("ABUBA %d\n",vv[2][i].fi);
		auto itr=upper_bound(v[1].begin(),v[1].end(),vv[2][i].fi);
		if(itr==v[1].begin()){sum-=vv[2][i].se-vv[2][i].fi+1; continue;}
		itr--;
		int ind1=itr-v[1].begin();
		//~ printf("ABUBEEE %d\n",ind1);
		auto itr2=upper_bound(v[3].begin(),v[3].end(),vv[2][son-1].se);
		if(itr2==v[3].end()){sum-=vv[2][i].se-vv[2][i].fi+1; continue;}
		int ind2=itr2-v[3].begin();
		//~ printf("ABUBEEE %d %d\n",ind1,ind2);
		int cev=vv[3][ind2].fi-vv[1][ind1].se-1-k;
		int sayi1=0;
		for(int j=ind1;j>=0;j--){
			sayi1+=vv[1][j].se-vv[1][j].fi+1;
			if(j!=ind1) cev+=vv[1][j+1].fi-vv[1][j].se-1;
			if(sayi1>=k) break;
		}
		int sayi2=0;
		for(int j=ind2;j<(int)vv[3].size();j++){
			sayi2+=vv[3][j].se-vv[3][j].fi+1;
			if(j!=ind2) cev+=vv[3][j].fi-vv[3][j-1].se-1;
			if(sayi2>=k) break;
		}
		if(sayi1<k || sayi2<k){sum-=vv[2][i].se-vv[2][i].fi+1; continue;}
		mn=min(mn,cev);
		sum-=vv[2][i].se-vv[2][i].fi+1;
	}
	if(mn==inf) cout<<"-1\n";
	else cout<<mn<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 0 ms 328 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 9 ms 2764 KB Output is correct
37 Correct 10 ms 2640 KB Output is correct
38 Correct 9 ms 2500 KB Output is correct
39 Correct 258 ms 2504 KB Output is correct
40 Correct 654 ms 2624 KB Output is correct
41 Correct 438 ms 2736 KB Output is correct
42 Correct 65 ms 2600 KB Output is correct
43 Correct 267 ms 1888 KB Output is correct
44 Correct 415 ms 2380 KB Output is correct
45 Correct 679 ms 2876 KB Output is correct
46 Correct 685 ms 2680 KB Output is correct
47 Correct 683 ms 2588 KB Output is correct
48 Correct 683 ms 2676 KB Output is correct
49 Correct 299 ms 1976 KB Output is correct
50 Correct 677 ms 2512 KB Output is correct
51 Correct 685 ms 2728 KB Output is correct
52 Correct 40 ms 2380 KB Output is correct
53 Correct 64 ms 2504 KB Output is correct
54 Correct 1 ms 848 KB Output is correct
55 Correct 1 ms 852 KB Output is correct
56 Correct 1 ms 852 KB Output is correct