Skip to content

Instantly share code, notes, and snippets.

View mejibyte's full-sized avatar

Andrés Mejía mejibyte

View GitHub Profile
@mejibyte
mejibyte / code_lock.cpp
Last active December 23, 2020 03:31
Problem C - Code Lock from ICPC South American Regionals 2009
// Stolen from https://github.com/gustavosm/uri/blob/master/1412.cpp
// Accepted
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
[50000, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -
@mejibyte
mejibyte / gist:bce163aa5f3f1920d3f72c5b42979ff4
Last active March 26, 2018 20:01
PS1: A nicely formatted command line.
hg_bookmark() {
hg bookmarks 2> /dev/null | \
awk '/\*/ { printf "\033[38;5;60m("$2")\033[00m" }'
}
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[38;5;59m\]\D{%T}\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\] $(hg_bookmark)\n\[\033[01;31m\]\$\[\033[00m\] '
@mejibyte
mejibyte / range.cpp
Created December 4, 2017 04:35
Solution to 632. Smallest Range from LeetCode
struct Item {
int value, list;
};
bool operator < (const Item& a, const Item& b) {
return a.value < b.value;
}
class Solution {
public:
@mejibyte
mejibyte / path.cpp
Created December 2, 2017 21:48
O(n) solution for problem 656 - Coin Path from LeetCode
// Problem statement:
// https://leetcode.com/problems/coin-path/description/
const int oo = INT_MAX / 2; // half to avoid overflow.
// This is a normal queue extended to allow querying for the minimum element inside it in O(1) time.
template <class T>
struct MinQueue {
deque<pair<T, int>> data;
int in, out;
@mejibyte
mejibyte / sudoku.cpp
Last active December 19, 2015 17:28 — forked from anaechavarria/sudoku.cpp
Ésta es la solución que habíamos hecho antes.
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
@mejibyte
mejibyte / gist:5519476
Last active December 17, 2015 00:18
O(n log^2 n) solution using a Fenwick tree for the problem of the "running medians": given an array a[0..n), find the median of the subarrays a[0..0], a[0..1], a[0..2] and so on up to a[0..n-1] and then find the average of all these medians. Constraints: 1 <= n <= 10^6 and 0 <= a[i] <= 10^9.
// Andrés Mejía
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
@mejibyte
mejibyte / gist:3921244
Created October 19, 2012 23:16
Link to Stanford's ACM-ICPC Notebook
http://www.stanford.edu/~liszt90/acm/
module Midterm
class << self
def ip_to_int(some_ip)
parts = some_ip.split(".").map(&:to_i)
(parts[0] << 24) + (parts[1] << 16) + (parts[2] << 8) + parts[3]
end
def int_to_ip(some_int)
parts = Array.new(4)
parts[0] = (some_int & (0xff << 24)) >> 24
@mejibyte
mejibyte / gist:2902752
Created June 9, 2012 22:08
Solution to 11813 - Shopping from UVa
// Andrés Mejía
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>