제출 #1357256

#제출 시각아이디문제언어결과실행 시간메모리
1357256sallyGift Boxes (EGOI25_giftboxes)C++20
11 / 100
31 ms6316 KiB
#include<iostream>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
const int mx = 5e5+5;
vector<int> team(mx);
vector<int> cnt(mx, 0);
int T, N;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>T>>N;
    int end = -1;
    vector<int> temp(N, 0);
    for(int i=0; i<N; i++) {
        cin>>team[i];
        temp[team[i]]++;
        if(temp[team[i]] == 2 && end == -1) end = i;
    }
    int L = 0, R = 0;
    cnt[team[L]]++;
    int nums = 1, mn = N+5, l, r;
    while(R+1<N) {
        R+=1;
        if(cnt[team[R]] == 0) nums++;
        cnt[team[R]]+=1;
        if(nums == T) {
            mn = (R - L) + 1;
            l = L;
            r = R;
            break;
        }
    }
    while(L+1<=end) {
        int t = team[L];
        L++;
        cnt[t]--;
        while(cnt[t] == 0 && R+1<N) {
            R++;
            cnt[team[R]]++;
        }
        if((R - L) + 1 < mn) {mn = (R - L) + 1; r = R, l = L;}
    }
    cout<<L<<' '<<R;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…