GoogleCodeJam 2021 [](./LICENSE)

April 3, 2022 · View on GitHub

  • Python solutions of Google Code Jam 2021. Solution begins with * means it will get TLE in the largest data set.
  • Total computation amount > 10^8 is not friendly for Python to solve in 5 ~ 15 seconds.
  • A problem was marked as Very Hard means that it was an unsolved one during the contest and may not be that difficult.
  • From 2021-04, PyPy3 is supported by the online judge.
  • From 2021-11, Python2/PyPy2 is no longer supported by the online judge.
  • You need to run 2to3 -n -W --add-suffix=3 solution.py to convert the solution into Python3/PyPy3.

Rounds

Qualification Round

#TitleSolutionTimeSpaceDifficultyTagNote
AReversortPythonO(N^2)O(1)EasySimulation
BMoons and UmbrellasPythonO(N)O(1)EasyDP
CReversort EngineeringPython PythonO(N)O(1)EasyGreedy
DMedian SortPythonO(N^2)O(1)MediumTernary Search, Insertion Sort
ECheating DetectionPython Python Python PythonO(S * Q)O(S + Q)HardUniform Distribution, Inversions Counting, Correlation Coefficient

Round 1A

#TitleSolutionTimeSpaceDifficultyTagNote
AAppend SortPython PythonO(N * log(MAX_X))O(1)EasyGreedy
BPrime TimePythonO((MAX_P * logX) * (M + logX))O(1)MediumMath, Prime Factorization, Pruning
CHacked ExamPythonprecompute: O(MAX_Q^2)
runtime: O(Q)
O(MAX_Q^2)HardBinomial Coefficients, DP, Math, Expected Value

Round 1B

#TitleSolutionTimeSpaceDifficultyTagNote
ABroken ClockPythonO(1)O(1)MediumMath, Linear Congruence
BSubtransmutationPython PythonO(MAX_M^2)O(MAX_M)MediumMath, Bézout's Identity, Greedy
CDigit BlocksPythonprecompute: O(N^3 * B * D)
runtime: O(N * B)
O(N^3 * B * D)HardDP, Math, Expected Value

Round 1C

#TitleSolutionTimeSpaceDifficultyTagNote
AClosest PickPythonO(NlogN)O(N)EasyMath, Sort
BRoaring YearsPythonO(D^2 * logD)O(D)MediumMath, Binary Search
CDouble or NOTingPython Python PythonO(|E| + |S|)O(|E| + |S|)HardMath, Bit Manipulation, KMP Algorithm

Round 2

#TitleSolutionTimeSpaceDifficultyTagNote
AMinimum SortPythonO(ClogN)O(1)EasySelection Sort
BMatrygonsPythonprecompute: O(NlogN)
runtime: O(1)
O(N)MediumPrecompute, DP
CHidden PancakesPython PythonO(N)O(N)MediumMath, Binomial Coefficients, DP
DRetilingPythonO((R * C)^3)O((R * C)^2)HardHungarian Weighted Bipartite Matching

Round 3

#TitleSolutionTimeSpaceDifficultyTagNote
ABuild-A-PairPyPy PyPy PythonO(N)O(1)EasyEnumeration, Greedy
BSquare FreePythonO(R^2 * C^2)O(R + C)MediumMax Flow, Greedy
CFence DesignPyPyO(NlogN) on averageO(N)Hard❤️Geometry, Convex Hull, Divide and Conquer, Random
DBinary Search GamePyPy PyPy PythonO(2^(2^(L-1)) * (2^L + N^2) + N^3)O(N^2 + L)Hard❤️Combinatorics, Counting, DP, Greedy, Polynomial, Faulhaber's Formula, Lagrange Interpolation

Virtual World Finals

You can relive the magic of the 2021 Code Jam Virtual World Finals by watching the Live Stream Recording of the competition, problem explanations, and announcement of winners.

#TitleSolutionTimeSpaceDifficultyTagNote
ACutting CakePythonO(NlogN)O(N)MediumMath, Line Sweep
BSlide CircuitsPython Python PythonO(B + N + SlogS)O(SlogS)MediumGraph, Hash, Prefix Sum
CRopesPyPyO(N^3)O(N^2)Hard❤️Greedy
DDivisible DivisionsPython PythonO(|S|logD)O(min(|S|logD, D))MediumMath, Linear Congruence, Chinese Remainder Theorem, DP, Prefix Sum
EInfinitreePyPy PyPy3O(N^3.5 * logN + N^3 * logB)O(N^2.5 * logN + N^2 * logB)Very Hard❤️Graph, Binary Tree, Matrix Exponentiation, Matrix Power Series, Prefix Sum, Binary Search, LCA, Tarjan's Algorithm