답안 #391000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391000 2021-04-17T14:29:41 Z wildturtle JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
15 ms 6368 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,d,i,e,f,g,n,m,k,l,minn,j;
ll A[500005],Ain[500005],L[500005],R[500005];
queue <ll> q;
string s;
int main() {
    cin>>n>>k>>s;
    for(ll i=0;i<s.size();i++) {
        if(s[i]=='O') {
            a++;
            A[a]=i;
            Ain[i]=a;
        }
    }
    for(ll i=0;i<s.size();i++) {
        if(s[i]=='J') {
            q.push(i);
            if(q.size()>k) q.pop();
        }
        if(s[i]=='O') {
            if(q.size()==k) L[i]=q.front();
            else L[i]=-1;
        }
    }
    while(!q.empty()) q.pop();
    for(ll i=s.size()-1;i>=0;i--) {
        if(s[i]=='I') {
            q.push(i);
            if(q.size()>k) q.pop();
        }
        if(s[i]=='O') {
            if(q.size()==k) R[i]=q.front();
            else R[i]=-1;
        }
    }
    minn=1e18;
    for(ll i=0;i<s.size();i++) {
        if(s[i]=='O') {
            j=A[Ain[i]+k-1];
            if(Ain[i]+k-1>a) continue;
            //cout<<i<<" "<<j<<" "<<L[i]<<" "<<R[j]<<endl;
            if(L[i]==-1 || R[j]==-1) continue;
            minn=min(minn,R[j]-L[i]+1-k*3);
        }
    }
    if(minn==1e18) cout<<-1;
    else cout<<minn;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:10:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(ll i=0;i<s.size();i++) {
      |                ~^~~~~~~~~
ho_t2.cpp:17:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(ll i=0;i<s.size();i++) {
      |                ~^~~~~~~~~
ho_t2.cpp:20:24: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   20 |             if(q.size()>k) q.pop();
      |                ~~~~~~~~^~
ho_t2.cpp:23:24: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |             if(q.size()==k) L[i]=q.front();
      |                ~~~~~~~~^~~
ho_t2.cpp:31:24: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   31 |             if(q.size()>k) q.pop();
      |                ~~~~~~~~^~
ho_t2.cpp:34:24: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   34 |             if(q.size()==k) R[i]=q.front();
      |                ~~~~~~~~^~~
ho_t2.cpp:39:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for(ll i=0;i<s.size();i++) {
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 308 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 15 ms 5572 KB Output is correct
37 Correct 14 ms 5968 KB Output is correct
38 Correct 14 ms 5976 KB Output is correct
39 Correct 14 ms 5944 KB Output is correct
40 Correct 14 ms 5984 KB Output is correct
41 Correct 15 ms 5984 KB Output is correct
42 Correct 14 ms 5984 KB Output is correct
43 Correct 9 ms 3936 KB Output is correct
44 Correct 12 ms 4704 KB Output is correct
45 Correct 14 ms 6112 KB Output is correct
46 Correct 15 ms 6112 KB Output is correct
47 Correct 14 ms 6112 KB Output is correct
48 Correct 14 ms 6112 KB Output is correct
49 Correct 11 ms 4196 KB Output is correct
50 Correct 14 ms 6112 KB Output is correct
51 Correct 14 ms 6080 KB Output is correct
52 Correct 14 ms 6112 KB Output is correct
53 Correct 14 ms 6368 KB Output is correct
54 Correct 10 ms 2912 KB Output is correct
55 Correct 9 ms 3168 KB Output is correct
56 Correct 9 ms 3356 KB Output is correct