회원가입
로그인
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
글쓰기
질문 도움말
자주묻는 질문
파이썬, 재귀함수 이분탐색으로 예제는 잘 나오는데 시간초과
10816번 - 숫자 카드 2
jaejunkim041219
3년 전
0
무슨 이유로 시간초과가 발생하는지 잘 모르겠네요... 도와주시면 답례로 뽀뽀를 드리겠습니다.
import sys def recall(low,high,mid,l1,i,n): if(low==high and i!=l1[mid]): return n elif(low==high and i==l1[mid]): n+=1 return n elif(high-low==1 and i!=l1[low] and i!=l1[high]): return n elif(high-low==1 and (i==l1[low] or i==l1[high])): if(i==l1[low]):n+=1 if(i==l1[high]):n+=1 return n if(i>l1[mid]): low=mid+1 high=high mid=(low+high)//2 return recall(low,high,mid,l1,i,n) elif(i<l1[mid]): low=low high=mid-1 mid=(low+high)//2 return recall(low,high,mid,l1,i,n) elif(i==l1[mid]): n+=1 n=recall(mid+1,high,((mid+1)+high)//2,l1,i,n) return recall(low,mid-1,(low+(mid-1))//2,l1,i,n) N=int(sys.stdin.readline().rstrip()) l1=list(map(int,sys.stdin.readline().rstrip().split())) M=int(sys.stdin.readline().rstrip()) l2=list(map(int,sys.stdin.readline().rstrip().split())) l1.sort() low=0 high=N-1 mid=(low+high)//2 n=0 for i in l2: print(recall(low,high,mid,l1,i,n), end=" ")
댓글을 작성하려면
로그인
해야 합니다.
jaejunkim041219 3년 전
무슨 이유로 시간초과가 발생하는지 잘 모르겠네요... 도와주시면 답례로 뽀뽀를 드리겠습니다.