답안 #831430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831430 2023-08-20T08:53:04 Z Mularstyle JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
7 ms 2472 KB
#include <bits/stdc++.h>
using namespace std;

char s[200008];
int qs[200008];

int main()
{
    int n, k;

	cin>>n>>k;
	cin>>s+1;
    n=strlen(s+1);
    vector<int> js;
    vector<int> is;

	for(int i = 1; i<= n; i++)
	{
		if(s[i] == 'J')
			js.push_back(i);
		else if(s[i] == 'O')
			qs[i] = 1;
		else
            is.push_back(i);
		qs[i] += qs[i-1];
	}
	int mn = INT_MAX;
	int cur = 0;
	for(int j = k-1; j<  js.size(); j++)
	{
		while(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]< k)
            cur++;

		if(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]>= k)
		{
			mn = min(mn, is[cur+k-1]-js[j-k+1]+1);
		}
	}

	if(mn == INT_MAX)
        cout<<"-1\n";
	else
        cout<<mn-3*k;

}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:12:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |  cin>>s+1;
      |       ~^~
ho_t2.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int j = k-1; j<  js.size(); j++)
      |                   ~^~~~~~~~~~~~
ho_t2.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   while(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]< k)
      |         ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:34:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   if(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]>= k)
      |      ~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 308 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 308 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 5 ms 1984 KB Output is correct
37 Correct 6 ms 2368 KB Output is correct
38 Correct 6 ms 2296 KB Output is correct
39 Correct 7 ms 2280 KB Output is correct
40 Correct 6 ms 2380 KB Output is correct
41 Correct 6 ms 2384 KB Output is correct
42 Correct 6 ms 2276 KB Output is correct
43 Correct 4 ms 1408 KB Output is correct
44 Correct 4 ms 1744 KB Output is correct
45 Correct 5 ms 2296 KB Output is correct
46 Correct 6 ms 2380 KB Output is correct
47 Correct 5 ms 2320 KB Output is correct
48 Correct 6 ms 2384 KB Output is correct
49 Correct 4 ms 1532 KB Output is correct
50 Correct 5 ms 2364 KB Output is correct
51 Correct 5 ms 2296 KB Output is correct
52 Correct 5 ms 2128 KB Output is correct
53 Correct 5 ms 2384 KB Output is correct
54 Correct 4 ms 2396 KB Output is correct
55 Correct 5 ms 2392 KB Output is correct
56 Correct 4 ms 2472 KB Output is correct