답안 #867640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867640 2023-10-29T03:56:26 Z MongHwa JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
7 ms 3048 KB
#include <iostream>
#include <queue>
#include <deque>
using namespace std;

#define INF 0x7f7f7f7f

int jpos[200001], ipos[200001];
queue<int> qj, qi;
deque<int> dq;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, k; string s;
	cin >> n >> k >> s;

	fill(jpos, jpos+n, -1);
	fill(ipos, ipos+n, -1);

	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'J')
		{
			qj.push(i);
			if(qj.size() > k)
				qj.pop();
		}
		else if(s[i] == 'O')
			if(qj.size() == k)
				jpos[i] = qj.front();
	}

	for(int i = n-1; i >= 0; i--)
	{
		if(s[i] == 'I')
		{
			qi.push(i);
			if(qi.size() > k)
				qi.pop();
		}
		else if(s[i] == 'O')
			if(qi.size() == k)
				ipos[i] = qi.front();
	}

	int ans = INF;
	for(int i = 0; i < n; i++)
		if(s[i] == 'O')
		{
			dq.push_back(i);
			if(dq.size() == k)
			{
				if(ipos[dq.back()] != -1 && jpos[dq.front()] != -1)
					ans = min(ans, ipos[dq.back()]-jpos[dq.front()]+1);
				dq.pop_front();
			}
		}

	cout << (ans == INF ? -1 : ans-k*3) << '\n';
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:28:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |    if(qj.size() > k)
      |       ~~~~~~~~~~^~~
ho_t2.cpp:32:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |    if(qj.size() == k)
      |       ~~~~~~~~~~^~~~
ho_t2.cpp:41:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |    if(qi.size() > k)
      |       ~~~~~~~~~~^~~
ho_t2.cpp:45:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |    if(qi.size() == k)
      |       ~~~~~~~~~~^~~~
ho_t2.cpp:54:17: warning: comparison of integer expressions of different signedness: 'std::deque<int, std::allocator<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |    if(dq.size() == k)
      |       ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 472 KB Output is correct
7 Correct 0 ms 468 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 472 KB Output is correct
7 Correct 0 ms 468 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 472 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 472 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 348 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 352 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 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 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 716 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 472 KB Output is correct
7 Correct 0 ms 468 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 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 472 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 472 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 0 ms 348 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 352 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 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 0 ms 348 KB Output is correct
36 Correct 5 ms 2280 KB Output is correct
37 Correct 6 ms 2532 KB Output is correct
38 Correct 6 ms 2536 KB Output is correct
39 Correct 6 ms 2448 KB Output is correct
40 Correct 6 ms 2532 KB Output is correct
41 Correct 6 ms 2788 KB Output is correct
42 Correct 6 ms 2540 KB Output is correct
43 Correct 4 ms 1632 KB Output is correct
44 Correct 5 ms 2028 KB Output is correct
45 Correct 7 ms 2640 KB Output is correct
46 Correct 6 ms 2780 KB Output is correct
47 Correct 6 ms 2600 KB Output is correct
48 Correct 6 ms 2572 KB Output is correct
49 Correct 4 ms 1764 KB Output is correct
50 Correct 6 ms 2536 KB Output is correct
51 Correct 6 ms 2532 KB Output is correct
52 Correct 6 ms 3048 KB Output is correct
53 Correct 6 ms 3048 KB Output is correct
54 Correct 3 ms 2412 KB Output is correct
55 Correct 3 ms 2788 KB Output is correct
56 Correct 3 ms 3044 KB Output is correct