Submission #872334

# Submission time Handle Problem Language Result Execution time Memory
872334 2023-11-12T22:04:50 Z Marco_Escandon JJOOII 2 (JOI20_ho_t2) C++11
100 / 100
12 ms 4524 KB
 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    deque<ll> temp;
    ll ac1[n+5]={ };
    ll ac2[n+5]={ };
    for(int i=0; i<n;i++)
        ac1[i]=-1e9;
    for(int i=0; i<n; i++)
    {
        if(s[i]=='J')
            temp.push_back(i);
        if(temp.size()==k)
        {
            ac1[i+1]=temp.front();
            temp.pop_front();
        }
        if(i>0)
            ac1[i]=max(ac1[i],ac1[i-1]);
        ac2[i]=1e9;
    }
    temp.clear();
    ac2[n]=1e9;
    for(int i=n-1; i>-1; i--)
    {
        //ac2[i]=1e9;
        if(s[i]=='I')
            temp.push_back(i);
        if(temp.size()==k)
        {
            if(i>0)
            ac2[i-1]=temp.front();
            temp.pop_front();
        }
        ac2[i]=min(ac2[i],ac2[i+1]);
        //cout<<ac2[i]<<" ";
    }
    ll i=0; ll d=0;
    ll c=0;
    ll bs=1e9;
    while(d!=n)
    {
        if(s[d]=='O')
            c++;
        while(c==k+1||(c==k&&s[i]!='O'))
        {
            if(s[i]=='O')
                c--;
            i++;
        }
        //cout<<c<<i<<" "<<d<<" "<<ac2[d]<<" "<<ac1[i]<<"\n";
        if(c==k&&ac2[d]!=1e9&&ac1[i]!=-1e9)
        {
            bs=min(bs,ac2[d]+1-ac1[i]-(3*k));
        }
        d++;
    }
    if(bs>=n)
        cout<<"-1";
    else 
        cout<<bs;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:23: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   19 |         if(temp.size()==k)
      |            ~~~~~~~~~~~^~~
ho_t2.cpp:35:23: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   35 |         if(temp.size()==k)
      |            ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 436 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 436 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 436 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 436 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 432 KB Output is correct
36 Correct 8 ms 3820 KB Output is correct
37 Correct 10 ms 4076 KB Output is correct
38 Correct 9 ms 4072 KB Output is correct
39 Correct 9 ms 3860 KB Output is correct
40 Correct 9 ms 4076 KB Output is correct
41 Correct 9 ms 4076 KB Output is correct
42 Correct 12 ms 4076 KB Output is correct
43 Correct 6 ms 2540 KB Output is correct
44 Correct 7 ms 3304 KB Output is correct
45 Correct 12 ms 4072 KB Output is correct
46 Correct 9 ms 4072 KB Output is correct
47 Correct 10 ms 4076 KB Output is correct
48 Correct 10 ms 4088 KB Output is correct
49 Correct 6 ms 2792 KB Output is correct
50 Correct 9 ms 4288 KB Output is correct
51 Correct 9 ms 4072 KB Output is correct
52 Correct 9 ms 4328 KB Output is correct
53 Correct 8 ms 4332 KB Output is correct
54 Correct 7 ms 4076 KB Output is correct
55 Correct 7 ms 4332 KB Output is correct
56 Correct 7 ms 4524 KB Output is correct