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 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; |
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 <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]; |
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
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; | |
} |
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 <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; |
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
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)) { |
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::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() { |
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::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; |
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 <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; |
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 <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; |
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
// 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; | |
} |