목록문제/백준_파이썬 (155)
sm 기술 블로그
import sys input = sys.stdin.readline N = int(input()) paper = [list(map(int, input().split())) for _ in range(N)] result = [] def find(x, y, N): color = paper[x][y] for i in range(x, x+N): for j in range(y, y+N): if color != paper[i][j]: find(x, y, N//2) find(x, y+N//2, N//2) find(x+N//2, y, N//2) find(x+N//2, y+N//2, N//2) return if color == 0: result.append(0) else: result.append(1) find(0, 0..
from collections import deque import sys input = sys.stdin.readline T = int(input()) for _ in range(T): p = list(input().rstrip()) n = int(input()) x = input() x = x.replace("[", "") x = x.replace("]", "") x = x.replace(",", " ") queue = deque(list(x.split())) R_cnt = 0 error = False for val in p: if val == 'R': R_cnt += 1 continue if val == 'D' and len(queue) == 0: error = True break else: if R..
from collections import deque from operator import indexOf import sys input = sys.stdin.readline N, M = map(int, input().split()) num = deque(i for i in range(1, N+1)) innum = deque(list(map(int, input().split()))) cnt = 0 while True: if num[0] == innum[0]: num.popleft() innum.popleft() if innum: continue else: break if len(num) // 2 >= num.index(innum[0]): while num[0] != innum[0]: num.append(n..
from collections import deque import sys input = sys.stdin.readline N = int(input()) queue = deque([]) result = [] for _ in range(N): tmp = list(input().split()) S = '' num = 0 if len(tmp) == 1: S = tmp[0] else: S = tmp[0] num = int(tmp[1]) if S == 'push_back': queue.append(num) elif S == 'push_front': queue.appendleft(num) elif S == 'pop_front': if queue: result.append(str(queue.popleft())) els..