답안 #332695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332695 2020-12-03T03:22:46 Z limabeans JJOOII 2 (JOI20_ho_t2) C++17
13 / 100
2000 ms 3960 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;




int n,k;
string s;
int a[maxn];
int acc[maxn][3];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n>>k;
    cin>>s;
    for (int i=0; i<n; i++) {
	if (s[i]=='J') {
	    a[i+1]=0;
	} else if (s[i]=='O') {
	    a[i+1]=1;
	} else if (s[i]=='I') {
	    a[i+1]=2;
	} else assert(false);
    }

    for (int i=1; i<=n; i++) {
	acc[i][a[i]]++;
	for (int j=0; j<3; j++) {
	    acc[i][j] += acc[i-1][j];
	}
    }


    auto qry = [&](int l, int r, int i) {
	return acc[r][i] - acc[l-1][i];
    };


    vector<int> need = {k,k,k};
    int res = 2*n;

    for (int i=1; i<=n; i++) {
	int rm = 0;
	int x = 0;
	
	need[0]=need[1]=need[2]=k;

	for (int j=i; j<=n && x<3; j++) {
	    assert(x<3 && need[x]>0);
	    if (a[j]==x) {
		need[x]--;
	    } else {
		rm++;
	    }
	    while (x<3 && need[x]==0) x++;
	}
	
	if (x==3) {
	    res = min(res, rm);
	}
	
    }
    

    if (res>n) res=-1;
    cout<<res<<endl;
    
    return 0;
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:48:10: warning: variable 'qry' set but not used [-Wunused-but-set-variable]
   48 |     auto qry = [&](int l, int r, int i) {
      |          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 404 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 7 ms 364 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 15 ms 364 KB Output is correct
22 Correct 16 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 19 ms 364 KB Output is correct
25 Correct 20 ms 468 KB Output is correct
26 Correct 18 ms 364 KB Output is correct
27 Correct 19 ms 364 KB Output is correct
28 Correct 18 ms 364 KB Output is correct
29 Correct 19 ms 364 KB Output is correct
30 Correct 22 ms 468 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 19 ms 364 KB Output is correct
33 Correct 6 ms 364 KB Output is correct
34 Correct 11 ms 364 KB Output is correct
35 Correct 9 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 404 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 7 ms 364 KB Output is correct
19 Correct 4 ms 492 KB Output is correct
20 Correct 3 ms 364 KB Output is correct
21 Correct 15 ms 364 KB Output is correct
22 Correct 16 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 19 ms 364 KB Output is correct
25 Correct 20 ms 468 KB Output is correct
26 Correct 18 ms 364 KB Output is correct
27 Correct 19 ms 364 KB Output is correct
28 Correct 18 ms 364 KB Output is correct
29 Correct 19 ms 364 KB Output is correct
30 Correct 22 ms 468 KB Output is correct
31 Correct 4 ms 364 KB Output is correct
32 Correct 19 ms 364 KB Output is correct
33 Correct 6 ms 364 KB Output is correct
34 Correct 11 ms 364 KB Output is correct
35 Correct 9 ms 364 KB Output is correct
36 Correct 13 ms 3704 KB Output is correct
37 Correct 15 ms 3960 KB Output is correct
38 Correct 14 ms 3960 KB Output is correct
39 Execution timed out 2092 ms 3960 KB Time limit exceeded
40 Halted 0 ms 0 KB -