Submission #649590

# Submission time Handle Problem Language Result Execution time Memory
649590 2022-10-10T22:25:59 Z inwbear JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
7 ms 2000 KB
#include<bits/stdc++.h>
using namespace std;
int n,k,ans=INT_MAX,mid_size;
char c[200005];
vector<int>pos[3];
int cur[3];
int main(){
  scanf("%d %d",&n,&k);
  scanf("%s",c+1);
  //hashing the position of each character
  for(int i=1;i<=n;i++){
    if(c[i] == 'J')pos[0].push_back(i);
    else if(c[i] == 'O')pos[1].push_back(i);
    else pos[2].push_back(i);
  }
  //brute-force for all possible x
  for(int i = 1; i <= n; i++){
    while(cur[0] < pos[0].size()){
      if(pos[0][cur[0]] >= i)break;
      cur[0]++;
    }
    if(cur[0]+k-1 >= pos[0].size())break;
    while(cur[1] < pos[1].size()){
      if(pos[1][cur[1]] >= pos[0][cur[0]+k-1])break;
      cur[1]++;
    }
    if(cur[1]+k-1 >= pos[1].size())break;
    while(cur[2] < pos[2].size()){
      if(pos[2][cur[2]] >= pos[1][cur[1]+k-1])break;
      cur[2]++;
    }
    if(cur[2]+k-1 >= pos[2].size())break;
    mid_size = pos[2][cur[2]+k-1] - i + 1;
    ans=min(ans, mid_size - (3 * k));
  }
  if(ans==INT_MAX)printf("-1");
  else printf("%d",ans);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(cur[0] < pos[0].size()){
      |           ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     if(cur[0]+k-1 >= pos[0].size())break;
      |        ~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while(cur[1] < pos[1].size()){
      |           ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if(cur[1]+k-1 >= pos[1].size())break;
      |        ~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while(cur[2] < pos[2].size()){
      |           ~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     if(cur[2]+k-1 >= pos[2].size())break;
      |        ~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d %d",&n,&k);
      |   ~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%s",c+1);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 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 212 KB Output is correct
18 Correct 0 ms 212 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 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 312 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 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 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 212 KB Output is correct
18 Correct 0 ms 212 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 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 312 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 6 ms 1488 KB Output is correct
37 Correct 7 ms 1816 KB Output is correct
38 Correct 7 ms 1964 KB Output is correct
39 Correct 7 ms 1976 KB Output is correct
40 Correct 4 ms 1832 KB Output is correct
41 Correct 5 ms 1872 KB Output is correct
42 Correct 6 ms 1856 KB Output is correct
43 Correct 3 ms 1220 KB Output is correct
44 Correct 3 ms 1348 KB Output is correct
45 Correct 4 ms 2000 KB Output is correct
46 Correct 4 ms 1868 KB Output is correct
47 Correct 4 ms 1856 KB Output is correct
48 Correct 4 ms 2000 KB Output is correct
49 Correct 3 ms 1316 KB Output is correct
50 Correct 5 ms 1872 KB Output is correct
51 Correct 4 ms 1876 KB Output is correct
52 Correct 4 ms 1472 KB Output is correct
53 Correct 4 ms 1796 KB Output is correct
54 Correct 3 ms 2000 KB Output is correct
55 Correct 3 ms 2000 KB Output is correct
56 Correct 2 ms 1980 KB Output is correct