Submission #795262

# Submission time Handle Problem Language Result Execution time Memory
795262 2023-07-27T07:54:05 Z Theo830 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
6 ms 3288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vll ex[3];
    ll p[3] = {0};
    f(i,0,n){
        if(s[i] == 'J'){
            ex[0].pb(i);
        }
        else if(s[i] == 'O'){
            ex[1].pb(i);
        }
        else{
            ex[2].pb(i);
        }
    }
    ll ans = n+1;
    f(i,0,n){
        while(p[0] < ex[0].size() && ex[0][p[0]] < i){
            p[0]++;
        }
        if(p[0]+k-1 >= ex[0].size()){
            break;
        }
        while(p[1] < ex[1].size() && ex[1][p[1]] < ex[0][p[0] + k - 1]){
            p[1]++;
        }
        if(p[1]+k-1 >= ex[1].size()){
            break;
        }
        while(p[2] < ex[2].size() && ex[2][p[2]] < ex[1][p[1] + k - 1]){
            p[2]++;
        }
        if(p[2]+k-1 >= ex[2].size()){
            break;
        }
        ans = min(ans,n - ex[0][p[0]] - (n-1 - ex[2][p[2] + k-1]) - 3 * k);
    }
    if(ans == n+1){
        ans = -1;
    }
    cout<<ans<<"\n";
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:47:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         while(p[0] < ex[0].size() && ex[0][p[0]] < i){
      |               ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:50:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(p[0]+k-1 >= ex[0].size()){
      |            ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:53:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while(p[1] < ex[1].size() && ex[1][p[1]] < ex[0][p[0] + k - 1]){
      |               ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:56:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         if(p[1]+k-1 >= ex[1].size()){
      |            ~~~~~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:59:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(p[2] < ex[2].size() && ex[2][p[2]] < ex[1][p[1] + k - 1]){
      |               ~~~~~^~~~~~~~~~~~~~
ho_t2.cpp:62:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         if(p[2]+k-1 >= ex[2].size()){
      |            ~~~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 1 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 212 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 1 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 212 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 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 372 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 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 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 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 212 KB Output is correct
32 Correct 0 ms 320 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 316 KB Output is correct
35 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 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 1 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 212 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 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 372 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 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 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 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 212 KB Output is correct
32 Correct 0 ms 320 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 316 KB Output is correct
35 Correct 0 ms 320 KB Output is correct
36 Correct 5 ms 2372 KB Output is correct
37 Correct 6 ms 2892 KB Output is correct
38 Correct 5 ms 2860 KB Output is correct
39 Correct 5 ms 2952 KB Output is correct
40 Correct 4 ms 3020 KB Output is correct
41 Correct 5 ms 3028 KB Output is correct
42 Correct 6 ms 2892 KB Output is correct
43 Correct 2 ms 1824 KB Output is correct
44 Correct 2 ms 2096 KB Output is correct
45 Correct 4 ms 2932 KB Output is correct
46 Correct 3 ms 2960 KB Output is correct
47 Correct 4 ms 3020 KB Output is correct
48 Correct 4 ms 2992 KB Output is correct
49 Correct 3 ms 1852 KB Output is correct
50 Correct 4 ms 3016 KB Output is correct
51 Correct 4 ms 3020 KB Output is correct
52 Correct 3 ms 2368 KB Output is correct
53 Correct 4 ms 2916 KB Output is correct
54 Correct 3 ms 3280 KB Output is correct
55 Correct 3 ms 3288 KB Output is correct
56 Correct 2 ms 3288 KB Output is correct