목록분류 전체보기 (165)
현제의 현재이야기

from collections import deque a = int(input()) current = deque(map(int, input().split())) cnt = 1 solo_count = 0 # 한줄로 서있는 스택의 개수 while cnt = 1 and current[-1] == cnt: current.pop() solo_count -= 1 cnt += 1 else: if solo_count == len(current): if current[-1] != cnt: print('Sad') break current.ro..

import sys input = sys.stdin.readline def bomb(map, R, C): for i in range(R): for j in range(C): if map[i][j] == '.': map[i][j] = 'O' elif map[i][j] == 'O': map[i][j] = '1' if j > 0: map[i][j - 1] = '1' if j 0: map[i - 1][j] = '1' if i < R - 1 and map[i + 1][j] != 'O': map[i + 1][j] = '1' for i in range(R): for j in range(C): if map[i]..

첫번째 try: from collections import deque n = int(input()) scores = [] time = 0 result = 0 resister = [] for i in range(n): a = deque(map(int, input().split())) if a[0] == 1: if time == 0: time = a[2] - 1 scores.append(a[1]) if time == 0: result += scores.pop() else: resister.append(time) time = a[2] - 1 scores.append(a[1]) if time == 0: result += scores.pop() else: if time == 0: result += scores.p..

from collections import deque n = int(input()) a = list(map(int, input().split())) a = deque(a) number = [ i + 1 for i in range(n) ] number = deque(number) results = [] pointer = 0 for i in range(n): pointer = a[0] a.popleft() pop = number.popleft() results.append(str(pop)) if pointer >= 0: a.rotate(-(pointer - 1)) number.rotate(-(pointer - 1)) elif pointer < 0: a.rotate(-(pointer)) number.rotat..

import sys from collections import deque input = sys.stdin.readline n, m, v = map(int, input().split()) # n: 노드개수 m: 질문 횟수 v: 가르키는 노드 a = list(map(int, input().split())) cut_a = a[:] cut_a = deque(cut_a) result = [] for _ in range(v - 1): cut_a.popleft() for _ in range(m): question = int(input()) if question < n: result.append(a[question]) else: question -= v - 1 question = question % len(cut_a)..

from collections import deque n, k = tuple(map(int, input().split())) a = [ i + 1 for i in range(n) ] a = deque(a) results = [] while len(a) != 0: a.rotate(-(k - 1)) pop = a.popleft() results.append(pop) print('') 덱의 로테이트를 이용하니깐 매우 깔끔하게게 되었다. | 알고리즘 n, k 받고 1 ~ n까지의 수가 담긴 덱을 생성 a가 빌 때까지 k - 1 번 왼쪽으로 로테이트하고 popleft 의의로 리스트 [] 를 로 바꾸는 것이 어려웠다. 파이썬 * unpacking 관련 정보 그리고 deque는 pop연산 중 특정한 위치의 값을 po..