/CSES-Solutions

Accepted solutions of CSES problemset

Primary LanguageC++

CSES-Solutions

Accepted solutions of CSES problemset

Table of Contents


Introductory Problems

  1. 1068 - Weird Algorithm
  2. 1083 - Missing Number
  3. 1069 - Repetitions
  4. 1094 - Increasing Array
  5. 1070 - Permutations
  6. 1071 - Number Spiral
  7. 1072 - Two Knights
  8. 1092 - Two Sets
  9. 1617 - Bit Strings
  10. 1618 - Trailing Zeros
  11. 1754 - Coin Piles
  12. 1755 - Palindrome Reorder
  13. 2205 - Gray Code
  14. 2165 - Tower of Hanoi
  15. 1622 - Creating Strings
  16. 1623 - Apple Division
  17. 1624 - Chessboard and Queens
  18. 2431 - Digit Queries
  19. 1625 - Grid Paths

Sorting and Searching

  1. 1621 - Distinct Numbers
  2. 1084 - Apartments
  3. 1090 - Ferris Wheel
  4. 1091 - Concert Tickets
  5. 1619 - Restaurant Customers
  6. 1629 - Movie Festival
  7. 1640 - Sum of Two Values
  8. 1643 - Maximum Subarray Sum
  9. 1074 - Stick Lengths
  10. 2183 - Missing Coin Sum
  11. 2216 - Collecting Numbers
  12. 2217 - Collecting Numbers II
  13. 1141 - Playlist
  14. 1073 - Towers
  15. 1163 - Traffic Lights
  16. 2162 - Josephus Problem I
  17. 2163 - Josephus Problem II
  18. 2168 - Nested Ranges Check
  19. 2169 - Nested Ranges Count
  20. 1164 - Room Allocation
  21. 1620 - Factory Machines
  22. 1630 - Tasks and Deadlines
  23. 1631 - Reading Books
  24. 1641 - Sum of Three Values
  25. 1642 - Sum of Four Values
  26. 1645 - Nearest Smaller Values
  27. 1660 - Subarray Sums I
  28. 1661 - Subarray Sums II
  29. 1662 - Subarray Divisibility
  30. 2428 - Subarray Distinct Values
  31. 1085 - Array Division
  32. 1076 - Sliding Median
  33. 1077 - Sliding Cost
  34. 1632 - Movie Festival II
  35. 1644 - Maximum Subarray Sum II

Dynamic Programming

  1. 1633 - Dice Combinations
  2. 1634 - Minimizing Coins
  3. 1635 - Coin Combinations I
  4. 1636 - Coin Combinations II
  5. 1637 - Removing Digits
  6. 1638 - Grid Paths
  7. 1158 - Book Shop
  8. 1746 - Array Description
  9. 2413 - Counting Towers
  10. 1639 - Edit Distance
  11. 1744 - Rectangle Cutting
  12. 1745 - Money Sums
  13. 1097 - Removal Game
  14. 1093 - Two Sets II
  15. 1145 - Increasing Subsequence
  16. 1140 - Projects
  17. 1653 - Elevator Rides
  18. 2181 - Counting Tilings
  19. 2220 - Counting Numbers

Graph Algorithms

  1. 1192 - Counting Rooms
  2. 1193 - Labyrinth
  3. 1666 - Building Roads
  4. 1667 - Message Route
  5. 1668 - Building Teams
  6. 1669 - Round Trip
  7. 1194 - Monsters
  8. 1671 - Shortest Routes I
  9. 1672 - Shortest Routes II
  10. 1673 - High Score
  11. 1195 - Flight Discount
  12. 1197 - Cycle Finding
  13. 1196 - Flight Routes
  14. 1678 - Round Trip II
  15. 1679 - Course Schedule
  16. 1680 - Longest Flight Route
  17. 1681 - Game Routes
  18. 1202 - Investigation
  19. 1750 - Planets Queries I
  20. 1160 - Planets Queries II
  21. 1751 - Planets Cycles
  22. 1675 - Road Reparation
  23. 1676 - Road Construction
  24. 1682 - Flight Routes Check
  25. 1683 - Planets and Kingdoms
  26. 1684 - Giant Pizza
  27. 1686 - Coin Collector
  28. 1691 - Mail Delivery
  29. 1692 - De Bruijn Sequence
  30. 1693 - Teleporters Path
  31. 1690 - Hamiltonian Flights
  32. 1689 - Knight's Tour
  33. 1694 - Download Speed
  34. 1695 - Police Chase
  35. 1696 - School Dance
  36. 1711 - Distinct Routes

