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
"""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
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
" 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
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
symbols = [ | |
"sziv", "virag", "ora", "villanykorte", "teknos", "pok", "cica", "szmotyi", | |
"kerdojel", "sajt", "katica", "lakat", "nap", "hopehely", "tilos", | |
"napszemuveg", "felkialtojel", "emberke", "jinjang", "tuz", "pokhalo", "madar", | |
"bohoc", "kalapacs", "iglu", "dino", "gyertya", "szaj", "fa", "hoember", "ollo", "lohere", | |
"hangjegy", "sakk", "szellem", "vizcsepp", "hold", "vasmacska", "jeg", "cumi", "bomba", | |
"zebra", "kutya", "koponya", "repa", "alma", "ceruza", "villam", "kaktusz", "auto", | |
"kez", "celkereszt", "szem", "delfin", "level", "sarkany", "kulcs" ] | |
s = set(symbols) | |
print "The number of symbols are: %s" % (len(symbols), ) |
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 os.path | |
import os | |
def touch(fname, times=None): | |
"""via: https://stackoverflow.com/a/1160227/8785384 """ | |
with open(fname, "a"): | |
os.utime(fname, times) | |
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
# kmp.py | |
def get_prefix(string): | |
l = len(string) | |
ret = [0] * l | |
border = 0 | |
for i in xrange(1, l): | |
while border > 0 and string[i] != string[border]: | |
border = ret[border - 1] | |
if string[i] == string[border]: | |
border += 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
n = int(raw_input().strip()) | |
acc = [] | |
for _ in xrange(n): | |
c = int(raw_input().strip()) | |
if c >= 90: | |
acc.append(c) | |
if acc: | |
print "%.2f" % (sum(acc) / float(len(acc))) |
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 <vector> | |
#include <unordered_set> | |
#include <algorithm> | |
#include <cmath> | |
#include <tuple> | |
#include <iostream> | |
using namespace std; | |
typedef long long ll; |