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, |
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 <cmath> | |
| #include <ostream> | |
| const double PI = 3.141592653589793; | |
| struct Quaternion { | |
| double a, b, c, d; |
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
| #include <algorithm> | |
| #include <iostream> | |
| #include <numeric> | |
| using namespace std; | |
| int main() { | |
| int nums[3]; | |
| for (auto &num: nums) { | |
| cin >> num; |
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
| pub fn compose<'l, X, Y, Z>( | |
| left: &'l dyn Fn(Y) -> Z | |
| ) -> Box<dyn | |
| Fn(&'l dyn Fn(X) -> Y) -> Box<dyn | |
| Fn(X) -> Z | |
| + 'l | |
| > | |
| + 'l | |
| > { | |
| Box::new(move |right| { |
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(Debug, Clone, Copy, PartialEq)] | |
| pub struct NonNanF64(f64); | |
| impl NonNanF64 { | |
| /// # Safety | |
| /// | |
| /// The value must not be `NaN`. | |
| pub const unsafe fn new_unchecked(f: f64) -> Self { | |
| // SAFETY: this is guaranteed to be safe by the caller. | |
| Self(f) |
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
| print('''<header> | |
| ここをもうちょっとシンプルに変えてっと | |
| え、なにこのエラー・・・ | |
| </header>''') | |
| try: | |
| uglyCode() | |
| except: | |
| print('よくあるError') | |
| try: |
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
| /// The regular expression tree. | |
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | |
| pub enum RegExp { | |
| /// Declares a variable of the match result. | |
| Var(String, Box<RegExp>), | |
| /// Matching pattern of a chatacter. | |
| Let(char), | |
| /// Or pattern of patterns. | |
| Or(Box<RegExp>, Box<RegExp>), | |
| /// Concatenated pattern of patterns. |
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
| /// Find values where satisify `a * p + b * q = gcd`. | |
| pub fn ext_gcd(a: u64, b: u64) -> ExtGcd { | |
| let mut s = (0i64, 1i64); | |
| let mut t = (1i64, 0i64); | |
| let mut r = (as_i64(b), as_i64(a)); | |
| while r.0 != 0 { | |
| let q = r.1 / r.0; | |
| let f = |mut r: (i64, i64)| { | |
| std::mem::swap(&mut r.0, &mut r.1); |
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 num::{traits::Pow, One, Zero}; | |
| use serde::{Deserialize, Serialize}; | |
| const R: u64 = 1 << 32; | |
| /// Find `modulo_inv` which satisifes `modulo * modulo_inv ≡ -1 (mod R)`. | |
| const fn find_neg_inv(modulo: u32) -> u32 { | |
| let mut inv_mod = 0u32; | |
| let mut t = 0; | |
| let mut i = 1u32; |