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 / gist:1360763
Created November 12, 2011 16:24
Solution to 11367 - Full Tank? from UVa
/*
Accepted
*/
#include <iostream>
#include <climits>
#include <vector>
#include <cstdio>
#include <queue>
//#include <cassert>
@mejibyte
mejibyte / gist:1233426
Created September 21, 2011 21:50
My implementation of Aho-Corasick's algorithm for string matching.
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
@mejibyte
mejibyte / gist:1248480
Created September 28, 2011 16:58
C++ template for programming contests
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
@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 / 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 / gist:1268709
Created October 6, 2011 21:20
Implementation of the Knuth-Morris-Pratt algorithm in C++
// http://www.spoj.pl/problems/NHAY/
#include <vector>
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
void kmp(const string &needle, const string &haystack) {
int m = needle.size();
vector<int> border(m + 1);
@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 / gist:2166667
Created March 23, 2012 04:07
Solution to 5795 - Garden Fence from Live Archive
// Andrés Mejía
// Accepted, 7.772s
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
@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;