This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[derive(Clone, PartialEq, Eq, Hash)] | |
| struct Poly<const W: usize, const H: usize> { | |
| field: [[bool; W]; H], | |
| } | |
| impl<const W: usize, const H: usize> std::fmt::Debug for Poly<W, H> { | |
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| writeln!(f, "\"\"\"")?; | |
| for y in 0..H { | |
| for x in 0..W { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// Coordinate on 2D plane, which `+X` is right and `+Y` is down. | |
| #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | |
| pub struct Coordinate { | |
| pub x: usize, | |
| pub y: usize, | |
| } | |
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | |
| pub struct GridGraph<T> { | |
| grid: Vec<Vec<T>>, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SelfLoveRecoveryProgram: | |
| def __init__(self): | |
| self.self_love_level = 50 | |
| def increase_self_love(self, amount): | |
| self.self_love_level += amount | |
| def decrease_self_love(self, amount): | |
| self.self_love_level -= amount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::collections::BTreeMap; | |
| #[derive(Debug)] | |
| pub struct CoCo<K: Ord> { | |
| forward: BTreeMap<K, usize>, | |
| backward: Vec<K>, | |
| } | |
| impl<K: Ord> CoCo<K> { | |
| pub const fn new() -> Self { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import itertools | |
| from typing import Any, Dict, List, Set, Tuple | |
| from tqdm import tqdm | |
| from functools import reduce | |
| import operator | |
| import math | |
| def product_of_positive_factorials(multi_index): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{borrow::Borrow, collections::BTreeMap, num::NonZeroUsize}; | |
| #[derive(Debug, Clone)] | |
| pub struct BTreeMultiSet<T> { | |
| counts: BTreeMap<T, NonZeroUsize>, | |
| len: usize, | |
| } | |
| impl<T> BTreeMultiSet<T> { | |
| pub const fn new() -> Self { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Make `<canvas>` prepared for more pixel density display and returns a 2D rendering context. | |
| * | |
| * @param canvas {HTMLCanvasElement} - To be preapared. | |
| * @param devicePixelRatio {number} - The pixel ratio by device. | |
| * @returns {Canvas2DRenderingContext} - The scaled 2D rendering context. | |
| */ | |
| export function setupCanvas(canvas, devicePixelRatio) { | |
| const { width, height } = canvas; | |
| canvas.width *= devicePixelRatio; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <vector> | |
| class Fenwick { | |
| std::vector<size_t> data; | |
| size_t parent(size_t i) const { | |
| return i - (i & (-i)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| template<class T> | |
| inline void insert_sort(vector<T> &vec, size_t g) { | |
| for (size_t i = g; i < vec.size(); ++i) { | |
| int v = vec[i]; | |
| int j = i - g; | |
| while (0 <= j && v < vec[j]) { | |
| vec[j + g] = vec[j]; | |
| j -= g; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <algorithm> | |
| #include <optional> | |
| enum class Direction { | |
| North, | |
| West, | |
| East, | |
| South, |