Algorithmic Solutions for Programming Competition Problems

Everyone Loves to Sleep Convert all times to minutes and store in a sorted set. Use binary search to find the nearest alarm time. If no alarm exists after bedtime, calculate duration untill first alarm next day. #include <iostream> #include <set> #include <climits> using namespace std; void calculateSleepDuration() { int ...

Posted on Fri, 22 May 2026 16:54:24 +0000 by Salkcin

Four Tasks from a Beginner Contest: Permutation Duel, Sub-grid Matching, Hamiltonian Walks, and Optimal Chemical Blending

Task A – Permutation Duel A cyclic permutation maps [1\to2\to3\to\dots\to13\to1] Two players choose indices (x,y\in[1,13]). Compare the images (p(x)) and (p(y)); output the winner or "Draw". int main() { int x, y; std::cin >> x >> y; int px = (x == 13 ? 1 : x + 1); int py = (y == 13 ? 1 : y + 1); if (px == ...

Posted on Fri, 15 May 2026 19:42:06 +0000 by NathanLedet

AtCoder Regular Contest 104 Problem Solutions

Problem A: Plus Minus Given the sum and difference of two numbers, we can easily retrieve the original values. The first number is the average of the sum and difference, while the second is half of the difference subtracted from the sum. s, d = map(int, input().split()) print((s + d) // 2, (s - d) // 2) Problem B: DNA Sequence A substring is c ...

Posted on Fri, 15 May 2026 00:15:36 +0000 by ganich

Dynamic Programming Patterns for Knapsack Problems

01 Knapsack Problem Statement Given N items and a knapsack with capacity m, each item has a volume v[i] and value w[i]. Each item can be selected at most once. Determine which items to select so that the total volume does not exceed the knapsack's capacity and the total value is maximized. Approach Let dp[i][j] denote the maximum value achievab ...

Posted on Sun, 10 May 2026 13:24:38 +0000 by basdog22

AtCoder Beginner Contest 056 Solutions and Optimization Techniques

Problem A: Honest or Dishonest Two characters (a) and (b) are given, each either H (honest) or D (dishonest). Person A always tells the truth if (a = H), otherwise always lies. A states that B is honest if (b = H), or that B is dishonest if (b = D). Determine whether B is actually honest. Solution If A is dishonest ((a = D)), the statement is f ...

Posted on Thu, 07 May 2026 18:11:44 +0000 by shseraj