FacebookHackerCup-2021 [](https://creativecommons.org/licenses/by-nc/3.0/)

December 25, 2022 ยท View on GitHub

Python solutions of Facebook Hacker Cup 2021. Solution begins with * means it will get TLE in the largest data set (total computation amount > 10^8, which is not friendly for Python to solve in 5 ~ 15 seconds). A 6-minute timer is set for uploading the result this year.

Qualification Round

#TitleSolutionTimeSpaceDifficultyTagNote
A1Consistency - Chapter 1Python PythonO(|S|)O(1)EasyGreedy
A2Consistency - Chapter 2Python PythonO(|S|)O(1)EasyFloyd-Warshall Algorithm, Dijkstra's Algorithm
BXs and OsPythonO(N^2)O(1)EasyArray
C1Gold Mine - Chapter 1PythonO(N)O(N)EasyTree, DFS
C2Gold Mine - Chapter 2PythonO(N * K^2)O(N * K)HardTree, DFS, DP

Round 1

#TitleSolutionTimeSpaceDifficultyTagNote
A1Weak Typing - Chapter 1PythonO(N)O(1)EasyArray
A2Weak Typing - Chapter 2Python PythonO(N)O(1)EasyDP, Math, Counting
A3Weak Typing - Chapter 3Python PythonO(N)O(1)MediumDP, Matrix Exponentiation, Math, Counting
BTraffic ControlPythonO(N * M)O(1)EasyArray, Constructive Algorithms
CBlockchainPythonO(N * MAX_C)O(N * MAX_C)HardSort, Union Find, Tree, DFS, DP

Round 2

#TitleSolutionTimeSpaceDifficultyTagNote
ARunwayPythonO(N * M)O(M)EasySimulation, Greedy
BChainblockPython PythonO(N)O(N)MediumTree Traversal, Tree Ancestors (Binary Lifting), Tarjan's Offline LCA Algorithm, Union Find
C1Valet Parking - Chapter 1PythonO(R * C)O(min(R, C))MediumArray
C2Valet Parking - Chapter 2(PyPy, Python) (PyPy, PyPy) (PyPy, Python) (PyPy, Python)O((R * C + S) * logR)O(R * C)HardArray, BIT, Fenwick Tree, Skip List, Sorted List, Heap, Segment Tree
DString ConcatenationPyPy Python PythonO(N + L*(logN1)^2 + N232^{3}/6 + X*2^X*(N3-X)/C)O(N)HardArray, Pigeonhole Principle, Birthday Paradox, Sorted List, BIT, Fenwick Tree, Bitmask

Round 3

#TitleSolutionTimeSpaceDifficultyTagNote
ARep-ore-tingPythonO(M + N)O(N)EasyIntervals, Union Find, Counting
BAuth-ore-izationPyPyO((M + N) * log(M + N))O(M + N)MediumSorted List, Segment Tree
CPerf-ore-mancePythonO(N * K^2)O(N * K)HardTree, DP
D1Expl-ore-ation - Chapter 1PythonO((R * C) * log(R * C))O(R * C)EasyUnion Find
D2Expl-ore-ation - Chapter 2PythonO((R * C + K) * log(R * C + K) + ((R * C) * log(R * C) + K) * logK)O(R * C + K)MediumUnion Find, Intervals, Sorted List
D3Expl-ore-ation - Chapter 3Python PythonO((R * C + K) * log(R * C)^2)O(R * C)HardUnion Find, Tree Traversal, Tree Ancestors (Binary Lifting), Heavy-Light Decomposition, Sorted List, BIT, Fenwick Tree

Final Round

You can relive the magic of the 2021 Hacker Cup World Finals by watching the Live Stream Recording of the announcement of winners.

#TitleSolutionTimeSpaceDifficultyTagNote
AAndPythonO(L * N)O(L * N)MediumGreedy, Union Find
BSSSSSSPythonO(NlogN)O(N)HardGreedy, Line Sweep
CHire FlyersPyPyO(N * (logN)^2)O(NlogN)HardLine Sweep, 2D Segment Tree, BIT, Fenwick Tree
DVacationPythonO(NlogN)O(N)MediumTree, DFS, DP, Greedy
EAntisocial*PyPy C++O(NlogN)O(N)HardGeometry, Voronoi Diagram (Fortune's Algorithm), Graph, Maximum Spanning Tree (Kruskal's Algorithm)
FTable Flipping*PyPy PyPy PyPyO(NlogN)O(NlogN)Hard2D Line Sweep, 2D Segment Tree, Implicit Segment Tree, Graph, DFS, BFS