Finding Shortest Paths with Alternating Edge Colors in Directed Graphs
Given a directed graph with nodes labeled 0 through n-1, where edge are colored either red or blue and may include self-loops and parallel edges.
Each [i, j] pair in red_edges represents a red directed edge from node i to node j. Similarly, each [i, j] pair in blue_edges represents a blue directed edge from node i to node j.
Compute an array re ...
Posted on Wed, 03 Jun 2026 17:06:15 +0000 by sharyn
Maximum Sum Divisible by Three
Given an integer array nums, find and return the maximum sum of elements that is divisible by three.
Examples
Example 1:
Input: nums = [3,6,5,1,8]
Output: 18
Explanation: Choose numbers 3, 6, 1, and 8. Their sum is 18 (the maximum sum divisible by three).
Example 2:
Input: nums = [4]
Output: 0
Explanation: 4 is not divisible by 3, so no number ...
Posted on Tue, 02 Jun 2026 17:22:57 +0000 by JamesThePanda
Contest Problem Solutions: Factorization, Rays, String Construction, and Tree Partitioning
Factorization into Factorial Divisors
Given integers (n) and (m) where (1 \le m \le n!) and (n \le 20), decompose (m) into a sum of at most (n) divisors of (n!). A solution is guaranteed to exist.
Define a sequence (d_i = \frac{n!}{i!}) for (i) from 1 to (n). By iterating downwards from (i=n) to (1) and greedily subtracting the largest possible ...
Posted on Mon, 01 Jun 2026 17:41:27 +0000 by taldos
Programming Contest Solutions and Algorithm Explanations
A. Programming Contest
This problem is a straightforward implementation task. The idea is to count the number of valid years betweeen two given years, excluding specific invalid years provided in the input.
void solve() {
int n, m;
std::cin >> n;
std::vector<int> invalidYearFlag(10000, 0); // Assuming a safe upper bound ...
Posted on Mon, 01 Jun 2026 17:35:16 +0000 by czs
Dynamic Programming: Solving Multi-State Problems
The Massage Therapist Scheduling Problem
Problem link: https://leetcode.cn/problems/the-masseuse-lcci/
A renowned massage therapist receives a continuous stream of appointment requests. Each appointment can be accepted or declined. Due to the need for rest periods between sessions, she cannot accept consecutive appointments. Given a sequence of ...
Posted on Sat, 30 May 2026 19:39:23 +0000 by stelthius
Algorithmic Solutions for Seasonal Contender Selection Examination
Problem A: String Substitution Logic
Process a single input line character by character. Output each character sequentially. If the current character is a dot, append the string xixixi. to the output stream immediately.
#include <iostream>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
...
Posted on Wed, 27 May 2026 22:34:47 +0000 by sander_ESP
Tree Divide and Conquer: Point, Edge, and Divide Tree Techniques
Point and Edge Divide and Conquer
Point and edge divide and conquer are algorithmic techniques that extend the concept of sequence divide and conquer to tree structures. The core idea involves selecting a "center" (a node or an edge) to partition the tree into smaller, independent sub-problems. To ensure efficiency and balance, we spe ...
Posted on Wed, 27 May 2026 16:26:54 +0000 by dakkonz
Competitive Programming Contest Solutions: Segment Trees and Combinatorial Optimization
Problem 1: Maximum Goals and Assists
Problem Overview
Given two arrays representing goals and assists for multiple players, process queries that ask for the maximum total balls needed under different matching scenarios.
Key Observations
The problem essentially asks for the maximum value among three distinct scenarios:
Scenario 1: Each assist ca ...
Posted on Sun, 24 May 2026 16:31:07 +0000 by KingIsulgard
Interval DP Solution for Zuma-like Ball Elimination Problem
The elimination rule—removing consecutive identical elements when their count reaches a threshold $k$—suggests an interval dynamic programming approach. A two-dimensional DP state is insufficient because it cannot capture how the leftmost element in a segment is eventually removed. To resolve this, we introduce a third dimension that tracks how ...
Posted on Sat, 23 May 2026 20:25:04 +0000 by joukar
Solutions for the SXJ202507250900 Simulation Contest
Problem 1: Dumpling Purchase Optimization
The problem reduces to a daily deciison: buy dumplings at the current price or rely on an earlier purchase plus storage cost. The total expense for day i if we buy on day j ≤ i is price[j] + c*(i - j). This can be rewritten as (price[j] - c*j) + c*i. Thus we can maintain the minimum value of price[j] - ...
Posted on Sat, 23 May 2026 19:20:05 +0000 by d_barszczak