답안 #964555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964555 2024-04-17T05:52:29 Z onebit1024 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
9 ms 3440 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"

const double PI=3.141592653589;


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif



void solve()
{
    int n,k;cin >> n >> k;
    string s;cin >> s;
    s = "0"+s;
    vector<int>J,O,I;
    for(int i =1 ;i<=n;++i){
        if(s[i] == 'J')J.pb(i);
        else if(s[i]=='O')O.pb(i);
        else I.pb(i);
    }
    int res = 1e18;
    for(int i = 0;i<((J.size())-k+1);++i){
        int l = J[i+k-1];
        int c = upper_bound(all(O),l)-O.begin();
        if((c+k-1) < O.size()){
            l = O[c+k-1];
            c = upper_bound(all(I),l)-I.begin();
            if((c+k-1) < I.size()){
                l = I[c+k-1];
                res = min(res, l-J[i]+1 - (k*3));
            }
        }
    }
    if(res == 1e18)res =-1;
    cout << res << endl;
}   

int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    

    int T=1;
    for(int i = 1;i<=T;++i)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
}

Compilation message

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:52:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   52 |     for(int i = 0;i<((J.size())-k+1);++i){
      |                   ~^~~~~~~~~~~~~~~~~
ho_t2.cpp:55:20: 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]
   55 |         if((c+k-1) < O.size()){
      |            ~~~~~~~~^~~~~~~~~~
ho_t2.cpp:58:24: 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]
   58 |             if((c+k-1) < I.size()){
      |                ~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 500 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 452 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 476 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 452 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 0 ms 452 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 500 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 452 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 476 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 8 ms 2600 KB Output is correct
37 Correct 9 ms 3104 KB Output is correct
38 Correct 9 ms 2944 KB Output is correct
39 Correct 8 ms 2960 KB Output is correct
40 Correct 9 ms 2968 KB Output is correct
41 Correct 8 ms 3356 KB Output is correct
42 Correct 9 ms 2980 KB Output is correct
43 Correct 4 ms 2004 KB Output is correct
44 Correct 5 ms 2376 KB Output is correct
45 Correct 6 ms 3440 KB Output is correct
46 Correct 7 ms 3356 KB Output is correct
47 Correct 8 ms 3356 KB Output is correct
48 Correct 6 ms 3356 KB Output is correct
49 Correct 4 ms 2140 KB Output is correct
50 Correct 6 ms 3356 KB Output is correct
51 Correct 7 ms 2960 KB Output is correct
52 Correct 3 ms 2852 KB Output is correct
53 Correct 4 ms 2844 KB Output is correct
54 Correct 4 ms 3232 KB Output is correct
55 Correct 3 ms 3232 KB Output is correct
56 Correct 3 ms 3228 KB Output is correct