답안 #286885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286885 2020-08-31T06:18:18 Z arnold518 JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
8 ms 2688 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

int N, K;
char S[MAXN+10];
int P[MAXN+10], Q[MAXN+10];

int main()
{
	scanf("%d%d", &N, &K);
	scanf("%s", S+1);

	vector<int> V;
	P[0]=-1;
	for(int i=1; i<=N; i++)
	{
		if(S[i]=='J') V.push_back(i);
		if(V.size()<K) P[i]=-1;
		else P[i]=V[V.size()-K];
	}
	V.clear();

	Q[N+1]=-1;
	for(int i=N; i>=1; i--)
	{
		if(S[i]=='I') V.push_back(i);
		if(V.size()<K) Q[i]=-1;
		else Q[i]=V[V.size()-K];
	}
	V.clear();

	int ans=2e9;
	for(int i=1; i<=N; i++)
	{
		if(S[i]=='O') V.push_back(i);
		if(V.size()<K) continue;
		else
		{
			int p=V[V.size()-K], q=i;
			int l=P[p-1], r=Q[q+1];
			if(l==-1 || r==-1) continue;
			ans=min(ans, r-l+1);
		}
	}

	if(ans==2e9) return !printf("-1\n");
	printf("%d\n", ans-3*K);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:24:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |   if(V.size()<K) P[i]=-1;
      |      ~~~~~~~~^~
ho_t2.cpp:33:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   33 |   if(V.size()<K) Q[i]=-1;
      |      ~~~~~~~~^~
ho_t2.cpp:42:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |   if(V.size()<K) continue;
      |      ~~~~~~~~^~
ho_t2.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%s", S+1);
      |  ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 416 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 416 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 7 ms 2684 KB Output is correct
37 Correct 7 ms 2680 KB Output is correct
38 Correct 7 ms 2680 KB Output is correct
39 Correct 7 ms 2680 KB Output is correct
40 Correct 7 ms 2680 KB Output is correct
41 Correct 8 ms 2680 KB Output is correct
42 Correct 7 ms 2680 KB Output is correct
43 Correct 5 ms 1788 KB Output is correct
44 Correct 5 ms 2172 KB Output is correct
45 Correct 7 ms 2680 KB Output is correct
46 Correct 7 ms 2680 KB Output is correct
47 Correct 7 ms 2680 KB Output is correct
48 Correct 7 ms 2680 KB Output is correct
49 Correct 5 ms 1916 KB Output is correct
50 Correct 7 ms 2680 KB Output is correct
51 Correct 7 ms 2688 KB Output is correct
52 Correct 7 ms 2556 KB Output is correct
53 Correct 7 ms 2680 KB Output is correct
54 Correct 5 ms 2680 KB Output is correct
55 Correct 5 ms 2680 KB Output is correct
56 Correct 5 ms 2680 KB Output is correct