회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
c++ 시간초과
7662번 - 이중 우선순위 큐
taiho0303
2년 전
0
우선순위 큐 안쓰고 map으로만 구현했는데 map만으로는 무조건 시간초과인가요..?
#include<iostream> #include<map> using namespace std; void play(){ int k; cin>>k; map<int,int> hash; for(int i=0;i<k;i++){ char cmd; cin>>cmd; if(cmd=='I'){ int pushNum; cin>>pushNum; hash[pushNum]++; } if(cmd=='D'){ int checkNum; cin>>checkNum; if(checkNum==1){ // 최댓값 삭제 for(auto it=hash.rbegin();it!=hash.rend();it++){ if(it->second<=0) continue; it->second--; break; } } if(checkNum==-1){ for(auto it=hash.begin();it!=hash.end();it++){ if(it->second<=0) continue; it->second--; break; } } } } int maxNum,minNum; bool check=false; for(auto it=hash.begin();it!=hash.end();it++){ // 최솟값찾기 if(it->second<=0) continue; minNum=it->first; check=true; break; } for(auto it=hash.rbegin();it!=hash.rend();it++){ // 최솟값찾기 if(it->second<=0) continue; maxNum=it->first; check=true; break; } if(!check){ cout<<"EMPTY"<<'\n'; return; } cout<<maxNum<<" "<<minNum<<'\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin>>t; for(int i=0;i<t;i++){ play(); } }
zenith82114
2년 전
0
rbegin부터 rend까지 루프를 도는 시점에서 아웃입니다. 카운트가 0인 값들이 잔뜩 쌓여 있을 때를 상상해 보세요.
댓글을 작성하려면
로그인
해야 합니다.
taiho0303 2년 전
우선순위 큐 안쓰고 map으로만 구현했는데 map만으로는 무조건 시간초과인가요..?