답안 #956359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956359 2024-04-01T17:14:18 Z Dennis_Jason JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
7 ms 5336 KB
#include <bits/stdc++.h>
#define NMAX 500001
#define pb push_back
#define MOD 1000000007
#define nl '\n'
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
int n,k,ans=INF;
string s;
int vj[NMAX],vo[NMAX],vi[NMAX],li,lo,lj;
int J='J'-'0';
int O='O'-'0';
int I='I'-'0';

signed main() {
    cin>>n>>k;

    cin>>s;
    for(int i=0;i<n;++i)
    {
        if(s[i]=='I')
            vi[++li]=i;
        if(s[i]=='J')
            vj[++lj]=i;
        if(s[i]=='O')
            vo[++lo]=i;
       // cout<<s[i];
    }

    int pj=1,po=1,pi=1;
    while(pj+k-1<=lj&& po+k-1<=lo&& pi+k-1<=li)
    {
       while(po+k-1<=lo&& vo[po]<=vj[pj+k-1])
           po++;
       if(po+k-1<=lo)
           while(pi+k-1<=li && vi[pi]<=vo[po+k-1])
               pi++;
       if(pj+k-1<=lj && po+k-1<=lo && pi+k-1<=li)
       {
           ans=min(ans,(vi[pi+k-1]-vj[pj]+1)-3*k);
       }
        pj++;
    }
    if(ans==INF)
        cout<<-1;
    else
        cout<<ans;


    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4544 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4544 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4456 KB Output is correct
25 Correct 1 ms 4708 KB Output is correct
26 Correct 1 ms 4456 KB Output is correct
27 Correct 1 ms 4452 KB Output is correct
28 Correct 1 ms 4448 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4448 KB Output is correct
31 Correct 1 ms 4452 KB Output is correct
32 Correct 1 ms 4456 KB Output is correct
33 Correct 1 ms 4456 KB Output is correct
34 Correct 1 ms 4456 KB Output is correct
35 Correct 1 ms 4456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4544 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4544 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4456 KB Output is correct
25 Correct 1 ms 4708 KB Output is correct
26 Correct 1 ms 4456 KB Output is correct
27 Correct 1 ms 4452 KB Output is correct
28 Correct 1 ms 4448 KB Output is correct
29 Correct 1 ms 4448 KB Output is correct
30 Correct 1 ms 4448 KB Output is correct
31 Correct 1 ms 4452 KB Output is correct
32 Correct 1 ms 4456 KB Output is correct
33 Correct 1 ms 4456 KB Output is correct
34 Correct 1 ms 4456 KB Output is correct
35 Correct 1 ms 4456 KB Output is correct
36 Correct 6 ms 5116 KB Output is correct
37 Correct 6 ms 5116 KB Output is correct
38 Correct 6 ms 5108 KB Output is correct
39 Correct 6 ms 5112 KB Output is correct
40 Correct 7 ms 5112 KB Output is correct
41 Correct 6 ms 5336 KB Output is correct
42 Correct 6 ms 5100 KB Output is correct
43 Correct 4 ms 4980 KB Output is correct
44 Correct 5 ms 5104 KB Output is correct
45 Correct 5 ms 5104 KB Output is correct
46 Correct 5 ms 5104 KB Output is correct
47 Correct 5 ms 5104 KB Output is correct
48 Correct 5 ms 5104 KB Output is correct
49 Correct 4 ms 5104 KB Output is correct
50 Correct 5 ms 5104 KB Output is correct
51 Correct 5 ms 5212 KB Output is correct
52 Correct 5 ms 5104 KB Output is correct
53 Correct 5 ms 5104 KB Output is correct
54 Correct 4 ms 5100 KB Output is correct
55 Correct 4 ms 5100 KB Output is correct
56 Correct 4 ms 5104 KB Output is correct