Skip to content

Instantly share code, notes, and snippets.

View vslaykovsky-zz's full-sized avatar

vslaykovsky-zz

View GitHub Profile
struct array_deleter
{
void operator ()(char * p)
{
delete[] p;
}
};
class A{
public:
#include <stdio.h>
int main(int argc, char* argv[]) {
int* vals;
size_t n;
size_t m;
int i;
MOD=1000000007
def solve a, b
#puts "solve #{a} #{b}"
return 1 if a == 0 or b == 0
$cache = (a + 1).times.map{[-1] * (b + 1)} unless $cache
return $cache[a][b] if $cache[a][b] != -1
r = solve(a, b - 1)
r += solve(a - 1, b) if a - 1 > b
$cache[a][b] = r
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
struct Tree {
int value;
Tree(int v) : value(v) {}
vector<Tree*> c;
};
#include <iostream>
#include <set>
using namespace std;
int common_prefix(const string& a, const string& b) {
int i = 0;
while (i < a.size() && i < b.size() && a[i] == b[i])
++i;
return i;
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
void gen_primes(vector<int>& primes, int max) {
primes.resize(max + 1);
for (int i = 2; i < primes.size(); ++i)
if (primes[i] == 0)
gets.to_i.times do |i|
m = []
c = gets.chomp
if c == "0"
puts "Case #{i+1}: 0 0"
else
c.size.times do |i1|
c.size.times do |i2|
c[i1],c[i2] = c[i2],c[i1]
m << c.clone
DIR={'<'=>[-1, 0], '^'=>[0, -1], '>'=>[1, 0], 'v'=>[0, 1]}
def rotate maze
maze.each_with_index do |row, y|
row.size.times do |x|
c = row[x]
ind = DIR.keys.index c
row[x] = DIR.keys[(ind + 1) % 4] if ind
end
end