Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Python utility codes, mainly for Kattis and AoC

NotificationsYou must be signed in to change notification settings

RussellDash332/pytils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Not to be confused with thepytils library for Russian-specific string utilities.

My collection ofPython utility codes primarily designed for solving Kattis and Advent of Code (AoC) problems. It is intended to be as fast as possible, if not as short as possible. Feel free to use and customize them for your own use as you see fit.

Treasure List

Classification taken fromcp-algorithms.

Algebra and Number Theory

Prime Numbers

Modular Arithmetic

Miscellaneous

Data Structures

Lists

Trees

Miscellaneous

Dynamic Programming

Knapsack

Convex Hull Trick

  • convex_hull_trick

    Convex hull optimization to optimize a specific$O(n^2)$ DP problem into an$O(n\log n)$ one. Here, we assume that the queries and slopes are sorted, thus reducing the problem into a sliding window after sorting.

    Kattis problem(s) to try on:coveredwalkway

  • dynamic_convex_hull_trick_line_container

    Dynamic convex hull optimization, also known as the line container, solves a more general problem where lines and queries are not necessarily given in sorted order. Due to list insertion and deletion being$O(n)$, each operation should run in$O(n)$ time instead of$O(\log n)$, but should still be fast enough in most cases.

    Kattis problem(s) to try on:quintessentialbirthdaysurprise,yatp

Miscellaneous

String Processing

Suffix Array

String Matching

Miscellaneous

Linear Algebra

Numerical Methods

Geometry

2D

3D

  • compgeo_3d_projection_intersection

    Solves different simple queries in 3D coordinate system:

    • point-to-segment projection
    • point-to-plane projection
    • point-line distance
    • point-plane distance
    • line-plane intersection
  • compgeo_3d_convex_hull

    Given$n$ 3D-coordinates where no four points lie on the same plane, compute its convex hull (smallest polyhedron that contains all points). Runs in$O(n^2)$ time.

    Kattis problem(s) to try on:worminapple

  • compgeo_3d_minimum_enclosing_circle

    Smallest circle/sphere (2D/3D) that covers all the given points. Outputs the center and the radius.

    Kattis problem(s) to try on:starsinacan

Graph Algorithms

Graph Representation

Graph Traversal

  • traversal_bfs

    Simple BFS implementation. Runs in$O(V+E)$ time.

  • traversal_dfs

    Simple iterative DFS implementation using stacks (because recursion is slow in Python). Runs in$O(V+E)$ time.

Connected Components & Graph Properties

Minimum Spanning Trees

Shortest Paths

Lowest Common Ancestor

Network Flows

Matchings

Miscellaneous

  • 2sat

    Check for 2-satisfiability of conjunctive normal forms (CNF). On top of checking if it's satisfiable, also finds such boolean assignment if any. Makes use of Kosaraju's algorithm.

    Kattis problem(s) to try on:palindromicdna

  • chinese_postman_problem

    Shortest circuit on a weighted undirected graph that visits every edgeat least once (as opposed to TSP that requires visiting every vertex other than starting nodeexactly once). Makes use of Floyd-Warshall's APSP algorithm.

    Kattis problem(s) to try on:joggingtrails

  • hierholzer_eulerian_cycle

    Prints the Eulerian circuit given a directed Eulerian graph (visits every edgeexactly once).

    Kattis problem(s) to try on:eulerianpath

  • min_path_cover_dag

    You can use Hopcroft Karp's algorithm to find the minimum number of paths needed to cover the edges of a directed acyclic graph (DAG).

  • maximum_clique_bron_kerbosch

    Finds the maximum number such that exists a complete subgraph (clique) consisting of this many vertices using Bron-Kerbosch's algorithm, which is supposes to run in$O(3^\frac{V}{3})$ time.

    Kattis problem(s) to try on:maxclique,letterballoons

  • minimum_vertex_cover_bipartite

    Minimum number of vertices needed to cover all edges of the graph using Kőnig's theorem.

    Kattis problem(s) to try on:bilateral

  • min_clique_cover_backtracking

    Minimum number of cliques needed to cover the entire graph, simply using the plain old backtracking.

    Kattis problem(s) to try on:busplanning,committeeassignment

Advent of Code

Miscellaneous


[8]ページ先頭

©2009-2025 Movatter.jp