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; | |
typedef long long ll; | |
template<typename T> using V = vector<T>; | |
string bigint_to_str(const V<char>& c) | |
{ | |
string s = ""; | |
for (int i = c.size()-1; i >= 0; --i) { | |
s += c[i] + '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
# Find last m non-zero digits of n! | |
n, m = map(int, input().split()) | |
cnt = 0 | |
power = 5 | |
while n // power > 0: | |
cnt += n // power | |
power *= 5 | |
print(f"{n}! has {cnt} zeros.") |
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
from jutge import read # Cosas del input... | |
def optimize(f, f_extra_args, l, r, y): | |
# Tiempo: O(t(f) log(r-l)) donde t(f) es el coste de calcular f(x) | |
# | |
# Este método maximiza la función f y si hay varios inputs que dan | |
# el valor y encuentra el mínimo {min x | f(x) = y} y se | |
# cumple que la función f es (no estrictamente) creciente, es decir, | |
# que siempre {f(x) >= f(x+1)}. | |
# Si tienes una función decreciente {f(x) <= f(x+1)} puedes convertirla |
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; | |
#define endl '\n' | |
template<typename T> using V = vector<T>; | |
using pii = pair<int,int>; | |
const int N = 2019; |
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
import sys | |
from math import * | |
def error(err): | |
print("Error:", err) | |
sys.exit(0) | |
def lcm(a, b): | |
return a//gcd(a,b)*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; | |
void pascals_triangle(int n) | |
{ | |
n = 1 << (n+1); | |
vector<vector<bool>> a; | |
a.resize(n); | |
a[0].resize(1); | |
a[0][0] = 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
#include <ostream> | |
namespace Color { | |
enum Code { | |
FG_RED = 31, | |
FG_GREEN = 32, | |
FG_BLUE = 34, | |
FG_DEFAULT = 39, | |
BG_RED = 41, | |
BG_GREEN = 42, |
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
# Reference: https://www.kaggle.com/gemartin/load-data-reduce-memory-usage | |
def reduce_mem_usage(df): | |
""" iterate through all the columns of a dataframe and modify the data type | |
to reduce memory usage. | |
""" | |
start_mem = df.memory_usage().sum() / 1024**2 | |
print('Memory usage of dataframe is {:.2f} MB'.format(start_mem)) | |
for col in df.columns: |
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: | |
Cody has 4 types of onions. | |
The number of purple onions can be any non-negative integer. | |
The number of green onions is a multiple of 2. | |
The number of red onions is a multiple of 3. | |
The number of blue onions is a multiple of 5. | |
If Cody has N onions, how many different distributions of colors can there be? | |
""" |
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
template <typename T> | |
struct SegmentTree { | |
int n; | |
T* t; | |
T zero_val; | |
inline T merge(T a, T b) | |
{ | |
return a + b; // MODIFY FOR EACH PROBLEM | |
} |