[PS] 그리디: 10162 전자레인지

devhans·2024년 8월 26일
0

PS

목록 보기
4/20
post-thumbnail

문제 출처

https://www.acmicpc.net/problem/10162

포인트

필요한 조리시간을 맞추지 못하는 경우 -1로 반환해야 함
이때 300초, 60초는 모두 10초로 인수분해되므로 10초로 나누었을 때 나머지가 존재하는 조리시간을 입력받은 경우 -1로 처리될 수 있도록 분기처리

코드

import sys

fast_print=sys.stdout.write
required_cook_time = int(sys.stdin.readline().rstrip())

timer_type = [300, 60, 10]

if required_cook_time % timer_type[-1] != 0:
    fast_print(str(-1))
else:
    for timer in timer_type:
        temp_cnt = required_cook_time // timer
        required_cook_time %= timer
        fast_print(str(temp_cnt) + " ")

코멘트

int 자료형을 str 함수로 문자열로 바꾸는 것보다 좋은 방법이 없을까..?
더 빠른 방법이 존재할 것 같다.

profile
책 읽고 운동하기

0개의 댓글