STUDY/Algorithm 402

[SWEA] 2105. [모의 SW 역량테스트] 디저트 카페

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5VwAr6APYDFAWu SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com import sys sys.stdin = open("swea_2105.txt", "r") T = int(input()) for tc in range(1, 1 + T): N = int(input()) matrix = [list(map(int,input().split())) for _ in range(N)] answer = -1 # [1,1], [1,2],[2,1], ~, [1,19], ~ ,[19,1..

STUDY/Algorithm 2021.07.29

[백준] 1912 연속합, python, C

https://www.acmicpc.net/problem/1912 1912번: 연속합 첫째 줄에 정수 n(1 ≤ n ≤ 100,000)이 주어지고 둘째 줄에는 n개의 정수로 이루어진 수열이 주어진다. 수는 -1,000보다 크거나 같고, 1,000보다 작거나 같은 정수이다. www.acmicpc.net N = int(input()) nums = list(map(int, input().split())) dp = [-200000000 for _ in range(N + 1)] for i in range(N): dp[i + 1] = max(dp[i] + nums[i], nums[i]) print(max(dp)) 처음엔 슬라이딩 윈도우라고 생각해서 브루트포스 방식으로 접근했는데 시간초과가 나왔다. O(N^2) 그래..

STUDY/Algorithm 2021.07.27

[백준] 18352 특정 거리의 도시 찾기 python

https://www.acmicpc.net/problem/18352 18352번: 특정 거리의 도시 찾기 첫째 줄에 도시의 개수 N, 도로의 개수 M, 거리 정보 K, 출발 도시의 번호 X가 주어진다. (2 ≤ N ≤ 300,000, 1 ≤ M ≤ 1,000,000, 1 ≤ K ≤ 300,000, 1 ≤ X ≤ N) 둘째 줄부터 M개의 줄에 걸쳐서 두 개 www.acmicpc.net import sys; input = sys.stdin.readline from collections import deque N, M, K, X = map(int, input().split()) linked_list = [list() for _ in range(N + 1)] for i in range(M): s, e = map..

STUDY/Algorithm 2021.07.27

[백준] 16236 아기 상어, python

https://www.acmicpc.net/problem/16236 16236번: 아기 상어 N×N 크기의 공간에 물고기 M마리와 아기 상어 1마리가 있다. 공간은 1×1 크기의 정사각형 칸으로 나누어져 있다. 한 칸에는 물고기가 최대 1마리 존재한다. 아기 상어와 물고기는 모두 크기를 가 www.acmicpc.net import sys; input = sys.stdin.readline from collections import deque def search(start, size, board): d = [(-1, 0), (0, -1), (0, 1), (1, 0)] ret = [] visit = [[-1 for _ in range(N)] for _ in range(N)] visit[start[0]][sta..

STUDY/Algorithm 2021.07.22

[백준] 20057 마법사 상어와 토네이도 python

https://www.acmicpc.net/problem/20057 20057번: 마법사 상어와 토네이도 마법사 상어가 토네이도를 배웠고, 오늘은 토네이도를 크기가 N×N인 격자로 나누어진 모래밭에서 연습하려고 한다. 위치 (r, c)는 격자의 r행 c열을 의미하고, A[r][c]는 (r, c)에 있는 모래의 양을 www.acmicpc.net import sys; input = sys.stdin.readline def sand_move(pos, direction_ind, matrix): rate = [2, 10, 7, 1, 5, 10, 7, 1, 2] sand_matrix = [ [(-2, 0), (-1, -1), (-1, 0), (-1, 1), (0, -2), (1, -1), (1, 0), (1, 1)..

STUDY/Algorithm 2021.07.20

[프로그래머스] 캐시, 2018 KAKAO BLIND RECRUITMENT[1차], python

https://programmers.co.kr/learn/courses/30/lessons/17680?language=python3# = cacheSize: cache_set.remove(cache.popleft()) if cacheSize: cache_set.add(city) cache.append(city) answer += 5 return answer set 을 사용해서 중복이 있는지 확인했다. 그리고 deque를 사용하여 사용된 값은 맨뒤로 보내는 작업을 했다. 더보기 from collections import deque def solution(cacheSize, cities): answer = 0 cache = deque() for i in range(len(cities)): city = cit..

STUDY/Algorithm 2021.07.19

[프로그래머스] 쿼드압축 후 개수 세기, 월간 코드 챌린지 시즌1, python

https://programmers.co.kr/learn/courses/30/lessons/68936?language=python3 코딩테스트 연습 - 쿼드압축 후 개수 세기 [[1,1,0,0],[1,0,0,0],[1,0,0,1],[1,1,1,1]] [4,9] [[1,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[0,0,0,0,1,1,1,1],[0,1,0,0,1,1,1,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,0,1],[0,0,0,0,1,0,0,1],[0,0,0,0,1,1,1,1]] [10,15] programmers.co.kr def solution(arr): # 분할 정복 answer = devideAndConquer(0,0,arr,len(arr)) return an..

STUDY/Algorithm 2021.07.18

[백준] 1916 최소비용 구하기 python

https://www.acmicpc.net/problem/1916 1916번: 최소비용 구하기 첫째 줄에 도시의 개수 N(1 ≤ N ≤ 1,000)이 주어지고 둘째 줄에는 버스의 개수 M(1 ≤ M ≤ 100,000)이 주어진다. 그리고 셋째 줄부터 M+2줄까지 다음과 같은 버스의 정보가 주어진다. 먼저 처음에는 그 www.acmicpc.net import sys; input = sys.stdin.readline from heapq import heappop, heappush inf = 100000000 # 최대값 (max(N)-1) * max(w) N = int(input()) # 1000 M = int(input()) # 100000 link_list = [list() for _ in range(N ..

STUDY/Algorithm 2021.07.15

[백준] 14503 로봇 청소기 python, C

https://www.acmicpc.net/problem/14503 14503번: 로봇 청소기 로봇 청소기가 주어졌을 때, 청소하는 영역의 개수를 구하는 프로그램을 작성하시오. 로봇 청소기가 있는 장소는 N×M 크기의 직사각형으로 나타낼 수 있으며, 1×1크기의 정사각형 칸으로 나누어 www.acmicpc.net import sys; input=sys.stdin.readline N, M = map(int, input().split()) r, c, d = map(int, input().split()) room = [list(map(int, input().split())) for _ in range(N)] clean = [[0 for _ in range(M)] for _ in range(N)] directi..

STUDY/Algorithm 2021.07.13

[백준] 2108 통계학, python

https://www.acmicpc.net/problem/2108 2108번: 통계학 첫째 줄에 수의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. 입력되는 정수의 절댓값은 4,000을 넘지 않는다. www.acmicpc.net import sys; input = sys.stdin.readline N = int(input()) # counting sort count = [0] * 8001 total = 0 for i in range(N): num = int(input()) count[num + 4000] += 1 total += num index = 0 mid = 0 mid_chk = False min_val = 0 min_chk = ..

STUDY/Algorithm 2021.07.11