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
Minimum Button Presses for a Strange Elevator
A building has an unusual elevator system. Each floor i (where 1 ≤ i ≤ N) has a fixed value K[i], which determines how many floors the elevator moves when the "up" or "down" button is pressed. The elveator can only move up by K[i] floors or down by K[i] floors from floor i. If the target floor would be below 1 or above N, th ...
Posted on Mon, 18 May 2026 01:53:57 +0000 by bobdabuilder
BFS on Parity-Based Reachability for a Single 1 in a Binary String
Spinning Around
Given a binary string (S) of length (n) with exactly one 1. In each operation, you can reverse a substring of length (k). For each position (i), find the minimum number of operations to move the 1 to position (i). Some positions are forbidden and cannot hold the 1 during the process. If no such number exists, output (-1).
(n \le ...
Posted on Fri, 15 May 2026 16:47:23 +0000 by Matt Kindig
Breadth-First Search: Practical Problem-Solving Patterns
Problem 1: Dual Container Water Measurement
This classic state-space search problem involves two containers with known capacities and an infinite water supply. The goal is to achieve a specific volume in one container through a series of operations.
Problem Analysis
The key insight is representing each state by the current water volumes in both ...
Posted on Mon, 11 May 2026 00:29:39 +0000 by cleary1981
Weekly Contest 357 Solutions
Problem 2810 - Faulty Keeyboard
Simulate the keyboard behavior as described. When encuontering character 'i', reverse the current string.
class Solution {
public:
string finalString(string input) {
string result = "";
for(char c : input) {
if(c == 'i') {
reverse(result.begin(), ...
Posted on Sun, 10 May 2026 02:00:36 +0000 by stone
Strange Elevator Problem (P1135) - BFS Solution
Problem Description
A dream once led to an unusual elevator that operates differently from typical ones. Each floor has a number K_i (0 ≤ K_i ≤ N), and the elevator can move up or down by exactly K_i floors when the corresponding button is pressed. The elevator has four buttons: open, close, go up, and go down.
Given a building with N floors, e ...
Posted on Sat, 09 May 2026 02:44:26 +0000 by cmp241
Foundations of Search: Classic Problems and Algorithmic Insights
A: Chessboard Rook Placement
Given an (n \times n) board where certain positions marked # allow placement, determine the number of ways to place (k) identical, non-attacking rooks. Constraints: (k \leq n \leq 8).
Since each row can hold at most one rook, a depth-first search over rows is feasible. The state space is bounded by ((n+1)^n), at mos ...
Posted on Thu, 07 May 2026 01:45:42 +0000 by benzrf