답안 #926464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926464 2024-02-13T04:44:01 Z oblantis JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
6 ms 3816 KB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e6 + 1;

void solve() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	deque<int> dq[3];
	int r[n][3], ans = n + 1;
	for(int i = n - 1; i >= 0; i--){
		r[i][0] = r[i][1] = r[i][2] = -1;
		if(s[i] == 'J'){
			dq[0].push_front(i);
			if((int)dq[0].size() > k)dq[0].pop_back();
		}
		else if(s[i] == 'O'){
			dq[1].push_front(i);
			if((int)dq[1].size() > k)dq[1].pop_back();
		}
		else {
			dq[2].push_front(i);
			if((int)dq[2].size() > k)dq[2].pop_back();
		}
		if((int)dq[0].size() >= k)r[i][0] = dq[0].back();
		if((int)dq[1].size() >= k)r[i][1] = dq[1].back();
		if((int)dq[2].size() >= k)r[i][2] = dq[2].back();
		if(r[i][0] != -1 && r[r[i][0]][1] != -1 && r[r[r[i][0]][1]][2] != -1)ans = min(ans, r[r[r[i][0]][1]][2] - i - k * 3 + 1);
	}
	cout << (ans == n + 1 ? -1 : ans);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int times = 1;
	//cin >> times;
	for(int i = 1; i <= times; i++) {
		solve();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 452 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 0 ms 452 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 5 ms 3048 KB Output is correct
37 Correct 5 ms 3084 KB Output is correct
38 Correct 5 ms 3304 KB Output is correct
39 Correct 5 ms 3292 KB Output is correct
40 Correct 5 ms 3304 KB Output is correct
41 Correct 5 ms 3304 KB Output is correct
42 Correct 5 ms 3304 KB Output is correct
43 Correct 3 ms 2136 KB Output is correct
44 Correct 4 ms 2792 KB Output is correct
45 Correct 5 ms 3312 KB Output is correct
46 Correct 5 ms 3304 KB Output is correct
47 Correct 5 ms 3300 KB Output is correct
48 Correct 5 ms 3304 KB Output is correct
49 Correct 3 ms 2276 KB Output is correct
50 Correct 6 ms 3304 KB Output is correct
51 Correct 5 ms 3456 KB Output is correct
52 Correct 4 ms 3556 KB Output is correct
53 Correct 5 ms 3816 KB Output is correct
54 Correct 3 ms 3304 KB Output is correct
55 Correct 4 ms 3560 KB Output is correct
56 Correct 3 ms 3816 KB Output is correct