목록PS/Python (269)
지나가던 개발자

import sys nums = [] for i in range(int(sys.stdin.readline())): nums.append(int(sys.stdin.readline())) for i in sorted(nums): sys.stdout.write(str(i)) sys.stdout.write("\n") 이 문제를 무려 6개월동안이나(!) 못 풀었다. 이렇게 쉬운 문제를.. 파이썬의 기본적인 sort 알고리즘은 Tim Sort 알고리즘이다. Tim Sort는 O(nlogn)의 시간 복잡도를 가진다. 이는 퀵 소트와도 같은 시간 복잡도로, 왠만한 문제는 다 풀린다고 보면 된다. 그런데 이렇게 떴다!! 시간 초과! 그래서 뭐가 문제지 하고 안 풀고 있다가 오늘 문득 sys가 기억이 나서.. 빠른 입력을..

def nthPrime(n): a = [False, False] + [True] * 999998 Primes = [] for i in range(2, 999998): if a[i]: Primes.append(i) for j in range(i+i, 999998, i): a[j] = False return Primes[n-1] print(nthPrime(int(input()))) https://wlghsp.tistory.com/17 [Python] n번째 소수 찾기 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 def nthPrime(n): # To-do # 충분히 큰 크기(1000000 정도)를 가진 리스트를 생성하고 # 에라토스테네스의 체를 사용해 n번.. wlghsp..

a, b = input().split(" ") print(bin(int(a, 2)+int(b, 2))[2:]) 와 ㅋㅋ int(변수, 2) 이런 식으로 해서 2진수인 변수를 10진수로 바꿀 수 있다는 건 진짜 처음 알았다. 혁신이네 진짜.

import sys sys.setrecursionlimit(10**6) def nth_fibonacci(n, lookup): if n

def 자기복제수(num): if str(num**2)[-len(str(num)):] == str(num): return "YES" return "NO" for i in range(int(input())): print(자기복제수(int(input()))) 겉멋만 든 영어 변수명을 거부합니다... 라기보다는 자기복제수를 어케 번역해야 적절한 변수명이 나올지 모르겠어서 그냥 한글로 했다.

players = [] for i in range(int(input())): players.append(list(reversed(list(map(int, input().split(" ")))))) players = sorted(players, reverse=True) printed_country = [] i = 0 while True: if printed_country.count(players[i][2]) < 2: print(players[i][2], players[i][1]) printed_country.append(players[i][2]) if len(printed_country) == 3: break i += 1 2차원 배열을 sort하면 0번째 인덱스를 기준으로 정렬된다. 사실 그냥 key를 사..

triangle_number = [n*(n+1)//2 for n in range(1, 45)] eureka = [0 for i in range(1001)] for i in triangle_number: for j in triangle_number: for k in triangle_number: if i+j+k