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
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 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 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 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 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 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 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 problem statement is the following: | |
You are given a list of size N, initialized with zeroes. You have to perform M operations on the list and output the maximum of final values of all the N elements in the list. For every operation, you are given three integers a, b and k. The value k needs to be added to all the elements ranging from index a through b (both inclusive). | |
Input Format | |
The first line will contain two integers N and M separated by a single space. | |
The next M lines will each contain three integers a, b and k separated spaces. | |
The numbers in the list are numbered from 1 to N. |
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; | |
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 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 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; |