본문 바로가기
728x90

BOJ9

[Java]기본형 변수 크기 및 범위 https://www.acmicpc.net/problem/10986 10986번: 나머지 합 수 N개 A1, A2, ..., AN이 주어진다. 이때, 연속된 부분 구간의 합이 M으로 나누어 떨어지는 구간의 개수를 구하는 프로그램을 작성하시오. 즉, Ai + ... + Aj (i ≤ j) 의 합이 M으로 나누어 떨어지는 (i, j) www.acmicpc.net 10986. 나머지 합 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringT.. 2023. 6. 17.
[알고리즘개념]구간합 11659. 구간 합 구하기 4 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWr.. 2023. 6. 15.
[백준]230410-230416 문제풀이(Python) 1774. 우주신과의 교감 import sys input = sys.stdin.readline def find(x): if parents[x] != x: parents[x] = find(parents[x]) return parents[x] def union(x, y): x = find(x) y = find(y) if x < y: parents[y] = x else: parents[x] = y N, M = map(int, input().split()) gods = [] for _ in range(N): r, c = map(int, input().split()) gods.append((r, c)) dist = [[0] * (N + 1) for _ in range(N + 1)] for i in range(N).. 2023. 4. 20.
[백준]230403-09 문제풀이(Java) 10809. 알파벳 찾기 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] arr = new int[26]; for(int i = 0; i < arr.length; i++) { arr[i] = -1; } String S = in.nextLine(); for(int i = 0; i < S.length(); i++) { char ch = S.charAt(i); if(arr[ch - 'a'] == -1) { arr[ch - 'a'] = i; } } for(int val : arr) { System.out.print(val + " .. 2023. 4. 9.
[백준]230403-09 문제풀이(Python) 9328. 열쇠 from collections import deque import sys input = sys.stdin.readline dy = [-1, 1, 0, 0] dx = [0, 0, -1, 1] def bfs(y, x): global ans q = deque() q.append((y, x)) visited = [[False] * (w + 2) for _ in range(h + 2)] visited[y][x] = True while q: cnt = 0 now = q.popleft() for d in range(4): ny, nx = now[0] + dy[d], now[1] + dx[d] if ny h + 1 or nx w + 1: continue if .. 2023. 4. 9.
[백준]230403 문제풀이 10171. 고양이 public class Main { public static void main(String[] args) { System.out.println("\\ /\\"); System.out.println(" ) ( \')"); System.out.println("( / )"); System.out.println(" \\(__)|"); } } 첫 자바 코드 제출기념! 패키지 제외, 메인 클래스는 포함해서 제출한다 2023. 4. 3.
[백준]230327-0402 문제풀이 21278. 호석이 두마리 치킨 from collections import deque import sys input = sys.stdin.readline N, M = map(int, input().split()) adj = [[0] * (N + 1) for _ in range(N + 1)] ans = (0, 0, 1e10) for i in range(M): a, b = map(int, input().split()) adj[a][b] = adj[b][a] = 1 def bfs(n): q = deque() q.append((n, 1)) visited = [n] while q: now, c = q.popleft() for nxt in range(1, N + 1): if adj[now][nxt] == 1 and.. 2023. 4. 3.
[백준]230320-26 문제풀이 23843. 콘센트 import heapq import sys input = sys.stdin.readline N, M = map(int, input().split()) lst = list(map(int, input().split())) lst.sort() q = [] temp = [] ans = 0 while lst: now = lst.pop() heapq.heappush(q, now) if len(q) == M: out = heapq.heappop(q) ans += out for i in range(M - 1): q[i] -= out while q and q[0] == 0: heapq.heappop(q) if q: ans += max(q) print(ans) 힙을 콘센트로 두고 전자기기를 하나씩 넣어.. 2023. 3. 26.
[백준]230313-19 문제풀이 1107. 리모컨 import sys input = sys.stdin.readline def dfs(i, c): if i == len(str(N)): lst.append(c) return cnt = 0 now = int(str(N)[i]) while cnt 0 and now - cnt in fine: dfs(i + 1, c + str(now - cnt)) if now < 9 and now + cnt in fine: dfs(i + 1, c + str(now + cnt)) cnt += 1 N = int(input()) M = int(input()) broken = list(map(int, input().split())) fine = [] for i in range(10): if i.. 2023. 3. 21.
728x90