python-algorithm
백준 31520 Champernowne Verification
무적김두칠
2024. 4. 18. 08:38
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번 조건문을 적지 않으면 시간초과가 발생합니다!
반응형