답안 #773078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773078 2023-07-04T14:47:37 Z RecursiveCo JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
12 ms 3380 KB
// CF template, version 3.0

#include <bits/stdc++.h>

using namespace std;

#define improvePerformance ios_base::sync_with_stdio(false); cin.tie(0)
#define getTest int t; cin >> t
#define eachTest for (int _var=0;_var<t;_var++)
#define get(name) int (name); cin >> (name)
#define out(o) cout << (o)
#define getList(cnt, name) vector<int> (name); for (int _=0;_<(cnt);_++) { get(a); (name).push_back(a); }
#define sortl(name) sort((name).begin(), (name).end())
#define rev(name) reverse((name).begin(), (name).end())
#define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
#define decision(b) if (b){out("YES");}else{out("NO");}

#define int long long int

signed main() {
    improvePerformance;
    get(n);
    get(k);
    vector<char> str;
    vector<int> J;
    vector<int> O;
    vector<int> I;
    forto(n, i) {
        char c;
        cin >> c;
        str.push_back(c);
        if (c == 'J') J.push_back(i);
        else if (c == 'O') O.push_back(i);
        else I.push_back(i);
    }
    int ans = 1e18;
    forto(J.size() - k + 1, i) {
        int start = J[i];
        int lastJ = J[i + k - 1];
        int oind = lower_bound(O.begin(), O.end(), lastJ) - O.begin() + k - 1;
        if (oind >= O.size()) continue;
        int lastO = O[oind];

        int iind = lower_bound(I.begin(), I.end(), lastO) - I.begin() + k - 1;
        if (iind >= I.size()) continue;
        int lastI = I[iind];
        int sz = lastI - start + 1;
        ans = min(ans, sz - 3 * k);
    }
    out(ans == 1e18? -1: ans);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:10:23: warning: unnecessary parentheses in declaration of 'n' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
ho_t2.cpp:22:5: note: in expansion of macro 'get'
   22 |     get(n);
      |     ^~~
ho_t2.cpp:10:23: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
   10 | #define get(name) int (name); cin >> (name)
      |                       ^
ho_t2.cpp:23:5: note: in expansion of macro 'get'
   23 |     get(k);
      |     ^~~
ho_t2.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
ho_t2.cpp:28:5: note: in expansion of macro 'forto'
   28 |     forto(n, i) {
      |     ^~~~~
ho_t2.cpp:15:35: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                   ^
ho_t2.cpp:37:5: note: in expansion of macro 'forto'
   37 |     forto(J.size() - k + 1, i) {
      |     ^~~~~
ho_t2.cpp:15:52: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   15 | #define forto(name, var) for (int (var) = 0; (var) < (name); (var)++)
      |                                              ~~~~~~^~~~~~~~
ho_t2.cpp:37:5: note: in expansion of macro 'forto'
   37 |     forto(J.size() - k + 1, i) {
      |     ^~~~~
ho_t2.cpp:41:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if (oind >= O.size()) continue;
      |             ~~~~~^~~~~~~~~~~
ho_t2.cpp:45:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         if (iind >= I.size()) continue;
      |             ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 316 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 10 ms 2368 KB Output is correct
37 Correct 11 ms 2932 KB Output is correct
38 Correct 11 ms 2920 KB Output is correct
39 Correct 10 ms 2872 KB Output is correct
40 Correct 9 ms 2936 KB Output is correct
41 Correct 12 ms 2980 KB Output is correct
42 Correct 12 ms 2916 KB Output is correct
43 Correct 5 ms 1692 KB Output is correct
44 Correct 7 ms 1968 KB Output is correct
45 Correct 10 ms 2916 KB Output is correct
46 Correct 9 ms 2908 KB Output is correct
47 Correct 8 ms 3012 KB Output is correct
48 Correct 9 ms 2900 KB Output is correct
49 Correct 8 ms 1756 KB Output is correct
50 Correct 8 ms 2908 KB Output is correct
51 Correct 11 ms 2852 KB Output is correct
52 Correct 6 ms 2392 KB Output is correct
53 Correct 7 ms 2900 KB Output is correct
54 Correct 9 ms 3380 KB Output is correct
55 Correct 7 ms 3340 KB Output is correct
56 Correct 4 ms 3336 KB Output is correct