제출 #1360799

#제출 시각아이디문제언어결과실행 시간메모리
1360799yyc000123Gift Boxes (EGOI25_giftboxes)C++20
100 / 100
319 ms25884 KiB
#include<bits/stdc++.h>
using namespace std ;
const int N = 5e5+5 ;
int t , n , arr[N] , cnt[N] , cur[N] , le , ri ;
multiset<int> mst ;
tuple<int,int,int> ans ;

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) ;
    cin >> t >> n ;
    for(int i=0 ; i<n ; i++) cin >> arr[i] , cnt[arr[i]]++ ;
    for(int i=0 ; i<t ; i++){
        for(int j=1 ; j<cnt[i] ; j++) mst.insert(i) ;
    }
    ans = {n,0,n-1} ; ri = -1 ;
    while(!mst.empty()){
        ri++ ; cur[arr[ri]]++ ;
        if(mst.find(arr[ri])!=mst.end()) mst.erase(mst.find(arr[ri])) ;
    }
    for(le=0 ; le<n && ri<n ; le++){
        ans = min(ans,{ri-le+1,le,ri}) ;
        cur[arr[le]]-- ;
        while(ri<n && cnt[arr[le]]-cur[arr[le]]>1){
            ri++ ; if(ri==n) break ;
            cur[arr[ri]]++ ;
        }
    }
    cout << get<1>(ans) << ' ' << get<2>(ans) << '\n' ;
    return 0 ;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…