제출 #206213

#제출 시각아이디문제언어결과실행 시간메모리
206213combi1k1JJOOII 2 (JOI20_ho_t2)C++14
100 / 100
76 ms3012 KiB
#include<bits/stdc++.h>

using namespace std;

#define ll  long long
#define X   first
#define Y   second

#define all(x)  x.begin(),x.end()
#define sz(x)   (int)x.size()

#define pb      emplace_back
#define endl    "\n"

const ll    inf = 1e18;
const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

int c[N][3];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n, k;   cin >> n >> k;
    string S;   cin >> S;

    S = "#" + S;

    for(int i = 1 ; i <= n ; ++i)   {
        c[i][0] = c[i - 1][0] + (S[i] == 'J');
        c[i][1] = c[i - 1][1] + (S[i] == 'O');
        c[i][2] = c[i - 1][2] + (S[i] == 'I');
    }

    int ans = 1e9 + 7;

    for(int i = 1 ; i <= n ; ++i)   {
        int p = i;
        for(int j = 0 ; j < 3 ; ++j)    {
            int l = p;
            int r = n + 1;

            while  (l < r)  {
                int m = l + r >> 1;

                if (c[m][j] - c[p - 1][j] >= k)
                    r = m;
                else
                    l = m + 1;
            }
            p = l;
        }
        if (p <= n)
            ans = min(ans,p + 1 - 3 * k - i);
    }
    if (ans == 1e9 + 7)
        ans = -1;

    cout << ans << endl;
}

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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:46:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
                 int m = l + r >> 1;
                         ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...