https://www.acmicpc.net/problem/31520
31520번: Champernowne Verification
The $k^{\text{th}}$ Champernowne word is obtained by writing down the first $k$ positive integers and concatenating them together. For example, the $10^{\text{th}}$ Champernowne word is $12345678910$. Given a positive integer $n$, determine if it is a Cham
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
def sol(s):
start = 1
chk = ''
while len(s) != len(chk):
chk += str(start)
if s[:len(chk)] != chk:
return -1
start += 1
start -= 1
if chk == s:
return start
else:
return -1
if __name__ == '__main__':
s = input()
print(sol(s))
|
cs |
라인 6번 조건문을 적지 않으면 시간초과가 발생합니다!
반응형
'python-algorithm' 카테고리의 다른 글
백준 31668 특별한 가지 (0) | 2024.04.19 |
---|---|
백준 31428 엘리스 트랙 매칭 (0) | 2024.04.19 |
백준 30501 관공... 어찌하여 목만 오셨소... (0) | 2024.04.18 |
백준 31090 2023은 무엇이 특별할까? (0) | 2024.04.18 |
백준 24087 アイスクリーム (Ice Cream) (0) | 2024.04.18 |
댓글