답안 #445614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445614 2021-07-19T04:43:35 Z jamezzz JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
8 ms 1484 KB
#include <bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
mt19937 rng(time(0));

int n,k;
deque<int> dq[3];
char c[200005];

int main(){
	sf("%d%d",&n,&k);
	sf(" %s",&c);
	for(int i=0;i<n;++i){
		if(c[i]=='J')dq[0].push_back(i);
		if(c[i]=='O')dq[1].push_back(i);
		if(c[i]=='I')dq[2].push_back(i);
	}
	int ans=INF;
	while(true){
		if(sz(dq[0])<k)break;
		while(!dq[1].empty()&&dq[1].front()<dq[0][k-1])dq[1].pop_front();
		if(sz(dq[1])<k)break;
		while(!dq[2].empty()&&dq[2].front()<dq[1][k-1])dq[2].pop_front();
		if(sz(dq[2])<k)break;
		ans=min(ans,dq[2][k-1]-dq[0][0]+1-3*k);
		dq[0].pop_front();
	}
	if(ans==INF)ans=-1;
	pf("%d\n",ans);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:31:8: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[200005]' [-Wformat=]
   31 |  sf(" %s",&c);
      |       ~^  ~~
      |        |  |
      |        |  char (*)[200005]
      |        char*
ho_t2.cpp:30:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |  sf("%d%d",&n,&k);
      |    ^
ho_t2.cpp:31:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  sf(" %s",&c);
      |    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 6 ms 1356 KB Output is correct
37 Correct 7 ms 1472 KB Output is correct
38 Correct 6 ms 1484 KB Output is correct
39 Correct 6 ms 1472 KB Output is correct
40 Correct 5 ms 1484 KB Output is correct
41 Correct 6 ms 1484 KB Output is correct
42 Correct 8 ms 1484 KB Output is correct
43 Correct 3 ms 972 KB Output is correct
44 Correct 4 ms 1228 KB Output is correct
45 Correct 5 ms 1472 KB Output is correct
46 Correct 5 ms 1484 KB Output is correct
47 Correct 5 ms 1484 KB Output is correct
48 Correct 4 ms 1484 KB Output is correct
49 Correct 3 ms 1100 KB Output is correct
50 Correct 4 ms 1484 KB Output is correct
51 Correct 5 ms 1484 KB Output is correct
52 Correct 4 ms 1484 KB Output is correct
53 Correct 4 ms 1484 KB Output is correct
54 Correct 3 ms 1484 KB Output is correct
55 Correct 3 ms 1472 KB Output is correct
56 Correct 3 ms 1484 KB Output is correct