답안 #831427

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

int main()
{
    int n, k;
    char s[3008];
    int qs[3008];

	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:11:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   11 |  cin>>s+1;
      |       ~^~
ho_t2.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int j = k-1; j<  js.size(); j++)
      |                   ~^~~~~~~~~~~~
ho_t2.cpp:30:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   while(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]< k)
      |         ~~~~~~~^~~~~~~~~~~
ho_t2.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   if(cur+k-1< is.size() && qs[is[cur]-1]-qs[js[j]]>= k)
      |      ~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 232 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 1 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 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 232 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 1 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 1 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 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 0 ms 212 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 232 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 1 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 1 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 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 0 ms 212 KB Output isn't correct
20 Halted 0 ms 0 KB -