답안 #532463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532463 2022-03-03T00:22:00 Z Nanashi_Panda JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
11 ms 3240 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#define jizz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define ll long long
using namespace std;
char str[200005];
ll s,t;
ll n, k;
ll ans = 200005;
ll loc, cnt;

vector <ll> locJ, locO, locI;
vector <ll>::iterator it;
int main() {
	scanf("%lld%lld", &n, &k);
	scanf("%s", str);
	s = 0;
	for(ll i = 0; i < n; i++){
		if(str[i]=='J')locJ.push_back(i);
		else if(str[i]=='O')locO.push_back(i);
		else locI.push_back(i);
	}
	ll num = 0;
	bool ok = 1;
	for(ll i = 0; i < locJ.size()-k+1; i++){
		num=locJ[i+k-1]-locJ[i]+1-k;
		ok = 1;
		it = upper_bound(locO.begin(), locO.end(), locJ[i+k-1]);
		if(it == locO.end()) ok = 0;
		if(ok){
			s = it-locO.begin();
			if(s+k-1>=locO.size()) ok = 0;
			else num+=locO[s+k-1]-locJ[i+k-1]-k;
			if(ok){
				it = upper_bound(locI.begin(), locI.end(), locO[s+k-1]);
				if(it==locI.end()) ok = 0;
				else{
					t = it-locI.begin();
					if(t+k-1>=locI.size()) ok = 0;
					else num+=locI[t+k-1]-locO[s+k-1]-k;
					if(ok) {
						ans = min(num, ans);
					}
				}
					
			}
		}
		if(!ok) break;
	}
	if(ans<200000)
		printf("%lld", ans);
	else
		printf("-1");
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:27:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   27 |  for(ll i = 0; i < locJ.size()-k+1; i++){
      |                ~~^~~~~~~~~~~~~~~~~
ho_t2.cpp:34:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    if(s+k-1>=locO.size()) ok = 0;
      |       ~~~~~^~~~~~~~~~~~~
ho_t2.cpp:41:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |      if(t+k-1>=locI.size()) ok = 0;
      |         ~~~~~^~~~~~~~~~~~~
ho_t2.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%lld%lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%s", str);
      |  ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 300 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 300 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 308 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 300 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 300 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 308 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 10 ms 2212 KB Output is correct
37 Correct 11 ms 2848 KB Output is correct
38 Correct 11 ms 2892 KB Output is correct
39 Correct 9 ms 2956 KB Output is correct
40 Correct 7 ms 3000 KB Output is correct
41 Correct 8 ms 2968 KB Output is correct
42 Correct 10 ms 2848 KB Output is correct
43 Correct 3 ms 1988 KB Output is correct
44 Correct 4 ms 1972 KB Output is correct
45 Correct 4 ms 2880 KB Output is correct
46 Correct 5 ms 2836 KB Output is correct
47 Correct 5 ms 2880 KB Output is correct
48 Correct 5 ms 2856 KB Output is correct
49 Correct 3 ms 1740 KB Output is correct
50 Correct 5 ms 2824 KB Output is correct
51 Correct 5 ms 2844 KB Output is correct
52 Correct 4 ms 2212 KB Output is correct
53 Correct 5 ms 2816 KB Output is correct
54 Correct 5 ms 3236 KB Output is correct
55 Correct 4 ms 3204 KB Output is correct
56 Correct 4 ms 3240 KB Output is correct