Range Queries

  1. 1646 - Static Range Sum Queries
  2. 1647 - Static Range Minimum Queries
  3. 1648 - Dynamic Range Sum Queries
  4. 1649 - Dynamic Range Minimum Queries
  5. 1650 - Range Xor Queries
  6. 1651 - Range Update Queries
  7. 1652 - Forest Queries
  8. 1143 - Hotel Queries
  9. 1749 - List Removals
  10. 1144 - Salary Queries
  11. 2166 - Prefix Sum Queries
  12. 2206 - Pizzeria Queries
  13. 1190 - Subarray Sum Queries
  14. 1734 - Distinct Values Queries
  15. 2416 - Increasing Array Queries
  16. 1739 - Forest Queries II
  17. 1735 - Range Updates and Sums
  18. 1736 - Polynomial Queries
  19. 1737 - Range Queries and Copies

Tree Algorithms

  1. 1674 - Subordinates
  2. 1130 - Tree Matching
  3. 1131 - Tree Diameter
  4. 1132 - Tree Distances I
  5. 1133 - Tree Distances II
  6. 1687 - Company Queries I
  7. 1688 - Company Queries II
  8. 1135 - Distance Queries
  9. 1136 - Counting Paths
  10. 1137 - Subtree Queries
  11. 1138 - Path Queries
  12. 2134 - Path Queries II
  13. 1139 - Distinct Colors
  14. 2079 - Finding a Centroid
  15. 2080 - Fixed-Length Paths I
  16. 2081 - Fixed-Length Paths II

Mathematics

  1. 2164 - Josephus Queries
  2. 1095 - Exponentiation
  3. 1712 - Exponentiation II
  4. 1713 - Counting Divisors
  5. 1081 - Common Divisors
  6. 1082 - Sum of Divisors
  7. 2182 - Divisor Analysis
  8. 2185 - Prime Multiples
  9. 2417 - Counting Coprime Pairs
  10. 1079 - Binomial Coefficients
  11. 1715 - Creating Strings II
  12. 1716 - Distributing Apples
  13. 1717 - Christmas Party
  14. 2064 - Bracket Sequences I
  15. 2187 - Bracket Sequences II
  16. 2209 - Counting Necklaces
  17. 2210 - Counting Grids
  18. 1722 - Fibonacci Numbers
  19. 1096 - Throwing Dice
  20. 1723 - Graph Paths I
  21. 1724 - Graph Paths II
  22. 1725 - Dice Probability
  23. 1726 - Moving Robots
  24. 1727 - Candy Lottery
  25. 1728 - Inversion Probability
  26. 1729 - Stick Game
  27. 1730 - Nim Game I
  28. 1098 - Nim Game II
  29. 1099 - Stair Game
  30. 2207 - Grundy's Game
  31. 2208 - Another Game

String Algorithms

  1. 1731 - Word Combinations
  2. 1753 - String Matching
  3. 1732 - Finding Borders
  4. 1733 - Finding Periods
  5. 1110 - Minimal Rotation
  6. 1111 - Longest Palindrome
  7. 1112 - Required Substring
  8. 2420 - Palindrome Queries
  9. 2102 - Finding Patterns
  10. 2103 - Counting Patterns
  11. 2104 - Pattern Positions
  12. 2105 - Distinct Substrings
  13. 2106 - Repeating Substring
  14. 2107 - String Functions
  15. 2108 - Substring Order I
  16. 2109 - Substring Order II
  17. 2110 - Substring Distribution

Geometry

  1. 2189 - Point Location Test
  2. 2190 - Line Segment Intersection
  3. 2191 - Polygon Area
  4. 2192 - Point in Polygon
  5. 2193 - Polygon Lattice Points
  6. 2194 - Minimum Euclidean Distance
  7. 2195 - Convex Hull

