답안 #957692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957692 2024-04-04T08:18:59 Z BhavayGoyal JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
25 ms 7312 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = 
            tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -------------------------------------------------- Main Code --------------------------------------------------

const int N = 2e5+5;
int arr[N];
vi pos[N];

void sol() {
    int n, k; cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        char x; cin >> x; 
        if (x == 'J') arr[i] = 0;
        else if (x == 'O') arr[i] = 1;
        else arr[i] = 2;
        pos[arr[i]].pb(i);
    }

    auto get = [&](int ch, int idx) {
        if (idx == -1) return -1;
        int i = lower_bound(all(pos[ch]), idx) - pos[ch].begin();
        i += k-1;
        if (i >= pos[ch].size()) return -1;
        return pos[ch][i]+1;
    };

    int ans = inf;

    for (int i = 1; i <= n; i++) {
        int j = i;
        j = get(0, j);
        j = get(1, j);
        j = get(2, j);
        if (j == -1) break;
        int x = i-1 + n-j+1;
        ans = min(ans, n - x - k*3);
    }

    if (ans == inf) cout << -1 << endl;
    else cout << ans << endl;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t; 
    while (t--) {
        sol();
    }
    return 0;
}

Compilation message

ho_t2.cpp: In lambda function:
ho_t2.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         if (i >= pos[ch].size()) return -1;
      |             ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 1 ms 5168 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4980 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 1 ms 5212 KB Output is correct
27 Correct 1 ms 5168 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 1 ms 5212 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 1 ms 4952 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4952 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 2 ms 4952 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 1 ms 5168 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4980 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 2 ms 5212 KB Output is correct
26 Correct 1 ms 5212 KB Output is correct
27 Correct 1 ms 5168 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 1 ms 5212 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 22 ms 6724 KB Output is correct
37 Correct 25 ms 7312 KB Output is correct
38 Correct 23 ms 7116 KB Output is correct
39 Correct 19 ms 7124 KB Output is correct
40 Correct 10 ms 7256 KB Output is correct
41 Correct 17 ms 7132 KB Output is correct
42 Correct 24 ms 7132 KB Output is correct
43 Correct 4 ms 6364 KB Output is correct
44 Correct 5 ms 6620 KB Output is correct
45 Correct 7 ms 7260 KB Output is correct
46 Correct 6 ms 7124 KB Output is correct
47 Correct 7 ms 7212 KB Output is correct
48 Correct 6 ms 7256 KB Output is correct
49 Correct 5 ms 6356 KB Output is correct
50 Correct 6 ms 7132 KB Output is correct
51 Correct 7 ms 7132 KB Output is correct
52 Correct 6 ms 6868 KB Output is correct
53 Correct 13 ms 7116 KB Output is correct
54 Correct 10 ms 7264 KB Output is correct
55 Correct 6 ms 7264 KB Output is correct
56 Correct 4 ms 7264 KB Output is correct