Binary Search for Rotated Arrays, Arrow Balloons, and Palindrome Partitioning

153. Minimum in Rotated Sorted Array Approach A rotated sorted array is formed by shifting elements from the end to the beginning. For instance, rotating [0,1,2,4,5,6,7] four times yields [4,5,6,7,0,1,2]. To find the minimum element efficiently, use binary search. Compare the middle element with the rightmost element: If arr[mid] < arr[righ ...

Posted on Wed, 05 Aug 2026 16:35:41 +0000 by fuzzy1

Competitive Programming Solutions: Niuke Summer Multi-School Training Camp 2024

Given an integer x, construct a y < x such that gcd(x, y) = x ⊕ y (bitwise XOR). The solution is to take y = x - lowestSetBit(x). If x is a power of 2, then no solution exists. #include<iostream> #include<cmath> using namespace std; using ll = long long; void solve() { ll x; cin >> x; ll lowest_bit = x & ...

Posted on Tue, 04 Aug 2026 16:19:06 +0000 by VLE79E

Applying Expected Value in Algorithm Design

Expected value is a fundamental concept in probability theory and statistics, used to describe the average or central tendency of data. In computer algorithm competitions, expected value algorithms are considered medium to advanced level, playing a crucial role in programming. In recent years, problems involving expectations and expectation dyn ...

Posted on Sat, 01 Aug 2026 16:42:30 +0000 by zak

Southwest University for Nationalities 2023 Programming Competition Selection Problems and Solutions

L1-1 Thank You, Karl! This problem requires outputting a specific formatted string. The output contains an emoticon with escaped backslashes. Reference Implementation #include <bits/stdc++.h> using namespace std; int main() { cout << "Thank You Karl!\\\\(>_<)/" << endl; return 0; } L1-2 It's Fantasy ...

Posted on Sat, 01 Aug 2026 16:26:03 +0000 by bender

2024 CAIP Undergraduate Division Programming Challenge Solution Overview

Overview of Selected Problems The following section outlines the algorithmic approaches and C++ implementations for specific tasks encountered during the undergraduate category of the 2024 competition. Each problem addresses distinct computational challenges ranging from string manipulation to graph optimization. Task 1: Character Compsoition V ...

Posted on Fri, 31 Jul 2026 16:27:01 +0000 by dotbands

USACO08MAR River Crossing S - Complete Knapsack and Interval DP Solutions

Problem Link Luogu P2904 [USACO08MAR] River Crossing S Approach 1: Copmlete Knapsack DP First, observe the problem constraints. We need to transport all (n) cows across the river, minimizing the total time. Suppose we make (k) trips, and on the (i)-th trip we take (a_i) cows. Then (a_1 + a_2 + \dots + a_k = n). This can be viewed as having (n) ...

Posted on Thu, 30 Jul 2026 16:26:47 +0000 by nblackwood

Essential Algorithms for Programming Competition Preparation

This collection presents fundamental algorithms and their applications to simple problems, primari sourced from the Lanqiao Cup competition. The problems are relatively straightforward, focusing more on algorithm templates and basic approaches. For better algorithm retention, the implementations are concise, frequently utilizing built-in C++ fu ...

Posted on Wed, 29 Jul 2026 16:32:20 +0000 by ThaboTheWuff

Efficient Algorithms for Dragon Slaying, Backpack Optimization, and Geometric Problems

Dragon Slayer Pathfinding with Binary Enumeration Coordinate scaling converts decimal start/end points to integers for grid processing. Binary enumeration efficiently searches all possible wall removal combinations. #include <iostream> #include <vector> #include <bitset> using namespace std; struct Barrier { int x_start, ...

Posted on Fri, 24 Jul 2026 17:13:22 +0000 by chreez

Maximum Subarray Sum Problem Solution

Problem Description Given a sequence of n integers a, find the maximum sum of any contiguous non-empty subarray. Input Specificatino The first line contains integer n indicating the sequence length. The second line contains n integers representing the sequence elements. Constraints: 1 ≤ n ≤ 2×10⁵, -10⁴ ≤ aᵢ ≤ 10⁴ Output Specification Output a s ...

Posted on Fri, 24 Jul 2026 17:01:37 +0000 by MK27

Optimizing Commute Time with Dynamic Programming and Nitro Boost

In this problem, we calculate the minimum time required to travel a distance $N$ with $M$ traffic lights, each having specific green and red durations. We are equipped with a "Nitrous Oxide" (Nitro) device that allows for instantaneous movement (teleportation) between traffic lights. However, this device cannot be used to cross zebra ...

Posted on Thu, 23 Jul 2026 16:52:20 +0000 by fiddler80