Skip to content

Instantly share code, notes, and snippets.

View sol.cc
void calc(vector<int> &d1, vector<int> &d2, const string &s, int n) {
for (int i = 0, l = 0, r = -1; i < n; i++) {
int k = (i > r) ? 1 : min(d1[l + r - i], r - i + 1);
while (0 <= i - k && i + k < n && s[i - k] == s[i + k]) {
k++;
}
d1[i] = k--;
if (i + k > r) {
l = i - k;
r = i + k;
@jakab922
jakab922 / boggle_board.cc
Last active Nov 28, 2020
Boggle board solver in C++
View boggle_board.cc
#include <bits/stdc++.h>
using namespace std;
struct Node {
vector<int> endings;
unordered_map<char, Node*> followers;
};
void insert_trie(Node *node, const string &word, int index) {
int ws = word.size();
View .tmux.conf
# Package manager settings
set -g @plugin 'tmux-plugins/tpm'
# Installs themes
set -g @plugin 'jimeh/tmux-themepack'
# Selects a theme
set -g @themepack 'powerline/block/cyan'
# Add resurrect and continuum to save tmux sessions automatically
View id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDsj3PW9mukC8pS0LyA8T3jbljvWqerPANMASkN8gwdtRy9+3v3QdvidlsxA1T4zkbktoYAMfbQzklidILDuSjYY4WyMos5hiGF4pJ3asZ55l/jL6cA1BBPU9edYdep30/A5qaxyjSVCEm6IIX5FBki9LkxrVtQ8f3yGWL5qkVQtylQgmZay4OLC2T5bJTLwjs8jcys6eEbbM2eA0R5omnJreUOpPxvOHHLO3U2Lq+Gdi2VhparuqISsKky47ggdMIwengPl2ScFZAN6i8qLvlzM7FFXWR8ODHGI33NKznk/y4APcRdjwZF2nfJanIaj2vNxd15S/KLFnPFqQT/zE1n65UAhJnnh+mU6MjXa7d/oNlqv450ui+SQ5HcEbe+6qdD6Rh+HqiYHpSohA4Gz+JLF+hJ/iuY0yoqETvoimKT2gYbX5k6Kxriyzl9MxLQM4Qo8Ygl2sYvIzxXKAGG9TAwgQdKUNP+tqGn1TMr4lntjN97FZTWelWVdawkHWbPmuE= dani@sigil-laptop
@jakab922
jakab922 / brute.py
Last active May 1, 2020
Finding the smallest lower/upper balanced substring in a string consisting of a-z A-Z in linear time
View brute.py
def check(substr):
lower = [False for i in range(26)]
upper = [False for i in range(26)]
for c in substr:
o = ord(c)
if o > 90:
lower[o - 97] = True
else:
@jakab922
jakab922 / smart_pointer.cc
Last active Apr 22, 2020
C++ smart pointer implementation
View smart_pointer.cc
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class my_shared_ptr {
T *data;
int *ref_count;
void _possibly_destroy() {
if (*ref_count == 0) {
View sol.cc
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
struct segment_tree {
View sol.cc
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
namespace prime {
View sol.cc
/*
First I try to figure out what are the elements from 1 to 2 ** g - 1. In the end the value at node i(val[i]) is the following:
- If i > 2 ** g - 1 then 0
- If it isn't than the minimal value from it's subtree such that it's bigger than max(val[2 * i], val[2 * i + 1]) that is the value of the roots of its subtrees since the heap property is preserved
during the operations.
Since we know which values should be in the heap in the end and since calling f on an index means removing the associated value we call f on the indices whose value we don't need(all values are different) back
to front. And that's it.
*/
View sol.cc
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;