1 solutions

  • 1
    @ 2023-10-6 10:42:23
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int n,m,painter[1000005],a,b,s=1000009,back,have[2005]={0},cnt=0;
    	bool right,goback=false,end=false;
    	cin>>n>>m;
    	for(int i=1;i<=n;++i) cin>>painter[i];
    	for(int i=1;i<=n;++i){
            if(end) break;
            have[painter[i-1]]-=1;
            if(have[painter[i-1]]==0) cnt--;
    		for(int j=i;j<=n;){
                if(goback) j=back;
                else{
                    have[painter[j]]++;
                    if(have[painter[j]]==1) cnt++;
                }
                right=false;
                goback=false;
                if(cnt==m) right=true;
    			if(right&&j-i+1<s){
    				a=i;
    				b=j;
                    s=j-i+1;
    			}
                if(j==n&&!right){
                    end=true;
                    break;
                }
                if(right){
                    goback=true;
                    back=j;
                    break;
                }
                else ++j;
    		}
    	}
    	cout<<a<<" "<<b;
    	return 0;
    }
    
    • 1

    Information

    ID
    630
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    3
    Tags
    # Submissions
    24
    Accepted
    6
    Uploaded By