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
mod bin_coeff { | |
#![deny(overflowing_literals)] | |
use ::std::collections::HashMap; | |
pub type Res = u64; | |
pub const BOUND: Res = Res::max_value(); | |
const _MIN_OVERFLOWING_LINE: Res = 67; | |
const FIRST_ALWAYS_OVERFLOWING_POS: Res = 33; |
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
type FieldLen = u32; | |
#[deny(overflowing_literals)] | |
//Ограничение на максимальную длину входных данных | |
const FIELD_BOUND: FieldLen = 5_000 - 1; | |
#[derive(Debug, PartialEq)] | |
enum SideDir { //Возможные направления стороны поля | |
NS, //С севера на юг (north-south) | |
WE, //С запада на восток (west-east) |
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
type Duration = u32; | |
type DurationTriple = (Duration, Duration, Duration); | |
const TIME_BOUND: Duration = 1_000; | |
const LEN_BOUND: usize = 1_000; | |
#[derive(Clone)] | |
struct SellTimes { | |
one: Duration, | |
two: Duration, |
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
type People = u32; | |
type Parts = People; | |
fn min_pie_parts(guests: People, old_friends: People) -> Parts { | |
fn gcd(a: People, b: People) -> People { | |
if a < b { gcd(b, a) } | |
else if b == 0 { a } | |
else { gcd(b, a % b) } | |
} | |
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, PartialEq)] | |
struct PiFractions(f64); | |
impl ::std::convert::Into<f64> for PiFractions { | |
fn into(self) -> f64 { | |
self.0 * ::std::f64::consts::PI | |
} | |
} |
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
//Вспомогательный тип для удобства измерения площади | |
//(в единицах [длина ^ 2] / π) | |
#[derive(Debug, PartialEq)] | |
struct PiFractions(f64); | |
//Сконвертировать PiFracions в нормальное число | |
impl ::std::convert::Into<f64> for PiFractions { | |
fn into(self) -> f64 { | |
self.0 * ::std::f64::consts::PI | |
} |
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
type Height = u8; | |
//Ищет индекс lineup, по которому можно разместить person, | |
//не нарушая упорядочения по убыванию. | |
//В случае, если в слайсе несколько элементов подряд, | |
//равных person, возвращается индекс после последнего элемента группы. | |
//ВНИМАНИЕ: проверка на то, что слайс действительно является | |
//упорядоченным, не производится | |
fn index_in_lineup(lineup: &[Height], person: Height) -> usize { | |
//Ищем person бинарным поиском (учитывая, что |
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; | |
use std::cmp::Ordering; | |
fn num_part_compare(a: &[u8], b: &[u8]) -> Ordering { | |
let a_b = a.iter().chain(b.iter()); | |
let b_a = b.iter().chain(a.iter()); | |
for (x, y) in a_b.zip(b_a) { | |
match x.cmp(y) { | |
Ordering::Equal => (), |
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
extern crate num; | |
type Input = u32; | |
mod gcd_memo { | |
use super::Input; | |
use std::collections::HashMap; | |
type GcdAcc = HashMap<(Input, Input), Input>; | |
pub struct GcdMemo(GcdAcc); |
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
fn majority(arr: &[f64]) -> Option<f64> { | |
use std::collections::HashMap; | |
let threshold = arr.len() / 2; | |
let mut occurs = HashMap::new(); | |
for &f in arr { | |
//f64 не хэшируется, в отличие от | |
//битового представления u64 | |
let fbits = f.to_bits(); |