문제풀이

https://www.acmicpc.net/problem/16920 코드처음에 작성한 코드 => 시간 초과from collections import dequeimport sysinput = sys.stdin.readlinen, m, p = map(int, input().split())s = [0]+list(map(int, input().split()))board = [list(input()) for _ in range(n)]ans = [0]*(p+1)dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]castle = [[] for _ in range(p+1)]# 처음 성의 위치for i in range(n): for j in range(m): if board[i][j] !=..
https://www.acmicpc.net/problem/2493 코드n = int(input())towers = list(map(int, input().split()))stack = []ans = [0]*nfor i in range(n): while stack and stack[-1][0]  for문을 i까지 돌았을 때 stack에는 towers[i-1]와 그보다 큰 타워들만 저장되어 있다. i번째 타워는 스택에서 자신보다 작은 타워는 다 pop하고 스택의 top, 즉 자신보다 큰 타워의 인덱스+1을 ans[i]에 저장하면 된다. 문제의 테스트케이스로 예를 들자면,위의 예시에서는 높이가 4인 5번째 타워까지 왔을 때 스택에 저장된 타워는 바로 이전 타워인 4번과 그보다 더 큰 타워인 2번이다.그러..
https://www.acmicpc.net/problem/1254 코드s = input()def is_palindrome(string): for i in range(len(string)//2): if string[i] != string[len(string)-1-i]: return False return Truefor i in range(len(s)): new_s = s+(s[:i])[::-1] if is_palindrome(new_s): print(len(new_s)) break 주어진 문자열 S의 앞에서부터 1글자, 2글자,... 이렇게 떼어서 거꾸로 S 뒤에 붙여보며 팰린드롬인지 확인한다.
https://www.acmicpc.net/problem/14889 코드from itertools import combinationsn = int(input())ability = [list(map(int, input().split())) for _ in range(n)]ans = int(1e9)for start in combinations(range(n), n//2): start = set(start) link = set(range(n))-start # 스타트팀 능력치 start_ability = 0 for comb in combinations(list(start), 2): start_ability += (ability[comb[0]][comb[1]]+ability..
https://www.acmicpc.net/problem/1743 코드from collections import dequen, m, k = map(int, input().split())trash = [[False]*m for _ in range(n)]for _ in range(k): r, c = map(int, input().split()) trash[r-1][c-1] = Truevisited = [[False]*m for _ in range(n)]def bfs(x, y): res = 1 # 음식물 쓰레기 덩어리의 크기 dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] q = deque([(x, y)]) visited[x][y] = True w..
딜레이레이
'문제풀이' 카테고리의 글 목록 (6 Page)