Skip to content

Instantly share code, notes, and snippets.

View jo32's full-sized avatar
🎯
Focusing

jo32

🎯
Focusing
View GitHub Profile
@jo32
jo32 / cf431c.py
Created October 14, 2015 09:33
CODEFORCE 431C
# http://codeforces.com/problemset/problem/431/C
[n, k, d] = [int(i) for i in raw_input().split(' ')]
dpAll = [[0 for i in range(n + 1)] for i in range(n + 1)]
dpNone = [[0 for i in range(n + 1)] for i in range(n + 1)]
for i in range(1, k + 1 if k + 1 < n + 1 else n + 1):
dpAll[1][i] = 1
for i in range(1, d if d < n + 1 else n + 1):
@jo32
jo32 / cf313b.py
Created October 14, 2015 03:11
CODEFORCE 313B
import bisect
s = raw_input()
nCases = int(raw_input())
cases = [[int(i) for i in raw_input().split(' ')] for x in range(nCases)]
dp = [0] * (len(s) + 1)
for i in range(1, len(s)):
dp[i] = dp[i - 1] + 1 if s[i - 1] == s[i] else dp[i - 1]
@jo32
jo32 / cf550a.py
Created October 13, 2015 07:09
CODEFORCE 550A
s = raw_input()
minAB = len(s) + 1
maxAB = -1
minBA = len(s) + 1
maxBA = -1
for i in range(len(s) - 1):
if [s[i], s[i + 1]] == ['A', 'B']:
minAB = i if i < minAB else minAB
maxAB = i if i > maxAB else maxAB
@jo32
jo32 / cf489c.py
Created October 13, 2015 06:51
CODEFORCE 489C
[n, s] = [int(i) for i in raw_input().split(' ')]
def hasSolution(n, ss):
return (ss >= 0 and ss <= 9 * n)
ss = s
minS = '';
for i in range(n):
for d in range(10):
if (i > 0 or d > 0 or (n == 1 and d == 0)) and hasSolution(n - i - 1, ss - d):
@jo32
jo32 / cf189a.py
Created October 12, 2015 12:12
CODEFORCE 189A
[n, a, b, c] = [int(i) for i in raw_input().split(' ')]
dp = [0] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
dp[i] = max(
dp[i - a] if i - a >= 0 else -4001,
dp[i - b] if i - b >= 0 else -4001,
dp[i - c] if i - c >= 0 else -4001
@jo32
jo32 / cf489b.py
Created October 12, 2015 09:54
CODEFORCE 489B
nBoys = int(raw_input())
aBoys = [int(i) for i in raw_input().split(' ')]
nGirls = int(raw_input())
aGirls = [int(i) for i in raw_input().split(' ')]
aBoys = sorted(aBoys)
aGirls = sorted(aGirls)
b = 0
g = 0
@jo32
jo32 / cf337a.py
Last active October 12, 2015 13:47
CODEFORCE 327A
n = int(raw_input())
a = [int(i) for i in raw_input().split(' ')]
def flip(a, i, j):
for index in range(i, j + 1):
a[index] = 1 - a[index]
maxCount = -1
for i in range(n):
@jo32
jo32 / cf455a.py
Created October 11, 2015 18:01
CODEFORCE 455A
n = int(raw_input())
a = [int(i) for i in raw_input().split(' ')]
maxElement = max(a)
count = {}
for ai in a:
count[ai] = count[ai] + 1 if ai in count else 1
def getCount(ai):
return count[ai] if ai in count else 0
@jo32
jo32 / cf337a.py
Created October 10, 2015 06:56
CODEFORCES 337A
import math
[n, m] = [int(i) for i in raw_input().split(' ')]
f = [int(i) for i in raw_input().split(' ')]
f = sorted(f);
minDist = min([(f[i + n - 1] - f[i]) for i in range(m - n + 1)]) if m > n else f[n - 1] - f[0]
print minDist
@jo32
jo32 / es7async-example.js
Created September 29, 2015 07:43
es7async-example.js
async function hello() {
var a = await Promise.resolve('Hello ');
return a;
}
(async function helloWorld() {
var hello = await hello();
console.log(hello + 'World!');
})();