답안 #242422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242422 2020-06-27T16:09:38 Z SorahISA JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
17 ms 3328 KB
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

vector<int> J, O, I;

int32_t main() {
    fastIO();
    
    int n, k;
    string s;
    cin >> n >> k >> s;
    
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'J') J.eb(i);
        if (s[i] == 'O') O.eb(i);
        if (s[i] == 'I') I.eb(i);
    }
    
    int Jz = J.size(), Oz = O.size(), Iz = I.size();
    // if (Jz < k or Oz < k or Iz < k) return cout << -1 << "\n", 0;
    
    // int pL = J[k - 1], pR = I[Iz - k];
    // int cnt = lower_bound(ALL(O), pR) - lower_bound(ALL(O), pL);
    // if (cnt < k) return cout << -1 << "\n", 0;
    
    int minCost = INF;
    for (int L = 0, R = k-1; R < Jz; ++L, ++R) {
        int O_ends = lower_bound(ALL(O), J[R]) - O.begin() + k - 1;
        if (O_ends >= Oz) continue;
        int I_ends = lower_bound(ALL(I), O[O_ends]) - I.begin() + k - 1;
        if (I_ends >= Iz) continue;
        minCost = min(minCost, (I[I_ends] - J[L] + 1) - 3 * k);
    }
    
    cout << (minCost == INF ? -1 : minCost) << "\n";
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 6 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 15 ms 2428 KB Output is correct
37 Correct 17 ms 3004 KB Output is correct
38 Correct 17 ms 3000 KB Output is correct
39 Correct 16 ms 2936 KB Output is correct
40 Correct 14 ms 2936 KB Output is correct
41 Correct 15 ms 3064 KB Output is correct
42 Correct 17 ms 2876 KB Output is correct
43 Correct 10 ms 1940 KB Output is correct
44 Correct 11 ms 2028 KB Output is correct
45 Correct 13 ms 3064 KB Output is correct
46 Correct 13 ms 2876 KB Output is correct
47 Correct 14 ms 2936 KB Output is correct
48 Correct 14 ms 3004 KB Output is correct
49 Correct 10 ms 1920 KB Output is correct
50 Correct 14 ms 2992 KB Output is correct
51 Correct 13 ms 3068 KB Output is correct
52 Correct 9 ms 2364 KB Output is correct
53 Correct 10 ms 2936 KB Output is correct
54 Correct 11 ms 3328 KB Output is correct
55 Correct 9 ms 3328 KB Output is correct
56 Correct 8 ms 3328 KB Output is correct