답안 #515961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
515961 2022-01-20T08:11:55 Z David_M JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
7 ms 5972 KB
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define FF first.first
#define FS first.second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e18, P=998244353;

ll q=1, n, m, x, y, z, l, r, c, k, a[N], b[3][N], f[N], ansl, ansr, ans, o, u, Ans[N];
vector <ll> v[3];
string s;

void solve(){
    cin>>n>>k>>s;
    for (int i=0; i<n; i++){
        a[i]=(s[i]=='J')?0:((s[i]=='O')?1:2);
        v[a[i]].pb(i);
    }
    for (int i=0; i<k; i++)v[1].pb(INF),v[2].pb(2*INF);
    ans=INF;
    for (int x0=0, x1=0, x2=0; x0+k-1<v[0].size(); x0++){
        while(v[1][x1]<v[0][x0+k-1])x1++;
        while(v[2][x2]<v[1][x1+k-1])x2++;
        ans=min(ans, v[2][x2+k-1]-v[0][x0]+1-3*k);
    }

    cout<<(ans>n?-1:ans);

}


main(){ios_base::sync_with_stdio(false), cin.tie(0);

	int T=1;
	//cin>>T;
    while(T--){
        solve();
    }

}

Compilation message

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:25:38: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int x0=0, x1=0, x2=0; x0+k-1<v[0].size(); x0++){
      |                                ~~~~~~^~~~~~~~~~~~
ho_t2.cpp: At global scope:
ho_t2.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main(){ios_base::sync_with_stdio(false), cin.tie(0);
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 0 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 0 ms 304 KB Output is correct
31 Correct 0 ms 300 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 0 ms 320 KB Output is correct
16 Correct 0 ms 336 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 0 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 0 ms 304 KB Output is correct
31 Correct 0 ms 300 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 5 ms 3752 KB Output is correct
37 Correct 6 ms 4424 KB Output is correct
38 Correct 6 ms 4400 KB Output is correct
39 Correct 5 ms 4504 KB Output is correct
40 Correct 7 ms 4680 KB Output is correct
41 Correct 6 ms 4548 KB Output is correct
42 Correct 6 ms 4424 KB Output is correct
43 Correct 4 ms 2968 KB Output is correct
44 Correct 5 ms 4016 KB Output is correct
45 Correct 6 ms 4488 KB Output is correct
46 Correct 6 ms 4460 KB Output is correct
47 Correct 6 ms 4540 KB Output is correct
48 Correct 5 ms 4524 KB Output is correct
49 Correct 4 ms 3092 KB Output is correct
50 Correct 7 ms 4516 KB Output is correct
51 Correct 5 ms 4512 KB Output is correct
52 Correct 5 ms 4768 KB Output is correct
53 Correct 5 ms 4808 KB Output is correct
54 Correct 4 ms 4800 KB Output is correct
55 Correct 4 ms 4812 KB Output is correct
56 Correct 6 ms 5972 KB Output is correct