답안 #872331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872331 2023-11-12T21:51:36 Z Marco_Escandon JJOOII 2 (JOI20_ho_t2) C++11
0 / 100
0 ms 344 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;
        if(s[i]=='J')
            temp.push_back(i);
        if(temp.size()==k)
        {
            ac1[i]=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+1]<<"\n";
        if(c==k&&ac2[d]!=1e9&&ac1[i+1]!=-1e9)
        {
            bs=min(bs,ac2[d]+1-ac1[i+1]-(3*k));
        }
        d++;
    }
    if(bs>=n)
        cout<<"-1";
    else 
        cout<<bs;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18: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]
   18 |         if(temp.size()==k)
      |            ~~~~~~~~~~~^~~
ho_t2.cpp:34: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]
   34 |         if(temp.size()==k)
      |            ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -