Submission #475908

# Submission time Handle Problem Language Result Execution time Memory
475908 2021-09-24T12:23:20 Z ymm JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
11 ms 2504 KB
///
///   Let the voice of love take you higher!
///

#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x, l, r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef          long long   ll;
typedef unsigned long long  ull;
typedef std::pair<int,int>  pii;
typedef std::pair<ll ,ll >  pll;
using namespace std;

const int N = 200010;
vector<pii> J, I;
int n, k;

int main()
{
    FAST;
    cin >> n >> k;
    int cnt = 0;
    Loop(i,0,n)
    {
        char c;
        cin >> c;
        if(toupper(c) == 'J') J.push_back({i,cnt});
        if(toupper(c) == 'I') I.push_back({i,cnt});
        if(toupper(c) == 'O') ++cnt;
    }
    int ans = INT_MAX;
    int p1 = k-1;
    int p2 = 0;
    while(p1 < (ll)J.size())
    {
        while(p2 <= (ll)I.size()-k && I[p2].S - J[p1].S < k) ++p2;
        if(p2 > (ll)I.size()-k) break;
        ans = min(ans, I[p2+k-1].F-J[p1-k+1].F+1-3*k);
        ++p1;
    }
    cout << (ans==INT_MAX?-1:ans) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 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 312 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 272 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 0 ms 312 KB Output is correct
34 Correct 1 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 1 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 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 312 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 272 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 0 ms 312 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 7 ms 1536 KB Output is correct
37 Correct 9 ms 2120 KB Output is correct
38 Correct 9 ms 2184 KB Output is correct
39 Correct 9 ms 2188 KB Output is correct
40 Correct 11 ms 2180 KB Output is correct
41 Correct 8 ms 2244 KB Output is correct
42 Correct 10 ms 2080 KB Output is correct
43 Correct 5 ms 1352 KB Output is correct
44 Correct 6 ms 1472 KB Output is correct
45 Correct 8 ms 2124 KB Output is correct
46 Correct 7 ms 2084 KB Output is correct
47 Correct 8 ms 2232 KB Output is correct
48 Correct 9 ms 2240 KB Output is correct
49 Correct 5 ms 1352 KB Output is correct
50 Correct 9 ms 2216 KB Output is correct
51 Correct 8 ms 2200 KB Output is correct
52 Correct 7 ms 1728 KB Output is correct
53 Correct 7 ms 2228 KB Output is correct
54 Correct 5 ms 2504 KB Output is correct
55 Correct 6 ms 2472 KB Output is correct
56 Correct 8 ms 2496 KB Output is correct