답안 #878360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878360 2023-11-24T08:39:07 Z hasan2006 JJOOII 2 (JOI20_ho_t2) C++17
1 / 100
1 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()
{
    int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
    cin>>n>>k;
    string a;
    cin>>a;
    deque<int>d[500];
    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 == 1e9) 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<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |     while(d['J'].size() >= k){
      |           ~~~~~~~~~~~~~~^~~~
ho_t2.cpp:38:26: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and '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<int>::size_type' {aka 'long unsigned int'} and '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<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |         if(d['J'].size() >= k && d['O'].size() >= k && d['I'].size() >= k)
      |                                                        ~~~~~~~~~~~~~~^~~~
ho_t2.cpp:26:9: warning: unused variable 'q' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |         ^
ho_t2.cpp:26:17: warning: unused variable 'j' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                 ^
ho_t2.cpp:26:21: warning: unused variable 'm' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                     ^
ho_t2.cpp:26:27: warning: unused variable 'z' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                           ^
ho_t2.cpp:26:30: warning: unused variable 's' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                              ^
ho_t2.cpp:26:38: warning: unused variable 'f' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                                      ^
ho_t2.cpp:26:41: warning: unused variable 'l' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                                         ^
ho_t2.cpp:26:45: warning: unused variable 'r' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                                             ^
ho_t2.cpp:26:53: warning: unused variable 'x' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                                                     ^
ho_t2.cpp:26:57: warning: unused variable 'y' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                                                         ^
ho_t2.cpp:26:73: warning: unused variable 'mx' [-Wunused-variable]
   26 |     int q , i , j , m ,n, z ,s = 0 , f, l , r , k , x , y , mn  = 1e9 , mx = 0;
      |                                                                         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 756 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 756 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 740 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Runtime error 1 ms 1116 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 1 ms 756 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 740 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Runtime error 1 ms 1116 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -