Skip to content

Instantly share code, notes, and snippets.

class Solution {
public:
void extend(forward_list<int>::iterator curr, forward_list<int>& route, vector<bool>& was, const int& k, const int& top) {
if(!was[*curr]) was[*curr] = true;
int neigh;
bool changed = true;
while(changed) {
changed = false;
for(int i = 0; i < k; i++) {
neigh = (*curr * 10) % top + i;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, j, k, in) for (ll i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (ll i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
ll dp[400][400], val[400][400];
impl Solution {
pub fn next_closest_time(time: String) -> String {
let vec: Vec<char> = time.chars().filter(|&x| x != ':').collect();
let to_usize = |x| vec[x] as usize - 48;
let base_value = 60 * (10 * to_usize(0) + to_usize(1)) + 10 * to_usize(2) + to_usize(3);
let mut letters = vec![false; 10];
for c in vec.iter() {
let i = *c as usize - 48;
letters[i] = true;
}
@jakab922
jakab922 / sol.cc
Last active February 18, 2020 13:58
Solution of the this problem -> https://codeforces.com/contest/1301/problem/E
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,n) for (int i=a;i<n;i++)
constexpr ll p = 1000000007;
constexpr int R = 0, G = 1, B = 2, Y = 3;
constexpr int N = 500, LOGN = 9;
impl Solution {
fn rec_solve(nums: &Vec<i32>, start: usize, left: usize, cache: &mut Vec<Vec<i32>>) -> i32 {
if left == 1 {
cache[start][1] = nums.iter().skip(start).sum();
return cache[start][1];
}
let l = nums.len();
let mut s = 0;
for last in start..(l - (left - 1)) {
use std::vec::Vec;
impl Solution {
pub fn multiply(num1: String, num2: String) -> String {
let one: Vec<u32> = num1.chars().map(|c| c.to_digit(10).unwrap()).rev().collect();
let other: Vec<u32> = num2.chars().map(|c| c.to_digit(10).unwrap()).rev().collect();
let mut tmp: Vec<u32> = vec![0; one.len() + other.len() + 1];
for (i, el1) in one.iter().enumerate() {
use std::cmp;
pub fn smaller(vec: &Vec<i32>, val: i32) -> i32 {
let len = vec.len();
if(len == 0) {
return 0;
}
if vec[len - 1] < val {
return len as i32;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll p = 1000000007;
ll gcd(ll a, ll b) {
while(b) {
ll tmp = b;
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1000000007;
ll fast_pow_mod(ll a, ll b, ll m) {
a %= m;
if(a == 0ll) return a;
@jakab922
jakab922 / variadic_join.cc
Created March 20, 2019 15:53
Python like join with C++ variadic templates
// Compile and run with g++ -o vjoin --std=c++17 variadic_join.cc; ./vjoin
// c++17 standard might not be needed since we use the c++11 variadic template notation
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
void join(stringstream &ss, const string &sep, T t) {
ss << t;
}