This file contains 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
/* | |
@robertkingnz | |
https://www.youtube.com/c/RobertKing/videos -> https://youtu.be/Z5WzJ9jbnKg | |
https://codingcompetitions.withgoogle.com/kickstart/round/00000000008cb0f5/0000000000ba86e6 | |
*/ | |
extern crate core; | |
fn calc_toll(c: i64, toll: &(char, i64)) -> i64 { | |
let ans = match toll.0 { |
This file contains 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
/* | |
https://www.youtube.com/c/RobertKing/videos | |
@robertkingnz | |
problem: https://www.facebook.com/codingcompetitions/hacker-cup/2011/round-1a/problems/C | |
video: | |
*/ | |
use std::collections::HashMap; | |
pub struct Combination { |
This file contains 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
/* | |
problem: https://codingcompetitions.withgoogle.com/kickstart/round/00000000008f4a94/0000000000b55465 | |
youtube: https://youtu.be/Yvj18KBThsE (subscribe) | |
twitter: https://twitter.com/robertkingNZ (follow) | |
*/ | |
use std::collections::VecDeque; | |
use std::usize; |
This file contains 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
// video here: https://www.youtube.com/c/RobertKing/videos | |
fn dist(x: u64, y: u64) -> u64 { | |
if x <= y { | |
return y - x; | |
} | |
x-y | |
} | |
fn min(x: u64, y: u64) -> u64 { |
This file contains 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
/* | |
twitter: @robertkingnz | |
youtube: https://www.youtube.com/c/RobertKing/videos | |
topological sort found here: https://github.com/kenkoooo/competitive-programming-rs/blob/master/src/graph/topological_sort.rs | |
Google Code Jam 2022 Chain Reactions: https://codingcompetitions.withgoogle.com/codejam/round/0000000000876ff1/0000000000a45ef7 | |
*/ | |
pub fn topological_sort(graph: &[Vec<usize>], mut fun: Vec<u64>) -> u64 { | |
let n = graph.len(); |
This file contains 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 main() { | |
let (r, w) = (std::io::stdin(), std::io::stdout()); | |
let mut sc = IO::new(r.lock(), w.lock()); | |
let t: usize = sc.read(); | |
for case_num in 1..=t { | |
let mut v: Vec<usize> = sc.chars().into_iter().map(|c| { | |
((c as u8) - b'0') as usize | |
}).collect(); |
This file contains 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::cmp::Reverse; | |
fn main() { | |
let (r, w) = (std::io::stdin(), std::io::stdout()); | |
let mut sc = IO::new(r.lock(), w.lock()); | |
let t: usize = sc.read(); | |
for case_num in 1..=t { | |
let mut heap = std::collections::BinaryHeap::new(); | |
let n: usize = sc.read(); |
This file contains 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
// @robertkingnz | |
// this rust implementation reduces the number of centers that need checking | |
// it does so by only trying one possible center for each group of repeating characters. | |
// this is one of the few 0ms solutions on leetcode, | |
// although there is a faster, more complex, O(N) solution possible. | |
impl Solution { | |
pub fn longest_palindrome(s: String) -> String { | |
let b = s.as_bytes(); | |
fn expand(mut i: usize, mut j: usize, b: &[u8]) -> (usize, usize) { |
This file contains 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
package main | |
import ( | |
"math/rand" | |
"fmt" | |
"time" | |
"sort" | |
) | |
const N = 1 << 20 |