Submission #878294

# Submission time Handle Problem Language Result Execution time Memory
878294 2023-11-24T08:03:45 Z hasan2006 JJOOII 2 (JOI20_ho_t2) C++17
1 / 100
2 ms 1116 KB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll   a[N] = {}, b[N] , c[N] , d[N] , dp[N];

void solve()
{
    ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
    cin>>n>>k;
    string a;
    cin>>a;
    deque<ll>d[400];
    for(i = 0; i < n; i++)
        d[a[i]].pb(i);
    while(d['J'].size() >= k){
        while(d['O'].size() && d['O'].front() < d['J'][k - 1])
            d['O'].pop_front();
        while(d['I'].size() && d['I'].front() < d['O'][k - 1])
            d['I'].pop_front();
        if(d['J'].size() >= k && d['O'].size() >= k && d['I'].size() >= k)
            mn = min(mn , d['I'][k - 1] - d['J'][0] - 3 * k + 1);
        d['J'].pop_front();
    }
    if(mn == 1e18) mn = -1;
    cout<<mn<<"\n";
}

int main(){
int t = 1;
//cin>>t;
while(t--)
     {
     solve();
     }
}
// Author : حسن

Compilation message

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:32:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   32 |         d[a[i]].pb(i);
      |               ^
ho_t2.cpp:33:25: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   33 |     while(d['J'].size() >= k){
      |           ~~~~~~~~~~~~~~^~~~
ho_t2.cpp:38:26: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |         if(d['J'].size() >= k && d['O'].size() >= k && d['I'].size() >= k)
      |            ~~~~~~~~~~~~~~^~~~
ho_t2.cpp:38:48: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |         if(d['J'].size() >= k && d['O'].size() >= k && d['I'].size() >= k)
      |                                  ~~~~~~~~~~~~~~^~~~
ho_t2.cpp:38:70: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   38 |         if(d['J'].size() >= k && d['O'].size() >= k && d['I'].size() >= k)
      |                                                        ~~~~~~~~~~~~~~^~~~
ho_t2.cpp:26:8: warning: unused variable 'q' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
ho_t2.cpp:26:16: warning: unused variable 'j' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                ^
ho_t2.cpp:26:20: warning: unused variable 'm' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                    ^
ho_t2.cpp:26:26: warning: unused variable 'z' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
ho_t2.cpp:26:29: warning: unused variable 's' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                             ^
ho_t2.cpp:26:37: warning: unused variable 'f' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                     ^
ho_t2.cpp:26:40: warning: unused variable 'l' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                        ^
ho_t2.cpp:26:44: warning: unused variable 'r' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                            ^
ho_t2.cpp:26:52: warning: unused variable 'x' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                    ^
ho_t2.cpp:26:56: warning: unused variable 'y' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                        ^
ho_t2.cpp:26:73: warning: unused variable 'mx' [-Wunused-variable]
   26 |     ll q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                                         ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 652 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 728 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Runtime error 2 ms 1116 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 472 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 652 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 728 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Runtime error 2 ms 1116 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -