회원가입
로그인
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
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
1107 리모컨 - 반례 부탁드립니다!!
1107번 - 리모컨
devheyrin
1년 전
0
1107 리모컨 문제입니다. 반례 부탁드립니다!!!
from itertools import product def not_contain_broken_btn(arr, n): for item in arr: if item in str(n): return False return True def solution(): n = int(input()) # 채널 m = int(input()) # 고장난 버튼 개수 if m: buttons = list(input().split()) # 고장난 버튼 # 현재 보고 있는 채널 - 100 now = 100 press = 0 while True: if n == now: return press if not m or not_contain_broken_btn(buttons, n): press = min(abs(now-n), len(str(n))) return press able_buttons = [str(i) for i in range(10) if str(i) not in buttons] candidates = list(product(able_buttons, repeat=len(str(n)))) for i in range(1, len(str(n))): candidates = candidates+list(product(able_buttons, repeat=i)) temp = [] for candidate in candidates: channel = int(''.join(candidate)) temp.append((abs(n - channel), len(str(channel)))) #print(temp) if not temp: return abs(n - now) temp.sort(key=lambda x: x[0]) press = temp[0][0] + temp[0][1] return min(press, abs(n - now)) print(solution())
kravi
1년 전
1
드렸습니다.
7 7 3 4 5 6 7 8 9 답: 5
댓글을 작성하려면
로그인
해야 합니다.
devheyrin 1년 전
1107 리모컨 문제입니다. 반례 부탁드립니다!!!