답안 #207913

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207913 2020-03-09T12:00:48 Z Blerargh JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
18 ms 2296 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;

#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define ROF(i, a, b) for(int i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define SORT(x) sort((x).begin(), (x).end())
#define CMPSORT(x, cp) sort((x).begin(), (x).end(), cp)
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define getchar_unlocked _getchar_nolock

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){ 
    FAST
    ll n, k;
    string ss = "";
    deque<ll> idj, ido, idi, idj1;
    cin >> n >> k;
    FOR(i, 1, n){
        char c;
        cin >> c;
        ss+=c;
        if (c == 'J') idj.pb(i);
        if (c == 'I') idi.pb(i);
    }

    ll op = INF;
    FOR(i, 1, n){
        while ((ido.empty() || (ll)idj.ft() < (ll)ido.ft()) && !idj.empty() && idj.ft() < i) idj1.pb(idj.ft()), idj.ppf(); 
        while ((ll)idj1.size()>k) idj1.ppf();

        while (!idi.empty() && i > (ll)idi.ft()) idi.ppf();

        if (ss[i-1] == 'O'){
            ido.pb(i);
            if ((ll)ido.size()==k){
                ido.ppf();
                if ((ll)idj1.size()>=k && (ll)idi.size()>=k) {
                    ll ops = idi[k-1] - idj1.ft()+1;
                    ops -= k*3;
                    op = min(op, ops);
                }
            }
        }
    }
    if (op == INF) cout << "-1";
    else cout << op;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 248 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 248 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 380 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 248 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 248 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 4 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 248 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 380 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 248 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 14 ms 1528 KB Output is correct
37 Correct 15 ms 1656 KB Output is correct
38 Correct 15 ms 1656 KB Output is correct
39 Correct 16 ms 1784 KB Output is correct
40 Correct 16 ms 1656 KB Output is correct
41 Correct 16 ms 1656 KB Output is correct
42 Correct 18 ms 1656 KB Output is correct
43 Correct 11 ms 1272 KB Output is correct
44 Correct 13 ms 1400 KB Output is correct
45 Correct 15 ms 1656 KB Output is correct
46 Correct 15 ms 1656 KB Output is correct
47 Correct 15 ms 1656 KB Output is correct
48 Correct 15 ms 1656 KB Output is correct
49 Correct 12 ms 1272 KB Output is correct
50 Correct 15 ms 1656 KB Output is correct
51 Correct 15 ms 1656 KB Output is correct
52 Correct 14 ms 1656 KB Output is correct
53 Correct 15 ms 1656 KB Output is correct
54 Correct 12 ms 1656 KB Output is correct
55 Correct 11 ms 1912 KB Output is correct
56 Correct 11 ms 2296 KB Output is correct