Submission #716206

# Submission time Handle Problem Language Result Execution time Memory
716206 2023-03-29T08:49:10 Z hello_there_123 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
15 ms 3036 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int>pos[3];
main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	for(int i=1;i<=n;i++){
		if(s[i-1] == 'J') pos[0].push_back(i);
		if(s[i-1] == 'O') pos[1].push_back(i);
		if(s[i-1] == 'I') pos[2].push_back(i);
	}
	int mini = 1e10;
	if(pos[0].size()<k-1){
		cout<<"-1";
		return 0;
	}
	for(int i=k-1;i<pos[0].size();i++){
		int x = lower_bound(pos[1].begin(),pos[1].end(),pos[0][i])-pos[1].begin();

		int x2 = pos[1][x+k-1];
		if(x+k-1>=pos[1].size()){
			break;
		}
		int y = lower_bound(pos[2].begin(),pos[2].end(),x2)-pos[2].begin();

		if(y+k-1>=pos[2].size()){
			break;
		}
		int p = pos[2][y+k-1]-pos[0][i-k+1]+1;
		mini = min(mini,p);
	}
	if(mini>1e9) cout<<"-1";
	else cout<<mini-k*3;
}

Compilation message

ho_t2.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    5 | main(){
      | ^~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:16:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   16 |  if(pos[0].size()<k-1){
      |     ~~~~~~~~~~~~~^~~~
ho_t2.cpp:20:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i=k-1;i<pos[0].size();i++){
      |                ~^~~~~~~~~~~~~~
ho_t2.cpp:24:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   if(x+k-1>=pos[1].size()){
      |      ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:29:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if(y+k-1>=pos[2].size()){
      |      ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 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 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 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 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 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 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 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 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 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 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 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 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 12 ms 2120 KB Output is correct
37 Correct 14 ms 2644 KB Output is correct
38 Correct 14 ms 2612 KB Output is correct
39 Correct 12 ms 2628 KB Output is correct
40 Correct 11 ms 2660 KB Output is correct
41 Correct 15 ms 2784 KB Output is correct
42 Correct 14 ms 2664 KB Output is correct
43 Correct 5 ms 1624 KB Output is correct
44 Correct 6 ms 1736 KB Output is correct
45 Correct 8 ms 2708 KB Output is correct
46 Correct 8 ms 2704 KB Output is correct
47 Correct 8 ms 2768 KB Output is correct
48 Correct 9 ms 2764 KB Output is correct
49 Correct 5 ms 1728 KB Output is correct
50 Correct 8 ms 2740 KB Output is correct
51 Correct 8 ms 2768 KB Output is correct
52 Correct 8 ms 2244 KB Output is correct
53 Correct 8 ms 2652 KB Output is correct
54 Correct 8 ms 3036 KB Output is correct
55 Correct 7 ms 3036 KB Output is correct
56 Correct 8 ms 3036 KB Output is correct