STUDY/Algorithm 402

[백준] 16234 인구 이동 python(pypy3)

https://www.acmicpc.net/problem/16234 16234번: 인구 이동 N×N크기의 땅이 있고, 땅은 1×1개의 칸으로 나누어져 있다. 각각의 땅에는 나라가 하나씩 존재하며, r행 c열에 있는 나라에는 A[r][c]명이 살고 있다. 인접한 나라 사이에는 국경선이 존재한다. 모 www.acmicpc.net import sys from collections import deque def bfs(r, c): visit[r][c] = 1 q = deque() q.append((r, c)) ret = [(r,c)] while q: y, x = q.popleft() for i in range(4): yy = y + dy[i] xx = x + dx[i] # 주어진 나라의 크기를 넘는 경우 if ..

STUDY/Algorithm 2021.07.08

[백준] 15686 치킨 배달, python

https://www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net import sys; sys.stdin.readline from itertools import combinations N, M = map(int, input().split()) _map = [] house = [] restaurant = [] for i in range(N): tmp = list(map(int, input().split())) _map.append(tmp) f..

STUDY/Algorithm 2021.07.06

[백준] 11054 가장 긴 바이토닉 부분 수열, python

https://www.acmicpc.net/problem/11054 11054번: 가장 긴 바이토닉 부분 수열 첫째 줄에 수열 A의 크기 N이 주어지고, 둘째 줄에는 수열 A를 이루고 있는 Ai가 주어진다. (1 ≤ N ≤ 1,000, 1 ≤ Ai ≤ 1,000) www.acmicpc.net N = int(input()) A = list(map(int, input().split())) dp_asc = [0 for _ in range(N)] dp_desc = [0 for _ in range(N)] for i in range(1, N): for j in range(0, i): if A[j] < A[i]: dp_asc[i] = max(dp_asc[i], dp_asc[j] + 1) for i in range(N..

STUDY/Algorithm 2021.07.05

[백준] 1780 종이의 개수, python

https://www.acmicpc.net/problem/1780 1780번: 종이의 개수 N×N크기의 행렬로 표현되는 종이가 있다. 종이의 각 칸에는 -1, 0, 1의 세 값 중 하나가 저장되어 있다. 우리는 이 행렬을 적절한 크기로 자르려고 하는데, 이때 다음의 규칙에 따라 자르려고 한다. www.acmicpc.net import sys input = sys.stdin.readline def devide(r, c, size): global m1, z, p1 if check(r, c, size): if paper[r][c] == -1: m1 += 1 elif paper[r][c] == 0: z += 1 else: p1 += 1 return # 분할 for i in range(r, r + size, si..

STUDY/Algorithm 2021.07.04

[프로그래머스] [3차] 방금그곡, 2018 KAKAO BLIND RECRUITMENT, python

https://programmers.co.kr/learn/courses/30/lessons/17683 코딩테스트 연습 - [3차] 방금그곡 방금그곡 라디오를 자주 듣는 네오는 라디오에서 방금 나왔던 음악이 무슨 음악인지 궁금해질 때가 많다. 그럴 때 네오는 다음 포털의 '방금그곡' 서비스를 이용하곤 한다. 방금그곡에서는 TV, programmers.co.kr def solution(m, musicinfos): answer = '' answer_playtime = 0 for info in musicinfos: # 문자열 파싱 s, e, title, melody = info.split(',') sh, sm = map(int, s.split(':')) sm_total = sh * 60 + sm eh, em =..

STUDY/Algorithm 2021.06.26

[프로그래머스 ] 압축, 2018 KAKAO BLIND RECRUITMENT[3차], python

https://programmers.co.kr/learn/courses/30/lessons/17684 코딩테스트 연습 - [3차] 압축 TOBEORNOTTOBEORTOBEORNOT [20, 15, 2, 5, 15, 18, 14, 15, 20, 27, 29, 31, 36, 30, 32, 34] programmers.co.kr def solution(msg): answer = [] # 1 사전 초기화 dic = dict(zip(map(chr, range(ord('A'), ord('Z') + 1)), range(1, 27))) msg_index, dic_index = 0, 27 while msg_index < len(msg): # 2 가장 긴 문자열 검색 tmp_ind = 1 while msg_index + ..

STUDY/Algorithm 2021.06.26

[프로그래머스] 2개 이하로 다른 비트,월간 코드 챌린지 시즌2, python, C

https://programmers.co.kr/learn/courses/30/lessons/77885 코딩테스트 연습 - 2개 이하로 다른 비트 programmers.co.kr def solution(numbers): answer = [0] * len(numbers) for i in range(len(numbers)): tmp = 1 while numbers[i] & tmp: tmp 1) return answer 월간 코드 챌린지 시즌 2를 참여했을땐 어떻게 풀어야하는지 잘 몰랐는데 다시 시간 잡고 푸니까 쉽게 풀렸다. 문제를 풀때 여러 단계로 규칙을 찾으려 노력했는데, 하위 두비트가 00,01,10 일경우 1을 더하면 되고 11인 경우 새로운 규칙을 찾는 것을 먼저 확인했다. 최하위 비트가 11 인경우..

STUDY/Algorithm 2021.06.25

[프로그래머스] 영어 끝말잇기, Summer/Winter Coding(~2018), python

https://programmers.co.kr/learn/courses/30/lessons/12981 코딩테스트 연습 - 영어 끝말잇기 3 ["tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"] [3,3] 5 ["hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"] [0,0] programmers.co.kr def solution(n, words): answer = [0, 0] word_se..

STUDY/Algorithm 2021.06.25

[프로그래머스] 배달, Summer/Winter Coding(~2018), python

https://programmers.co.kr/learn/courses/30/lessons/12978 코딩테스트 연습 - 배달 5 [[1,2,1],[2,3,3],[5,2,2],[1,4,2],[5,3,1],[5,4,2]] 3 4 6 [[1,2,1],[1,3,2],[2,3,2],[3,4,3],[3,5,2],[3,5,3],[5,6,1]] 4 4 programmers.co.kr from collections import deque def solution(N, road, K): INF = 5000000 g= [[] for _ in range(N + 1)] dist = [INF] * (N + 1) for i in range(len(road)): g[road[i][0]].append((road[i][1],road[i..

STUDY/Algorithm 2021.06.23