Feel free to follow my progress on my main online judge profiles:
· #strings · #divide-&-conquer · #ad-hoc · #miscellaneous · #data-structures · #geometry · #brute-force · #graphs · #greedy · #math · #dynamic-programming ·
- 🙂 uva/10943
- 😳 uri/2699:
given a 1000-digit number S with some digits hidden, determine the minimum S possible such that S % N == 0
- 😳 codeforces/166-E
- 🙂 timus/1225
- 😳 codeforces/608-C
- 🙂 uva/10911 → use bitmasks
- 🙂 uva/10337
- 🙂 spoj/RPLB
- 😳 uva/10721
- 🙂 uva/11450
- 🙂 spoj/LINEUP → use bitmask
- 🙂 kattis/narrowartgallery:
narrow art gallery
- 🙂 uva/11000
- 🙂 uva/10003
- 😳 uva/10651 → use bitmask
- 🙂 spoj/TRT → don't memoize the current day
- 😳 codeforces/1061-C → use space saving + all divisors in O(sqrt(n)) to optimize
- LCS reduced to LIS
- 0-1 knapsack
- 🙂 uva/990:
with recovering
- 😳 uva/10261:
as if there were 2 knapsacks to fill at the same time; with recovering
- 🙂 spoj/KNAPSACK
- 😳 uri/1487
- 🙂 spoj/SCUBADIV
- 😳 spoj/FISHER:
get the (min) total value and total weight of the optimal knapsack
- 🙂 uri/2498
- 🙂 uva/990:
- coin change
- 🙂 codeforces/189-A
- 😳 uva/166:
coin change with limited amount of coins + greedy coin change with unlimited amount of coins; I don't know why, but it works without memo
- 🙂 uva/11407 → consider the coins as the perfect squares
- longest common subsequence (LCS)
- 🙂 spoj/IOIPALIN:
given a string, determine the minimal quantity of characters to be inserted into it in order to obtain a palindrome
→ compute length of string minus lcs between string and reversed string - 🙂 spoj/ADASEQEN
- 🙂 spoj/IOIPALIN:
- digit
- 😳 uri/1707:
given two numbers x and y, compute the sum of the decimal digits of the odd numbers in the range [min(x,y) .. max(x,y)]
- 🙂 spoj/CPCRC1C
- 😳 uri/1707:
- max 1D range sum
- kadane
- max 2D range sum
- longest increasing subsequence (LIS)
- longest palindromic subsequence (LPS)
- traveling salesman problem (TSP)
- subset sum
- 🙂 uri/1203:
check if any subset of A has a sum equal to K
- 😳 uva/10616:
given an array of size N, count how many subsets of size M have their sum divisible by D
→ use module arithmetic - 😳 uva/11658:
find the smallest sum s of a subset of A, s >= S
→ scan as %d.%d - 😳 uri/2089 → optimize memory
- 🙂 uva/624:
print the subset of A with the max sum k, k <= K
- with repetition
- 🙂 uri/1203:
- number theory
- 😳 uri/2291:
print n-th divine number, the one that is equal to the sum of the sum of each divisor from 1 to n
→ think like sieve - 😳 uva/547:
find the longest DDF sequence
→ pre-process a array f, where f[i] is the sum of digits of all positive factors of i; think like sieve - greatest common divisor (GCD)
- 🙂 codeforces/822-A
- 😳 codeforces/75-C:
find the gcd(a, b) that is in a query range [lo .. hi]
→ note that all divisors of gcd(a, b) are also divisors of a and b - 🙂 codeforces/854-A:
given n, determine maximum possible proper (a < b) and irreducible fraction a/b such that a+b == n
- module arithmetic
- prime numbers
- 🙂 spoj/PRIONPRI:
prime checking
- sieve of eratosthenes
- 😳 uva/10539:
compute the quantity of non-prime numbers in [lo .. hi] which are divisible by only a single prime number, 0 < lo <= hi < 10^12
→ generate all powers of each prime number - 🙂 spoj/AMR11E:
print the n-th number that has at least 3 distinct prime factors
→ use modified sieve - 😳 codeforces/576-A
- 🙂 codeforces/230-B:
check if a large n has exactily three distinct positive divisors
→ check if sqrt(n) is prime - 😳 spoj/PRIME1:
print all primes p in [m .. n], 0 <= m <= n <= 10^9, n-m <= 10^5
→ sieve + prime checking
- 😳 uva/10539:
- prime factorization
- 🥵 uri/2661:
compute the number of divisors of n that can be written as the product of two or more distinct prime numbers (without repetition), 1 <= n <= 10^12
→ note that the product of any combination of prime factors of a number will always be a divisor of that number - 🙂 uva/10042
- 😳 uva/10139:
do n! is divisible by m?
→ check if the prime factors of m are contained in the prime factors of n!
- 🥵 uri/2661:
- 🙂 spoj/PRIONPRI:
- 😳 uri/2291:
- matrix exponentiation
- 🙂 uva/10229 → transform the fibonacci recurrence into a matrix exponentiation
- game theory
- minimax
- 😳 uva/12484:
alberto and wanderley take one of two cards at the edges of the cards sequence, alberto want maximize it
→ fill memo table in row-major order - 😳 uva/10111:
given a state of a tic tac toe board, check if X will win independent of the O movement
→ minimax + memo + backtracking - optimized
- 🥵 uva/847:
multiplication game
→ note that if Stan always multiply by 9 and Ollie by 2, it's still an optimal solution
- 🥵 uva/847:
- 😳 uva/12484:
- minimax
- ad-hoc
- 🙂 uva/11723
- 🙂 codeforces/1042-A
- 🙂 uva/10110:
check if the number of divisors of n is odd
→ check if n is a perfect square - 😳 codeforces/573-A
- 🙂 uva/10346
- 🙂 codeforces/16-C
- 🙂 uva/12791
- 🙂 uva/10812
- 🙂 uva/11875
- sequences
- arithmetic progression
- finding pattern
- 🙂 codeforces/1324-A
- 🙂 spoj/EIGHTS
- 🙂 codeforces/1221-C
- 😳 uva/10161
- 🥵 uva/11718 → compute K * N^(K-1) * sumA using fast power mod
- 😳 codeforces/1092-D1 → remove adjacent ones whose absolute difference is even (using a stack)
- combinatorics
- 🙂 codeforces/459-B:
find the max difference between numbers of a given array and the number of ways to get it
- 🙂 codeforces/131-B
- combinations
- multi-combinations
- 😳 codeforces/630-G → C(n+5-1,5) * C(n+3-1,3)
- binomial coefficient
- 🥵 uri/2972:
calculate the sum of C(N, k)%2 for all k in [0 .. n], i.e., how many odd combinations of k heads between n coins there are
→ just compute 2^qtyBitsOn(n) - 🙂 codeforces/844-B
- 🥵 uri/2972:
- multi-combinations
- 🙂 codeforces/459-B:
- 🙂 codeforces/1360-C
- 🙂 code-jam/2020-QR-nesting-depth
- 😳 code-jam/2020-1A-pattern-matching
- 🙂 codeforces/1257-A
- 🙂 codeforces/1324-B:
given a sequence of integers, is there a subsequence palindrome of size 3?
→ check if there are two equal non-adjacent numbers using brute force - 🙂 codeforces/1324-C → note that it's unnecessary jump to the left, so to minimize d, just jump between the nearest 'R' cells
- 🙂 uva/11491:
remove D digits from the given number, in a such way that the remain number is maximum
- 😳 uva/11240:
length of the longest inc/dec (alternating) subsequence
- 😳 codeforces/1237-C2 → sort the points, remove pairs with equal x and y first, then pairs with equal x and finally the rest
- 😳 codeforces/204-B:
given the two-sided values of N cards, what is the minimum number of turns in the cards so that at least half of them are the same front?; they are initially facing upwards
- 🙂 code-jam/2020-QR-parenting-partnering-returns
- 🙂 spoj/SNGINT:
given an integer n, find the smallest positive integer m > 0 such that the product of digits of m equals n
- 🙂 codeforces/275-C
- 🙂 spoj/BUSYMAN:
compute the maximum number of activities (each with start and end times) that you can do without overlapping them (one at a time)
→ sort the activites by increasing end time - 🙂 spoj/GERGOVIA
- 🙂 spoj/CADYDIST
- 🙂 codeforces/545-D
- 🙂 uva/10954:
add all
- 🙂 codeforces/1092-B
- 🙂 codeforces/984-A
- loading balance
- interval covering
- 😳 uva/10382 → reduce the problem using pythagoras to one line
- bipartite matching
- restrict coin change
- maximum flow
- shortest path
- all-pairs
- 🙂 uri/2372
- single-source
- negative-weighted and cycle graph
- 😳 at-coder/ABC137-E:
longest distance from 0 to V-1, checking for positive cycle that are part of that path (0 to V-1)
- 😳 at-coder/ABC137-E:
- weighted graph
- 😳 uva/11833 → build the graph already with the given constraints
- 😳 uva/12144:
almost shortest path
- 🥵 live-archive/3652:
dijkstra on a given implicit graph as a 2D grid
- 😳 uva/10806:
find the global shortest path from 0 to V-1 (round trip), without repeting edges
- 🥵 uva/11367 → find the shortest path on state-space graph, where each vertex represent a city and a level of car fuel
- unweighted graph
- 😳 uva/12797 → apply a BFS for each subset of letters possible (only 2^10) using bitmask
- negative-weighted and cycle graph
- all-pairs
- minimum spanning tree (MST)
- traversal
- 😳 uva/11906 → consider grid as an implicit graph and walk through it avoiding redundant positions (nr, nc)
- 🙂 uva/11831 → consider grid as an implicit graph and walk through it, or just rotate the robot, for each received instruction
- 😳 code-jam/2020-1A-pascal-walk-TLE
- bridges or articulation points
- 🥵 codeforces/178-B3:
given an undirected graph, count how many bridge edges exists between 2 query vertices
→ group the vertices connected by non-bridge edge during dfs; generate a tree considering each group as a vertice, and using only the bridge edges; find the distance between 2 query vertices of that tree with LCA in O(1) - 🥵 uva/12363:
given an undirected graph, check if there is a unique path between 2 query vertices
→ there is a unique path between s and t if the path between them is formed only by bridge edges; for optimize, keep sets for the vertices that are on the same connected component in the pruned graph (with only bridge edges) - 🙂 uva/796
- 🥵 codeforces/178-B3:
- topological sorting
- flood fill
- depth-first search (DFS)
- 😳 uri/2965
- strongly connected components (SCC)
- 😳 uva/11504 → count the number of SCCs without incoming edge from a vertex of another SCC
- edge classification
- 🙂 codeforces/104-C:
check if the given undirected graph can be represented as a set of three or more rooted trees, whose roots are connected by a simple cycle
→ check if the graph is connective and has only one cycle - 🙂 codeforces/510-B:
check if a given implicit undirected graph has a cycle of length >= 4
- 🙂 codeforces/104-C:
- specials
- 😳 uva/12442:
given a graph with all vertices with out-degree 1, find the vertice that reaches the most vertices
- tree
- 😳 spoj/ONP:
infix to postfix conversion
→ see that the given expression is the in-order traversal in a binary tree, then print post-order traversal recursively without building the tree - 🙂 codeforces/115-A:
given a forest, find the length of the longest path
- 🙂 spoj/LABYR1:
compute the diameter of a given implicit tree
- lowest common ancestor (LCA)
- 🙂 timus/1471:
given a weighted tree, find the distance between 2 query vertices
- 😳 uva/12238:
given a weighted tree, find the distance between 2 query vertices
- 🙂 timus/1471:
- 😳 spoj/ONP:
- directed acyclic graph (DAG)
- 🙂 uva/988:
counting paths from 0 to V-1
- 🙂 uva/988:
- bipartite
- bipartite checking
- 🙂 spoj/BUGLIFE → check all connect components
- 🙂 uva/10004
- max cardinality bipartite matching
- bipartite checking
- 😳 uva/12442:
- iterative
- 🙂 uva/628
- 🙂 uva/10360
- 🙂 uva/12801
- 🙂 codeforces/633-A:
check if a diophantine equation has positive solution
- 🙂 uva/725
- 😳 uva/12792:
simulation
→ note that if you 'watch' a unique card, the full deck will become sorted as soon as this card reaches its original position - all subsets
- 🙂 uva/12455 → use bitmask
- 🙂 codeforces/550-B → use bitmask
- all permutations
- 🙂 uva/750
- recursive backtracking
- 🙂 code-jam/2020-QR-indicium-TLE:
generate M, where M[i][j] is any value in [1 .. N] (2 <= N <= 5), but without repeting a value in same line or column, and with the sum of the main diagonal equal to K
- 😳 uva/10503:
given domino pieces, check if it is possible to arrive at a target piece from an initial piece using N intermediate pieces (possibly rotating them)
→ DFS + backtracking - 🙂 live-archive/2883:
chess with a single horse against up to 8 pawns; print the length of the minimum sequence of horse moves if it wins
- 🙂 uva/10344:
check if some arithmetic expression of 5 given numbers will result in 23
→ check all combination of operators for each permutation of the given numbers - 🙂 spoj/MKJUMPS:
given an unweighted implicit graph, count the longest possible path
→ DFS + backtracking - sudoku
- 🙂 uva/989
- pruned permutations
- n-queens
- 😳 uva/11195 → use bitmask
- 🙂 code-jam/2020-QR-indicium-TLE:
- 🙂 codeforces/659-D
- 🙂 codeforces/1047-B
- 🙂 codeforces/499-C → count how many lines the 2 points cross
- 🙂 spoj/GOALFR
- 🙂 uva/11152
- sparse table
- 🙂 spoj/THRBL:
range max query
- 🙂 spoj/THRBL:
- union-find disjoint sets (UFDS)
- 🙂 uva/10608
- 🙂 codeforces/1249-B2
- 😳 codeforces/25-D
- 🙂 uva/11966
- 🙂 codeforces/445-B → 2 ^ (sum of (size of set - 1), for each disjoint set)
- segment tree
- 🙂 codeforces/339-D
- 🙂 live-archive/6139:
range product query
- lazy propagation
- two pointers
- 🙂 codeforces/6-C
- 😳 codeforces/676-C
- 🥵 codeforces/1041-D
- 😳 uva/967:
pope
- 🙂 codeforces/381-A
- 😳 codeforces/279-B
- binary search
- 🙂 spoj/PAIRS1:
given the A array, count the quantity of pairs i < j such that A[i]-A[j] == K
→ search on the sorted array A by the A[n]+K, for all n in [0 .. N-1] - 😳 codeforces/1284-B
- 😳 codeforces/91-B:
given the array a, compute the array d, where d[i] = j-(i+1) for the max j such that a[j] < a[i]
→ apply binary search on preprocessed array mn, filled from right to left - 😳 codeforces/1324-D:
given the A and B arrays, count the quantity of pairs i < j such that A[i]+A[j] > B[i]+B[j]
→ diff being the A-B array, count, for all i in [0 .. N-2], how many times -diff[i] < diff[j], for all j in [i+1 .. N-1] - on answer
- 😳 spoj/AGGRCOW:
given an array A of size N (2 <= N <= 10^5), print the largest minimum distance between any two of C (C <= N) elements choosen any
- 🥵 codeforces/460-C
- 😳 codeforces/1223-C
- 😳 uva/12097
- 😳 uri/2973
- 😳 spoj/AGGRCOW:
- 🙂 spoj/PAIRS1:
- bitmask
- 🙂 codeforces/151-A
- 🙂 uva/11799
- 🙂 uri/2963
- 🙂 uva/10141
- 🙂 code-jam/2020-1C-overexcited-fan
- 🙂 spoj/EC_CONB
- 🙂 codeforces/37-A
- 🙂 uri/2879
- 🙂 spoj/ADAQUEUE
- 🙂 codeforces/1285-A
- 🙂 codeforces/1220-A
- 🙂 uva/12015
- 🥵 uri/1368
- 🙂 uri/3024
- 🙂 uri/2242
- 🙂 uva/12798
- 🙂 uri/2968
- 🙂 spoj/SBANK
- 🙂 uri/2884
- implementation
- 😳 codeforces/1296-C → maps each position of the robot with the string index, and check if a new position has already been mapped before
- 🙂 uri/1763
- 🙂 codeforces/110-A
- 🙂 uri/1975
- 🙂 uva/105:
skyline
- 🙂 codeforces/373-A
- 🙂 uri/2593
- 🙂 codeforces/158-C
- 🙂 code-jam/2020-QR-vestigium
- 🙂 codeforces/81-A
- 😳 codeforces/1254-A
- 🙂 codeforces/266-A
- 🙂 codeforces/811-B
- 🙂 uri/1260
- 😳 codeforces/519-C
- 🙂 uri/1215
- 🙂 codeforces/492-B
- 😳 uri/2971
- 🙂 spoj/GNY07D
- 🙂 codeforces/1284-A
- 🙂 uri/1261
- 😳 codeforces/768-B → knowing the size of the final array with a little math, use the same idea to query a range in a segment tree
- suffix array
- 😳 spoj/SARRAY:
just build a suffix array in O(N * log N)
- 😳 spoj/SARRAY: