답안 #221871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
221871 2020-04-11T11:05:30 Z davooddkareshki JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
23 ms 9540 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define F first
#define S second
#define int long long

const int maxn = 5e5+10;
const int inf = 2e9+10;

string s;
int n, k;
vector<int> ve[26];
int lst[maxn];
int lj[maxn], lo[maxn], li[maxn];

signed main()
{
    cin>> n >> k >> s;
    s = "*" + s;
  //  cout<< s <<" ";
   // cout<< s[n] <<" ";
    ll ans = inf;
    for(int i = 1; i <= n; i++)
    {
        int x = s[i]-'A';
   //     cout<< x <<" ";
        ve[x].push_back(i);
      //  cout<< x <<" ";
        if(ve[x].size() >= k)
        {
       //     cout<< ve[x].size() - k <<" ";
            lst[i] = ve[x][ve[x].size()-k];
        }
        if(s[i] == 'J') lj[i] = i;
        else lj[i] = lj[i-1];

        if(s[i] == 'O') lo[i] = i;
        else lo[i] = lo[i-1];

        if(s[i] == 'I') li[i] = i;
        else li[i] = li[i-1];


        if(s[i] == 'I')
        {
                int x = lst[i];
                //cout<< x <<" ";
                x = lo[x];
                //cout<< x <<" ";
                x = lst[x];
                //cout<< x <<" ";
                x = lj[x];
              //  cout<< x <<" ";
                x = lst[x];
            //    cout<< x <<" ";


           // cout<<

            if(x > 0)
                ans = min(ans, i-x+1);
        }
    }

    if(ans == inf)
        return cout<< -1, 0;
    cout<< ans - 3 * k;
}


Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:33:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(ve[x].size() >= k)
            ~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 5 ms 512 KB Output is correct
33 Correct 5 ms 512 KB Output is correct
34 Correct 5 ms 512 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 21 ms 8144 KB Output is correct
37 Correct 22 ms 9156 KB Output is correct
38 Correct 23 ms 9148 KB Output is correct
39 Correct 23 ms 9408 KB Output is correct
40 Correct 22 ms 9020 KB Output is correct
41 Correct 23 ms 9284 KB Output is correct
42 Correct 23 ms 9152 KB Output is correct
43 Correct 16 ms 5388 KB Output is correct
44 Correct 18 ms 6896 KB Output is correct
45 Correct 22 ms 9024 KB Output is correct
46 Correct 23 ms 9020 KB Output is correct
47 Correct 23 ms 9020 KB Output is correct
48 Correct 22 ms 9020 KB Output is correct
49 Correct 16 ms 6020 KB Output is correct
50 Correct 23 ms 9020 KB Output is correct
51 Correct 22 ms 9004 KB Output is correct
52 Correct 21 ms 7116 KB Output is correct
53 Correct 21 ms 7868 KB Output is correct
54 Correct 21 ms 9540 KB Output is correct
55 Correct 21 ms 8516 KB Output is correct
56 Correct 20 ms 8004 KB Output is correct