Submission #1114930

# Submission time Handle Problem Language Result Execution time Memory
1114930 2024-11-19T19:56:55 Z AdamGS JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MAXN = 20007;
int J[MAXN];
int O[MAXN];
int I[MAXN];

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> vJ;
    vector<int> vO;
    vector<int> vI;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] == 'J')
            vJ.push_back(i);
        if(s[i] == 'O')
            vO.push_back(i);
        if(s[i] == 'I')
            vI.push_back(i);
    }
    for(int i = 0; i < (int)vJ.size() - k + 1; ++i)
        J[vJ[i]] = vJ[i+k-1];
    for(int i = 0; i < (int)vO.size() - k + 1; ++i)
        O[vO[i]] = vO[i+k-1];
    for(int i = 0; i < (int)vI.size() - k + 1; ++i)
        I[vI[i]] = vI[i+k-1];
    int naso[n];
    int nasi[n];
    int oo = n;
    int ii = n;
    for(int i = n-1; i >= 0; --i)
    {
        naso[i] = oo;
        nasi[i] = ii;
        if(s[i] == 'O')
            oo = i;
        if(s[i] == 'I')
            ii = i;
    }
    int odp = MAXN;
    for(int i = 0; i < n; ++i)
    {
        if(s[i] != 'J')
            continue;
        int a = J[i];
        if(k == 1 && a == 0) continue;
        int b = naso[a];
        if(b == n) continue;
        int c = O[b];
        if(c == 0) continue;
        int d = nasi[c];
        if(d == n) continue;
        int e = I[d];
        if(e == 0) continue;
        odp = min(odp, e-i+1);
    }
    if(odp == MAXN)
    {
        cout << "-1";
        return 0;
    }
    cout << odp - k*3;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 1 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 1 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Incorrect 1 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -