Submission #524551

# Submission time Handle Problem Language Result Execution time Memory
524551 2022-02-09T13:23:09 Z mosiashvililuka JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
25 ms 2000 KB
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,K,pas;
vector <int> v[5];
string s;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>K;pas=a+3;
	cin>>s;s.insert(0,"0");
	for(i=1; i<=a; i++){
		if(s[i]=='J') v[1].push_back(i);
		if(s[i]=='O') v[2].push_back(i);
		if(s[i]=='I') v[3].push_back(i);
	}
	for(i=1; i<=a; i++){
		c=lower_bound(v[1].begin(),v[1].end(),i)-v[1].begin();
		if(v[1].size()<=c+K-1) continue;
		c=c+K-1;
		d=lower_bound(v[2].begin(),v[2].end(),v[1][c]+1)-v[2].begin();
		if(v[2].size()<=d+K-1) continue;
		d=d+K-1;
		e=lower_bound(v[3].begin(),v[3].end(),v[2][d]+1)-v[3].begin();
		if(v[3].size()<=e+K-1) continue;
		e=e+K-1;
		zx=v[3][e];
		pas=min(pas,zx-i+1);
	}
	
	
	
	if(pas==a+3){
		cout<<-1;
	}else{
		cout<<pas-3*K;
	}
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:17:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |   if(v[1].size()<=c+K-1) continue;
      |      ~~~~~~~~~~~^~~~~~~
ho_t2.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |   if(v[2].size()<=d+K-1) continue;
      |      ~~~~~~~~~~~^~~~~~~
ho_t2.cpp:23:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |   if(v[3].size()<=e+K-1) continue;
      |      ~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 288 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 308 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 312 KB Output is correct
29 Correct 1 ms 288 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 308 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 22 ms 1600 KB Output is correct
37 Correct 24 ms 1808 KB Output is correct
38 Correct 25 ms 1948 KB Output is correct
39 Correct 25 ms 1964 KB Output is correct
40 Correct 19 ms 2000 KB Output is correct
41 Correct 22 ms 1940 KB Output is correct
42 Correct 23 ms 1816 KB Output is correct
43 Correct 11 ms 1260 KB Output is correct
44 Correct 14 ms 1512 KB Output is correct
45 Correct 18 ms 1992 KB Output is correct
46 Correct 18 ms 1964 KB Output is correct
47 Correct 17 ms 2000 KB Output is correct
48 Correct 17 ms 1992 KB Output is correct
49 Correct 11 ms 1328 KB Output is correct
50 Correct 17 ms 1984 KB Output is correct
51 Correct 18 ms 2000 KB Output is correct
52 Correct 11 ms 1480 KB Output is correct
53 Correct 11 ms 1760 KB Output is correct
54 Correct 10 ms 1996 KB Output is correct
55 Correct 11 ms 1956 KB Output is correct
56 Correct 8 ms 1996 KB Output is correct