随笔分类 - CodeForces
摘要:Problem Link Based on initial observation, it seems that greedily pick the smallest row / column length works. But the last example test case outputs
阅读全文
摘要:Problem Statement 1. N is up to 35, so trying all possible subsequences is too slow (2^35). We can apply the meet in the middle technique and divide A
阅读全文
摘要:Problem Link Dp[i][j]: the number of possible ways from s[0, i] with the ith statement ending with indentation j. dp[0][0] = 1, the 1st statement must
阅读全文
摘要:A. Counting Kangaroos is Fun There can be only at most N / 2 hold and held pairs based the problem's statment. So a greedy approach is just to divide
阅读全文
摘要:Problem First I thought about modelling this problem as a directed graph, where between each pair of nodes, an edge represents a valid < > or > < tran
阅读全文
摘要:Problem S: the set of numbers said by player 1; P: the set of numbers said by player 2; S^2 * P = a; S * P^2 = b; a * b = (S * P)^3, so a * b must be
阅读全文
摘要:Problem Each fence is increased at most 2 times, so dp[i][j] is the min cost to make A[0, i] great with the last fence A[i] increased j times. The ans
阅读全文
摘要:Problem Key idea: 1. for any substring s, if we can do not consider padding prefix 0s, its decimal value is always >= its length. 2. Appending a binar
阅读全文
摘要:I have run into 2 different problems that can be solved using binary lifting. Then there is second thread's tree basics youtube video that talks about
阅读全文
摘要:Given 2 integers u and v, find the shortest array such that bitwise-xor of its elements is u, and the sum of its elements is v. Input The only line co
阅读全文
摘要:Primitive Primes : two integers are coprime if their GCD is 1. If a number A is not divisible by another prime number P, then A and P are guranteed to
阅读全文
摘要:An interesting problem using suffix sum. For each wrong tries that is correct until after index p[i], we add 1 to cnt[p[i]]. This represents that all
阅读全文
摘要:Problem Statement Link Clarification: The problem states that for each pair of points, we consider the minimum possible distance over any possible mom
阅读全文
摘要:Dynamic programming solution State: dp[i]: the minimum cost to cover all positions from[0, i]. (left shift by 1 to get 0 index) // if position i is al
阅读全文
摘要:Given an array that has n integers, count the number of ways to split all elements of this array into 3 contiguous parts so that the sum of each part
阅读全文
摘要:Consider a multiset of integers S, the union of n closed intervals of positive integers: S = [l1..r1] ∪ [l2..r2] ∪ · · · ∪ [ln..rn](recall that a clos
阅读全文
摘要:Smaller input size: https://codeforces.com/contest/1249/problem/D1 Big input size: https://codeforces.com/contest/1249/problem/D2 Given n segments on
阅读全文
摘要:Given n kinds of present and m boxes. Find out the different ways to pack all boxes with presents, using the following rules. 1. Each box can not have
阅读全文