제출 #828869

#제출 시각아이디문제언어결과실행 시간메모리
828869raphaelpJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
8 ms3296 KiB
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    vector<int> J(N, -1), O(N, -1), I(N, -1);
    deque<int> temp;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'J')
            temp.push_back(i);
        if (temp.size() > K)
            temp.pop_front();
        if (temp.size() == K)
            J[i] = temp.front();
    }
    temp.clear();
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'O')
            temp.push_back(i);
        if (temp.size() > K)
            temp.pop_front();
        if (temp.size() == K)
            O[i] = temp.front();
    }
    temp.clear();
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'I')
            temp.push_back(i);
        if (temp.size() > K)
            temp.pop_front();
        if (temp.size() == K)
            I[i] = temp.front();
    }
    int ans = -1;
    for (int i = 0; i < N; i++)
    {
        int u = I[i];
        if (!(u + 1))
            continue;
        int o = O[u];
        if (!(o + 1))
            continue;
        int j = J[o];
        if (!(j + 1))
            continue;
        if (i - j + 1 - (K * 3) > -1)
        {
            ans = min(ans, i - j + 1 - (K * 3));
            if (ans == -1)
                ans = i - j + 1 - (K * 3);
        }
    }
    cout << ans;
}

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:15:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         if (temp.size() > K)
      |             ~~~~~~~~~~~~^~~
ho_t2.cpp:17:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |         if (temp.size() == K)
      |             ~~~~~~~~~~~~^~~~
ho_t2.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |         if (temp.size() > K)
      |             ~~~~~~~~~~~~^~~
ho_t2.cpp:27:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |         if (temp.size() == K)
      |             ~~~~~~~~~~~~^~~~
ho_t2.cpp:35:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if (temp.size() > K)
      |             ~~~~~~~~~~~~^~~
ho_t2.cpp:37:25: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         if (temp.size() == K)
      |             ~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...