답안 #854247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854247 2023-09-26T13:19:12 Z LeVanThuc JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
9 ms 8540 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
    if(x<y)
    {
        x=y;
        return 1;
    }
    return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
    if(x>y)
    {
        x=y;
        return 1;
    }
    return 0;
}
void online()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef thuc
    freopen("input.INP","r",stdin);
    freopen("output.OUT","w",stdout);
#endif
}
const ll N=2e5+10,inf=1e18;
pll a[N];
ll s[3],n,k;
ll c[N][3];
deque<ll> dq[3];
int main()
{
    online();
    ll ans=1e18;
    memset(c,0x3f,sizeof c);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        char ch;
        cin>>ch;
        c[i][0]=c[i-1][0]+1;
        c[i][1]=c[i-1][1]+1;
        c[i][2]=c[i-1][2]+1;
        if(ch=='J')
        {
            if(dq[0].size()) s[0]+=i-dq[0].back()-1;
            dq[0].push_back(i);
            if(dq[0].size()>k)
            {
                ll z=dq[0].front();
                dq[0].pop_front();
                s[0]-=dq[0].front()-z-1;
            }
            if(dq[0].size()==k)
            {
                minimize(c[i][0],s[0]);
            }
        }
        if(ch=='O')
        {
            if(dq[1].size()) s[1]+=i-dq[1].back()-1;
            dq[1].push_back(i);
            if(dq[1].size()>k)
            {
                ll z=dq[1].front();
                dq[1].pop_front();
                s[1]-=dq[1].front()-z-1;
            }
            if(dq[1].size()==k)
            {
                minimize(c[i][1],c[dq[1].front()-1][0]+s[1]);
            }
        }
        if(ch=='I')
        {
            if(dq[2].size()) s[2]+=i-dq[2].back()-1;
            dq[2].push_back(i);
            if(dq[2].size()>k)
            {
                ll z=dq[2].front();
                dq[2].pop_front();
                s[2]-=dq[2].front()-z-1;
            }
            if(dq[2].size()==k)
            {
                minimize(ans,c[dq[2].front()-1][1]+s[2]);
            }
        }
    }
    if(ans==1e18) ans=-1;
    cout<<ans;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:63:28: 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]
   63 |             if(dq[0].size()>k)
      |                ~~~~~~~~~~~~^~
ho_t2.cpp:69:28: 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]
   69 |             if(dq[0].size()==k)
      |                ~~~~~~~~~~~~^~~
ho_t2.cpp:78:28: 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]
   78 |             if(dq[1].size()>k)
      |                ~~~~~~~~~~~~^~
ho_t2.cpp:84:28: 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]
   84 |             if(dq[1].size()==k)
      |                ~~~~~~~~~~~~^~~
ho_t2.cpp:93:28: 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]
   93 |             if(dq[2].size()>k)
      |                ~~~~~~~~~~~~^~
ho_t2.cpp:99:28: 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]
   99 |             if(dq[2].size()==k)
      |                ~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6804 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6804 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6804 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6804 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 7000 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6612 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 2 ms 6744 KB Output is correct
31 Correct 1 ms 6748 KB Output is correct
32 Correct 1 ms 6744 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 7000 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6804 KB Output is correct
10 Correct 1 ms 6744 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6804 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 7000 KB Output is correct
18 Correct 1 ms 6748 KB Output is correct
19 Correct 1 ms 6612 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
21 Correct 1 ms 6748 KB Output is correct
22 Correct 1 ms 6748 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 2 ms 6744 KB Output is correct
31 Correct 1 ms 6748 KB Output is correct
32 Correct 1 ms 6744 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 7000 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 7 ms 6744 KB Output is correct
37 Correct 7 ms 6808 KB Output is correct
38 Correct 7 ms 6912 KB Output is correct
39 Correct 8 ms 7004 KB Output is correct
40 Correct 9 ms 7452 KB Output is correct
41 Correct 8 ms 7220 KB Output is correct
42 Correct 8 ms 6932 KB Output is correct
43 Correct 6 ms 7516 KB Output is correct
44 Correct 6 ms 7380 KB Output is correct
45 Correct 8 ms 7576 KB Output is correct
46 Correct 9 ms 7580 KB Output is correct
47 Correct 7 ms 7524 KB Output is correct
48 Correct 8 ms 7516 KB Output is correct
49 Correct 5 ms 7120 KB Output is correct
50 Correct 8 ms 7516 KB Output is correct
51 Correct 7 ms 7516 KB Output is correct
52 Correct 8 ms 8356 KB Output is correct
53 Correct 7 ms 8284 KB Output is correct
54 Correct 5 ms 6748 KB Output is correct
55 Correct 5 ms 8028 KB Output is correct
56 Correct 7 ms 8540 KB Output is correct