제출 #332695

#제출 시각아이디문제언어결과실행 시간메모리
332695limabeansJJOOII 2 (JOI20_ho_t2)C++17
13 / 100
2092 ms3960 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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) {
      |          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...