목록백준 (60)
컴공생의 다이어리
백준 관련 크롬 확장 프로그램(익스텐션) - submit_java, BOJ Extended 백준에서 문제를 풀면서 유용했던 크롬 익스텐션을 소개하려고 한다. submit_java submit_java 익스텐션은 백준이나 swea에서 Java 코드 제출시 맞춰줘야 할 포맷(백준: class Main, swea: class Soultion)을 맞춰주고 필요없는 패키지 경로를 삭제해준다. submit_java 알고리즘 사이트에서 java언어의 포맷을 맞춰줍니다! chrome.google.com BOJ Extended BOJ Extended 익스텐션은 아래와 같은 기능을 사용할 수 있었는데 이 중에 신기하고 자주 사용했던 기능은 채점 현황과 어두운 테마 기능이다. 채점 현황의 경우 몇 퍼센트까지 실행되었는지 항..
백준 16928번 : 뱀과 사다리 게임 (문제 바로가기) 내 코드 import sys from collections import deque input = sys.stdin.readline N, M = map(int, input().split()) # N: 사다리의 개수, M: 뱀의 개수 board = [0] * 101 # 사다리와 뱀의 위치를 저장할 리스트 for _ in range(N + M): x, y = map(int, input().split()) board[x] = y # 사다리와 뱀의 위치를 저장 visited = [0] * 101 # 방문 여부를 저장할 리스트 queue = deque([1]) # 시작점 while queue: x = queue.popleft() if x == 100: # 도..
백준 16954번 : 움직이는 미로 탈출 (문제 바로가기) 내 코드 import sys from collections import deque input = sys.stdin.readline wall_pos = set() # 벽 위치 for i in range(8): temp = input().rstrip() for j in range(8): if temp[j] == '#': wall_pos.add((i, j)) queue = deque([(7, 0)]) # 캐릭터 시작 위치 넣기 result = 0 direction = [(i, j) for i in range(-1, 2) for j in range(-1, 2)] # 이동할 수 있는 모든 방향 while queue and wall_pos: temp = s..
백준 16637번 : 괄호 추가하기 (문제 바로가기) 내 코드 N = int(input()) data = list(map(lambda x: int(x) if x.isdigit() else x, input())) result = -int(1e9) def calculate(num1, num2, s): # 연산자 s에 따라 계산처리 if s == '+': return num1 + num2 elif s == '-': return num1 - num2 elif s == '*': return num1 * num2 def dfs(idx, prev): global result if idx >= N: # 연산이 끝났을 때 result = max(result, prev) # 최댓값 갱신 return if idx + 3 <..
백준 17779번 : 게리맨더링 2 (문제 바로가기) 내 코드 import sys input = sys.stdin.readline def simulation(x, y, d1, d2): section = [0] * 5 # 구역별 인구 수 temp_c = y for r in range(x + d1): # 1구역 인구 합 구하기 if r >= x: temp_c -= 1 section[0] += sum(data[r][0:temp_c + 1]) temp_c = y - d1 - 1 for r in range(x + d1, n): # 3구역 인구 합 구하기 section[2] += sum(data[r][0:temp_c + 1]) if r < x + d1 + d2: temp_c += 1 temp_c = y + 1 fo..
백준 2023번 : 수들의 합 5 (문제 바로가기) 내 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class baekjoon_2023 { private static int N; private static StringBuilder sb = new StringBuilder(); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); N = Integer.parseInt(br.readLin..
백준 2018번 : 수들의 합 5 (문제 바로가기) 내 코드 n = int(input()) start, end = 1, 1 cnt, total = 0, 1 while end != n: if total n: # 합이 n보다 크면 앞에 수 빼기 total -= start start += 1 else: # 합이 n과 같으면 cnt += 1 end += 1 total += end print(cnt + 1) # 자기 자신도 포함
백준 6497번 : 전력난 (문제 바로가기) 내 코드 import sys input = sys.stdin.readline def find_parent(parent, x): if parent[x] != x: parent[x] = find_parent(parent, parent[x]) return parent[x] def union(parent, a, b): a = find_parent(parent, a) b = find_parent(parent, b) if a < b: parent[b] = a else: parent[a] = b while True: m, n = map(int, input().split()) # m: 집의 수, n: 길의 수 if m == 0 and n == 0: break parent =..
백준 1972번 : 놀라운 문자열 (문제 바로가기) 내 코드 import sys input = sys.stdin.readline while (text := input().rstrip()) != "*": check, length = False, len(text) for i in range(length-1): pairs = set() # D-쌍 for j in range(length-i-1): temp = text[j] + text[j+i+1] if temp in pairs: # 유일하지 않은 경우 print(f"{text} is NOT surprising.") check = True break else: pairs.add(temp) if check: break else: # 유일한 경우 print(f"{t..
백준 1043번 : 거짓말 (문제 바로가기) 내 코드 import sys input = sys.stdin.readline n, m = map(int, input().split()) # n : 사람의 수, m : 파티의 수 know_truth = set(map(int, input().split()[1:])) # 이야기의 진실을 아는 사람의 번호 party = [set(map(int, input().split()[1:])) for _ in range(m)] # 각 파티에 오는 사람의 번호 for _ in range(m): for p in party: # 각 파티에 대해 if p & know_truth: # 진실 아는 사람 있다면 know_truth |= p # 진실 아는 사람에 현재 파티에 있는 사람 추가 ..