답안 #1115042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1115042 2024-11-19T23:03:14 Z AdamGS JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 336 KB
#include<bits/stdc++.h>
#ifdef _DEBUG
#define ls(x) << (x) << ", "
#define lv(x) << #x << ": " << flush << (x) << ", "
#define pr(x) cout << "Line: " << __LINE__ << ", " x << endl;
#else
#define ls(x)
#define lv(x)
#define pr(x) ;
#endif
using namespace std;
typedef unsigned int uint;

constexpr char J = 'J';
constexpr char O = 'O';
constexpr char I = 'I';
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    uint n, k;
    cin >> n >> k;
    string a;
    cin >> a;
    vector<uint> o(n), j(n), i(n);
    uint o_size = 0, i_size = 0, j_size = 0;
    for (uint it = 0; it < n; it++) {
        if (a[it] == J) {
            j[j_size] = it;
            j_size++;
        } else if (a[it] == O) {
            o[o_size] = it;
            o_size++;
        } else if (a[it] == I) {
            i[i_size] = it;
            i_size++;
        }
    }
    uint num_o = 0, result = 1e9;
    for (uint it = 0; it < n; it++) {
        pr(lv(it) lv(a[it]) lv(a[it] == O))
        if (a[it] != O) continue;
        pr()
        num_o++;
        vector<uint>::iterator i_pos = lower_bound(i.begin(), i.begin() + i_size, it);
        if (i_pos == i.begin() + i_size) {
            pr(ls("not found"))
            continue;
        }
        int i_first = i.begin() - i_pos + k - 1;
        int o_last = o[num_o + k - 1];
        vector<uint>::iterator j_last_pos = upper_bound(j.begin(), j.begin() + j_size, o_last);
        if (j_last_pos == i.begin() + j_size) {
            pr(ls("not found"))
            continue;
        }
        int j_last = *j_last_pos;
        uint cost = j_last - i_first + 1 - 3*k;
        pr(lv(num_o) lv(i_first) lv(o_last) lv(j_last))
        result = min(result, cost);
    }
    if (result == 1e9) {
        result = 0;
    }
    cout << result << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -