전체 글
-
17404. [Python]RGB거리 2Python_알고리즘/Gold IV 2024. 9. 2. 20:35
1. 문제 https://www.acmicpc.net/problem/17404 2. 접근 방법 시간 제한: 0.5초메모리 제한: 128MBDP 3. 파이썬 코드 import sysinput = sys.stdin.readlineN = int(input())houses = []# 최소값 저장 변수result = 10**9# 집 마다 색에 대한 값for _ in range(N): houses.append(list(map(int,input().split())))# 빨, 파, 초 선택하는 범위for i in range(3): # dp 값 각각 0번 집 어느 색을 선택한지에 대한 초기화 dp = [[10**9] * 3 for _ in range(N)] # dp 첫 인덱스 값 갱신 dp[0..
-
6581. [Python]HTMLPython_알고리즘/Gold V 2024. 8. 26. 19:29
1. 문제 https://www.acmicpc.net/problem/6581 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB구현파싱 3. 파이썬 코드 import sysans = []# input으로 들어오는 대로 받기for words in sys.stdin: # 공백 제거하고 구분하여 리스트에 추가 for word in words.strip().split(): ans.append(word)# 정답 출력할 변수answer = ""# 리스트 안을 순회for an in ans: # 개행 태그인 경우 이때까지 저장한 문자 출력 후 초기화 if an == "": print(answer) answer = "" continue ..
-
2866. [Python]문자열 잘라내기Python_알고리즘/Gold V 2024. 8. 19. 18:17
1. 문제 https://www.acmicpc.net/problem/2866 2. 접근 방법 시간 제한: 1초메모리 제한: 256MB정렬 3. 파이썬 코드 import sysinput = sys.stdin.readline# 행, 열 길이R, C = map(int,input().split())# 문자열 받아옴words = [ list(map(str,input().strip())) for _ in range(R) ]# 문자 역순으로 저장new_words = []# 아래서부터 문자열을 저장for j in range(C): ans = "" for i in range(R-1,-1,-1): ans += words[i][j] new_words.append(ans)# 문자열 정렬new_wo..
-
1806. [Python]부분합Python_알고리즘/Gold IV 2024. 8. 19. 17:35
1. 문제 https://www.acmicpc.net/problem/1806 2. 접근 방법 시간 제한: 0.5초메모리 제한: 128MB투 포인터누적합 3. 파이썬 코드 N,S = map(int,input().split())numList = list(map(int,input().split()))left = 0right = 0# 누적합 구하는 변수total = 0# 최소 길이 측정minLength = 10**9# right 값이 끝에 도달할때까지while right = S: # S값보다 작아질때까지 left 값 더해나감 while total >= S: # right - left 길이 체크 check = right - left ..
-
2866. [Python]문자열 잘라내기Python_알고리즘/Gold V 2024. 8. 13. 18:46
1. 문제 https://www.acmicpc.net/problem/2866 2. 접근 방법 시간 제한: 1초메모리 제한: 256MB정렬 3. 파이썬 코드 import sysinput = sys.stdin.readline# 행, 열 길이R, C = map(int,input().split())# 문자열 받아옴words = [ list(map(str,input().strip())) for _ in range(R) ]# 문자 역순으로 저장new_words = []# 아래서부터 문자열을 저장for j in range(C): ans = "" for i in range(R-1,-1,-1): ans += words[i][j] new_words.append(ans)# 문자열 정렬new_wo..
-
[JavaScript] 크기가 작은 부분 문자열JavaScript_알고리즘 2024. 8. 7. 21:36
1. 문제 https://school.programmers.co.kr/learn/courses/30/lessons/147355 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 2. 자바스크립트 코드 function solution(t, p) { let answer = 0 let cnt = 0 // p 길이 체크 pLength = p.length // t 길이 - p 길이 까지 반복문 진행 for (let i = 0; i 3. 문제를 풀고난 후 생각 문자열 슬라이싱을 진행하여 문자열을 자른 후 Number 혹은 parseInt로..
-
[JavaScript] 대충 만든 자판JavaScript_알고리즘 2024. 8. 7. 21:26
1. 문제 https://school.programmers.co.kr/learn/courses/30/lessons/160586 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 2. 접근 방법 시간 제한: 1초메모리 제한: 128MB구현 3. 자바스크립트 코드 function solution(keymap, targets) { let answer = [] // 목표가 되는 값을 탐색 for (target of targets) { // 총 몇번의 횟수를 눌러야는지 체크 let total = 0 // 한 문자씩 ..
-
14891. [Python]톱니바퀴Python_알고리즘/Gold V 2024. 8. 7. 21:24
1. 문제 https://www.acmicpc.net/problem/14891 2. 접근 방법 시간 제한: 2초메모리 제한: 512MB구현시뮬레이션 3. 파이썬 코드 import sysfrom collections import deque# 시계 방향 회전def right(target): check = matrix[target].pop() matrix[target].appendleft(check)# 반시계 방향 회전def left(target): check = matrix[target].popleft() matrix[target].append(check)# 연결된 톱니바퀴 체크def DFS(start,dir): # 방문처리를 통해 연결된 톱니바퀴 회전 visited = [..
-
2589. [Python]보물섬Python_알고리즘/Gold V 2024. 8. 6. 18:22
1. 문제 https://www.acmicpc.net/problem/2589 2. 접근 방법 시간 제한: 1초메모리 제한: 512MB너비 우선 탐색 3. 파이썬 코드 from collections import dequeimport sysinput = sys.stdin.readline# 방향 탐색direction = [(0,-1), (-1,0), (0,1), (1,0)]# 너비 우선 탐색def BFS(x,y): global max_value visited = [ [0] * M for _ in range(N) ] visited[x][y] = 1 queue = deque([(x,y)]) while queue: check = queue.popleft() fo..
-
14888. [Python]연산자 끼워넣기Python_알고리즘/Silver I 2024. 7. 31. 19:17
1. 문제 https://www.acmicpc.net/problem/14888 2. 접근 방법 시간 제한: 2초메모리 제한: 512MB브루트 포스백트래킹 3. 파이썬 코드 def backtracking(index): global N global min_value global max_value # 백트래킹 마지막 도달 if index == N-1: # 추가되지 않은 마지막 숫자 추가 ans.append(num_list[index]) # 초기 계산값으로 0번 인덱스 숫자 check = num_list[0] # 현재 리스트 길이 측정 list_length = len(ans) # 총 길이가 숫자 리..