답안 #757082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757082 2023-06-12T14:19:35 Z michao JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
24 ms 5416 KB
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2e5+5;
const int inf=(int)1e18+9;
int pref[MAX][3];
char s[MAX];
int ans=inf;
int getnum(char x){
  if (x=='J')return 0;
  if (x=='O')return 1;
  if (x=='I')return 2;
  assert(false);
  return -1;
}
int n,k;

int ile(int l,int r,int id){
  return pref[r][id]-pref[l-1][id];
}

int check(int lefty){
  int l=lefty;
  for (int i=0;i<3;i++){
    if (l>n)return inf;
    if (ile(l,n,i)<k)return inf;
    int ip=l-1,ik=n;
    while (ip+1<ik){
      int mid=(ip+ik)>>1;
      if (ile(l,mid,i)>=k)ik=mid;
      else ip=mid;
    }
    if (i<2)
    l=ik+1;
    else l=ik;
  }
  return l-lefty+1-k*3;
}
int32_t main()
{
  BOOST;
  cin>>n>>k;
  for (int i=1;i<=n;i++)cin>>s[i];
  for (int i=1;i<=n;i++){
    for (int j=0;j<3;j++)pref[i][j]=pref[i-1][j]+(getnum(s[i])==j);
  }
  for (int i=1;i<=n;i++){
    if (s[i]=='J'){
      ans=min(ans,check(i));
    }
  }
  if (ans==inf)ans=-1;
  cout<<ans;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 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 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 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 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 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 324 KB Output is correct
22 Correct 1 ms 328 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 324 KB Output is correct
26 Correct 1 ms 324 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 324 KB Output is correct
31 Correct 1 ms 340 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 320 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 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 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 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 324 KB Output is correct
22 Correct 1 ms 328 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 324 KB Output is correct
26 Correct 1 ms 324 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 324 KB Output is correct
31 Correct 1 ms 340 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 320 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 13 ms 4948 KB Output is correct
37 Correct 13 ms 5332 KB Output is correct
38 Correct 17 ms 5324 KB Output is correct
39 Correct 24 ms 5332 KB Output is correct
40 Correct 21 ms 5392 KB Output is correct
41 Correct 20 ms 5332 KB Output is correct
42 Correct 19 ms 5332 KB Output is correct
43 Correct 8 ms 3412 KB Output is correct
44 Correct 10 ms 4272 KB Output is correct
45 Correct 13 ms 5332 KB Output is correct
46 Correct 13 ms 5364 KB Output is correct
47 Correct 12 ms 5332 KB Output is correct
48 Correct 16 ms 5416 KB Output is correct
49 Correct 12 ms 3668 KB Output is correct
50 Correct 17 ms 5388 KB Output is correct
51 Correct 18 ms 5364 KB Output is correct
52 Correct 10 ms 5204 KB Output is correct
53 Correct 9 ms 5332 KB Output is correct
54 Correct 13 ms 5332 KB Output is correct
55 Correct 10 ms 5332 KB Output is correct
56 Correct 7 ms 5332 KB Output is correct