Advanced Techniques

  1. 1628 - Meet in the Middle
  2. 2136 - Hamming Distance
  3. 2137 - Beautiful Subgrids
  4. 2138 - Reachable Nodes
  5. 2143 - Reachability Queries
  6. 2072 - Cut and Paste
  7. 2073 - Substring Reversals
  8. 2074 - Reversals and Sums
  9. 2076 - Necessary Roads
  10. 2077 - Necessary Cities
  11. 2078 - Eulerian Subgraphs
  12. 2084 - Monster Game I
  13. 2085 - Monster Game II
  14. 2086 - Subarray Squares
  15. 2087 - Houses and Schools
  16. 2088 - Knuth Division
  17. 2111 - Apples and Bananas
  18. 2112 - One Bit Positions
  19. 2113 - Signal Processing
  20. 2101 - New Roads Queries
  21. 2133 - Dynamic Connectivity
  22. 2121 - Parcel Delivery
  23. 2129 - Task Assignment
  24. 2130 - Distinct Routes II

Additional Problems

  1. 1087 - Shortest Subsequence
  2. 1146 - Counting Bits
  3. 1670 - Swap Game
  4. 1134 - Prüfer Code
  5. 1756 - Acyclic Grpah Edges
  6. 2177 - Strongly Connected Edges
  7. 2179 - Even Outdegree Edges
  8. 2422 - Multiplication Table
  9. 1142 - Advertisement
  10. 2186 - Special Substrings
  11. 2229 - Permutation Inversions
  12. 1655 - Maximum Xor Subarray
  13. 1664 - Movie Festival Queries
  14. 1697 - Chess Tournament
  15. 1702 - Tree Traversals
  16. 1704 - Network Renovation
  17. 1707 - Graph Girth
  18. 1740 - Intersection Points
  19. 2214 - Inverse Inversions
  20. 2215 - Monotone Subsequences
  21. 1743 - String Reorder
  22. 2425 - Stack Weights
  23. 1747 - Pyramid Array
  24. 1748 - Increasing Subsequence II
  25. 1149 - String Removals
  26. 1188 - Bit Inversions
  27. 2419 - Xor Pyramid
  28. 1086 - Writing Numbers
  29. 1113 - String Transform
  30. 2427 - Letter Pair Move Game
  31. 1147 - Maximum Building I
  32. 1162 - Sorting Methods
  33. 1191 - Cyclic Array
  34. 2414 - List of Sums
  35. 2132 - Increasing Array II
  36. 1189 - Food Division
  37. 1654 - Bit Problem
  38. 1698 - Swap Round Sorting
  39. 2430 - Binary Subsequences
  40. 1700 - Tree Isomorphism I
  41. 2228 - Counting Sequences
  42. 1703 - Critical Cities
  43. 1706 - School Excursion
  44. 1709 - Coin Grid
  45. 1742 - Robot Path
  46. 2426 - Programmers and Artists
  47. 1757 - Course Schedule II
  48. 2174 - Removing Digits II
  49. 2180 - Coin Arrangement
  50. 2176 - Counting Bishops
  51. 2432 - Grid Puzzle I
  52. 2131 - Grid Puzzle II
  53. 1080 - Empty String
  54. 1078 - Grid Paths
  55. 2115 - Bit Substrings
  56. 2075 - Reversal Sorting
  57. 2421 - Counting Reorders
  58. 1159 - Book Shop II
  59. 1677 - Network Breakdown
  60. 1203 - Visiting Cities
  61. 2184 - Missing Coin Sum Queries
  62. 1157 - Number Grid
  63. 1148 - Maximum Building II
  64. 2423 - Filling Trominos
  65. 1161 - Stick Divisions
  66. 1665 - Coding Company
  67. 1699 - Flight Route Requests
  68. 2402 - Two Stacks Sorting
  69. 1701 - Tree Isomorphism II
  70. 1705 - Forbidden Cities
  71. 1741 - Area of Rectangles
  72. 2429 - Grid Completion
  73. 1752 - Creating Offices
  74. 1075 - Permutations II
  75. 2415 - Functional Graph Distribution
  76. 1685 - New Flight Routes
  77. 2418 - Grid Path Construction