Submission #484841

# Submission time Handle Problem Language Result Execution time Memory
484841 2021-11-05T15:39:48 Z dxz05 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
10 ms 1560 KB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 2222;

int f(char c){
    return (c == 'J' ? 0 : c == 'O' ? 1 : 2);
}

void solve(int TC) {
    int n, k; string s;
    cin >> n >> k >> s;

    deque<int> dq[3];
    for (int i = 0; i < n; i++){
        dq[f(s[i])].push_back(i + 1);
    }

    int ans = -1;
    for (int i = 1; i <= n; i++){
        while (!dq[0].empty() && dq[0].front() < i) dq[0].pop_front();
        
        if (dq[0].size() < k) break;

        int j = dq[0][k - 1];
        while (!dq[1].empty() && dq[1].front() < j) dq[1].pop_front();

        if (dq[1].size() < k) break;

        j = dq[1][k - 1];
        while (!dq[2].empty() && dq[2].front() < j) dq[2].pop_front();

        if (dq[2].size() >= k){
            j = dq[2][k - 1];
            if (ans == -1 || ans > j - i + 1 - 3 * k) ans = j - i + 1 - 3 * k;
        }
    }

    cout << ans;

}

int main() {
    startTime = clock();
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
//    cin >> TC;

    for (int test = 1; test <= TC; test++) {
        debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}

Compilation message

ho_t2.cpp: In function 'void solve(int)':
ho_t2.cpp:60:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |         if (dq[0].size() < k) break;
      |             ~~~~~~~~~~~~~^~~
ho_t2.cpp:65:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |         if (dq[1].size() < k) break;
      |             ~~~~~~~~~~~~~^~~
ho_t2.cpp:70:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |         if (dq[2].size() >= k){
      |             ~~~~~~~~~~~~~^~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:20: warning: statement has no effect [-Wunused-value]
   19 | #define debug(...) 42
      |                    ^~
ho_t2.cpp:93:9: note: in expansion of macro 'debug'
   93 |         debug(test);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 316 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 7 ms 1484 KB Output is correct
37 Correct 7 ms 1496 KB Output is correct
38 Correct 6 ms 1488 KB Output is correct
39 Correct 7 ms 1552 KB Output is correct
40 Correct 5 ms 1496 KB Output is correct
41 Correct 6 ms 1496 KB Output is correct
42 Correct 10 ms 1560 KB Output is correct
43 Correct 3 ms 1044 KB Output is correct
44 Correct 4 ms 1240 KB Output is correct
45 Correct 7 ms 1496 KB Output is correct
46 Correct 5 ms 1496 KB Output is correct
47 Correct 5 ms 1516 KB Output is correct
48 Correct 4 ms 1496 KB Output is correct
49 Correct 3 ms 1112 KB Output is correct
50 Correct 6 ms 1496 KB Output is correct
51 Correct 4 ms 1496 KB Output is correct
52 Correct 3 ms 1496 KB Output is correct
53 Correct 3 ms 1496 KB Output is correct
54 Correct 3 ms 1496 KB Output is correct
55 Correct 2 ms 1496 KB Output is correct
56 Correct 2 ms 1496 KB Output is correct