Submission #922808

# Submission time Handle Problem Language Result Execution time Memory
922808 2024-02-06T06:52:04 Z dimashhh JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 12, MOD = 1e9 + 7;

typedef long long ll;

int n,k,A[N],B[N],C[N];
string s;
vector<int> a,b,c;
void test(){
    cin >> n >> k >> s;
    s = "#" + s;
    for(int i = 1;i <= n;i++){
        A[i] = A[i - 1];
        B[i] = B[i - 1];
        C[i] = C[i - 1];
        if(s[i] == 'J'){
            A[i]++;
            a.push_back(i);
        }else if(s[i] == 'O'){
            B[i]++;
            b.push_back(i);
        }else{
            C[i]++;
            c.push_back(i);
        }
    }
    if(min({(int)a.size(),(int)b.size(),(int)c.size()}) < k){
        cout << -1 << '\n';
        return;
    }
    int res = 1e9;
    for(int i = 0;i < (int)a.size();i++){
        if(i + k - 1 >= (int)a.size()) break;
//        int l = 0,r = min((int)c.size() - 1,(int)c.size() - 1 + k);
//        while(r - l > 1){
//            int j = (l + r) >> 1;
//            if(i + k - 1 < (int)a.size() && B[c[j]] - B[a[i + k - 1]] >= k){
//                res = min(res,n - k * 3 - (a[i] - 1) - (n - c[j + k - 1]));
//                r = j;
//            }else{
//                l = j;
//            }
//        }
        for(int j = min((int)c.size() - 1,(int)c.size() - 1 + k);j >= 0;j--){
            if(B[c[j]] - B[a[i + k - 1]] >= k){
                res = min(res,n - k * 3 - (a[i] - 1) - (n - c[j + k - 1]));
            }
        }
    }
    if(res == 1e9) res = -1;
    cout<< res << '\n';
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int T = 1;
//    cin >> T;
    while (T--)
        test();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 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 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -