Home
MINJUN PARK
Cancel

BOJ. Shortest path with specification (1504)

[Link] https://www.acmicpc.net/problem/1504 Approach In an undirected graph with positive edge weights, find the shortest route from vertex 1 to vertex N that visits both required vertices v1 and...

BOJ. Prefix Product (11505)

Problem Maintain an array under point assignments and answer the product of any inclusive range modulo 1,000,000,007. Since an update changes only one position, an iterative segment tree can recom...

BOJ. Shortest Path (1753)

Solution The graph is directed, so each edge is stored only in the adjacency list of its source. Dijkstra’s algorithm is valid because all edge weights are nonnegative. The distance array stores t...

Programmers. Network

Problem Approach The computers form an undirected graph: computers[i][j] === 1 means computer i can connect directly to computer j. The requested number of networks is the number of connected com...

BOJ. Bipartite Graph (1707)

Color the vertices of each test graph with two colors. A graph is bipartite exactly when every edge joins vertices of different colors. The graph may be disconnected, so start a breadth-first searc...

BOJ. Move the Knight (7562)

Problem link For each test case, find the minimum number of knight moves between two squares on an L × L chessboard. Each move changes one coordinate by 1 and the other by 2, with either sign, and...

LeetCode. 40. Combination Sum II

Link Approach Sort the candidates, then perform a depth-first search over their indices. Each recursive call chooses only a later index (i + 1), so an array occurrence can be used at most once....

AtCoder. 018 Statue of Chokudai(3)

Problem link Let r = L / 2. At elapsed time E, the wheel has turned through theta = 2π * (E mod T) / T radians, where T is its period. Wrapping the elapsed time by T keeps the angle within one rev...

AtCoder. 020 Log Inequality(3)

[Link] https://AtCoder.jp/contests/typical90/tasks/typical90_t import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Buffer...

AtCoder. 014 We Used to Sing a Song Together(3)

Problem link Given two arrays of N integers, pair every value in the first array with one value in the second so that the sum of absolute differences is minimized. Sort both arrays in nondecreasi...