This file contains hidden or 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 pytest | |
from sol2 import solve | |
def brute_solve(n, step=2): | |
curr = range(n) | |
what = 0 | |
while len(curr) > 1: | |
nwhat = (what - len(curr) % step) % step |
This file contains hidden or 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
" Vundle setup | |
set nocompatible | |
filetype off | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
Plugin 'dyng/ctrlsf.vim' | |
Plugin 'vim-syntastic/syntastic' | |
Plugin 'tomtom/tlib_vim' | |
Plugin 'toml-lang/toml' | |
Plugin 'Shougo/unite.vim' |
This file contains hidden or 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 fractions import gcd | |
from collections import defaultdict as dd | |
n, k = map(int, raw_input().strip().split()) | |
ais = filter(lambda x: x != 0, map(int, raw_input().strip().split())) | |
n = len(ais) | |
mod = 10 ** 9 + 7 | |
curr = {1: 1} | |
for ai in ais: |
This file contains hidden or 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
"""The problem statement is the following: | |
You are given a list of size N, initialized with zeroes. You have to perform M operations on the list and output the maximum of final values of all the N elements in the list. For every operation, you are given three integers a, b and k. The value k needs to be added to all the elements ranging from index a through b (both inclusive). | |
Input Format | |
The first line will contain two integers N and M separated by a single space. | |
The next M lines will each contain three integers a, b and k separated spaces. | |
The numbers in the list are numbered from 1 to N. |
This file contains hidden or 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
def sol(n): | |
other = lambda x: 1 if x == 2 else 2 | |
first, empty = (1, 2) if n % 2 == 0 else (2, 1) | |
ms = [[1, 2, 0], [2, 0, 1]] | |
m = ms[empty % 2] | |
ret = [(0, first)] | |
for i in xrange(2, n + 1): | |
ret.append((0, empty)) | |
ret.extend(map(lambda x: (m[x[0]], m[x[1]]), ret[:-1])) |
This file contains hidden or 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
RED, BLACK = range(2) | |
LEFT, RIGHT = range(2) | |
SMALLER, EQUAL, BIGGER = range(-1, 2) | |
def _set_relation(child, parent, rtype): | |
if child is not None: | |
child.parent = parent | |
if parent is not None: | |
if rtype == LEFT: |
This file contains hidden or 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 random import shuffle, randint as ri | |
from itertools import product | |
PLAYER, OP, BOTH, NEITHER = range(4) | |
suits = ["clubs", "diamonds", "hearts", "spades"] | |
values = [ | |
"ace", "two", "three", "four", "five", | |
"six", "seven", "eight", "nine", "ten", | |
"jack", "queen", "king"] |
This file contains hidden or 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
#!python | |
#cython: boundscheck=False, wraparound=False, initializedcheck=False | |
from cpython cimport bool | |
LEFT, RIGHT = range(2) | |
RED, BLACK = range(2) | |
cocodes = ["R", "B"] | |
chcodes = ["l", "r"] |
This file contains hidden or 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 <iostream> | |
#include <string> | |
#include <algorithm> | |
using namespace std; | |
bool sol(string& s) { | |
bool total[26]; | |
fill_n(&total, 26, false); | |
for(char& c : s) { |
This file contains hidden or 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 math import sqrt, ceil | |
from functools import wraps | |
from optparse import OptionParser | |
CACHE = {} | |
def cache(f): | |
@wraps(f) | |
def cached(*args, **kwargs): |