답안 #581603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581603 2022-06-22T20:45:48 Z HeyYouNotYouYou JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
38 ms 5520 KB
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 100001,INF=1e12;
int32_t main()
{
  //freopen("abc.in", "r", stdin);
  int n , k ;
  cin >> n >> k;
  string s;
  cin>>s;
  vector<int>J(n),I(n),O(n);
  for(int i = 0 ; i < s.size() ; i ++){
    if(s[i]=='J') J[i]++;
    if(s[i]=='O') O[i]++;
    if(s[i]=='I') I[i]++;
    if(i) J[i]+=J[i-1],I[i]+=I[i-1],O[i]+=O[i-1];
  }
  int ans=INT_MAX;
  for(int i = 0 ; i < n ; i ++)
  {
    int start = i ;
    int cons=J[i]; if(s[i]=='J') cons--;
    auto it = lower_bound(J.begin(),J.end(),cons+k);
    if(it==J.end()) break;
    int ptr2 = it-J.begin();
    it = lower_bound(O.begin(),O.end(),O[ptr2]+k);
    if(it==O.end()) break;
    int ptr3 = it-O.begin();
    it = lower_bound(I.begin(),I.end(),I[ptr3]+k);
    if(it==I.end()) break;
    int ptr4 = it-I.begin();
    ans=min(ans,(ptr4-start+1)-(k*3));
  }
  if(ans==INT_MAX) ans=-1;
  cout<<ans;
}

Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:14:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for(int i = 0 ; i < s.size() ; i ++){
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 260 KB Output is correct
10 Correct 1 ms 296 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 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 260 KB Output is correct
10 Correct 1 ms 296 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 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 296 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 300 KB Output is correct
23 Correct 1 ms 304 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 296 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 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 260 KB Output is correct
10 Correct 1 ms 296 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 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 296 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 300 KB Output is correct
23 Correct 1 ms 304 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 296 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 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 30 ms 5188 KB Output is correct
37 Correct 31 ms 5476 KB Output is correct
38 Correct 38 ms 5520 KB Output is correct
39 Correct 29 ms 5456 KB Output is correct
40 Correct 13 ms 5476 KB Output is correct
41 Correct 22 ms 5448 KB Output is correct
42 Correct 30 ms 5476 KB Output is correct
43 Correct 6 ms 3524 KB Output is correct
44 Correct 7 ms 4324 KB Output is correct
45 Correct 9 ms 5448 KB Output is correct
46 Correct 8 ms 5476 KB Output is correct
47 Correct 8 ms 5476 KB Output is correct
48 Correct 9 ms 5476 KB Output is correct
49 Correct 6 ms 3852 KB Output is correct
50 Correct 9 ms 5476 KB Output is correct
51 Correct 11 ms 5448 KB Output is correct
52 Correct 9 ms 5316 KB Output is correct
53 Correct 9 ms 5444 KB Output is correct
54 Correct 14 ms 5476 KB Output is correct
55 Correct 10 ms 5448 KB Output is correct
56 Correct 8 ms 5476 KB Output is correct