-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42f5b84
commit 9c925e0
Showing
12 changed files
with
706 additions
and
350 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from array import * | ||
import sys; sys.set_int_max_str_digits(2*10**6) | ||
N, X = map(int, input().split()); S = input(); V = array('i', [1]); U = set(); M = 1<<20 | ||
while V[-1] not in U: U.add(V[-1]); V.append((V[-1]*33+1)%M) | ||
C = array('i', [0]) | ||
for i in range(X): C[0] += V[X*i%M]; C[0] %= M | ||
for _ in range(X-1): C.append((33*C[-1]+X)%M) | ||
|
||
A = int(''.join(map(str, C))); D = 1 | ||
while 27**D < A: D *= 2 | ||
|
||
W = array('b', [0]*D); Q = [(A, 0, D-1)]; Z = [] | ||
while Q: | ||
x, l, r = Q.pop() | ||
if x < 27: W[l] = x | ||
# divmod is faster than the regular // and % | ||
else: k = r-(l+r)//2; p, q = divmod(x, 27**k); Q.append((q, l, l+k-1)); Q.append((p, l+k, r)) | ||
while W[-1] == 0: W.pop() | ||
|
||
for i in S: | ||
t = ord(i)-65 | ||
if t < 0: t = 26 | ||
t += W.pop(); t %= 27 | ||
if t == 26: Z.append(' ') | ||
else: Z.append(chr(t+65)) | ||
sys.stdout.write(''.join(Z)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
n = int(input()) | ||
p = [[2*i] for i in range(1, 21)]+[[50]] | ||
for i in [*p]: | ||
for x in range(1, 21): p.append([x]+i); p.append([2*x]+i); p.append([3*x]+i) | ||
p.append([25]+i); p.append([50]+i) | ||
for i in [*p]: | ||
for x in range(1, 21): p.append([x]+i); p.append([2*x]+i); p.append([3*x]+i) | ||
p.append([25]+i); p.append([50]+i) | ||
for i in p: | ||
if sum(i)==n: | ||
for j in range(len(i)-1): | ||
if i[j]==50: print('bullseye') | ||
elif i[j]==25: print('single bull') | ||
elif i[j]%3==0: print('triple', i[j]//3) | ||
elif i[j]%2==0: print('double', i[j]//2) | ||
else: print('single', i[j]) | ||
if i[-1] == 50: print('bullseye') | ||
else: print('double', i[-1]//2) | ||
exit(0) | ||
print('impossible') |
10 changes: 10 additions & 0 deletions
10
src/Counting Greedily Increasing Supersequences/countinggis.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import sys; input = sys.stdin.readline; from array import * | ||
N, L = map(int, input().split()); A = array('i', map(int, input().split())); Z = array('i'); C = K = 0; X = 1; M = 10**9+7 | ||
if A[-1] != N or any(A[i]>=A[i+1] for i in range(L-1)): print(0), exit(0) | ||
for i in range(L): | ||
while C <= A[i]-1: Z.append(L-i); C += 1 | ||
while C < N: Z.append(L-i); C += 1 | ||
for i in range(N)[::-1]: | ||
if A and A[-1] == i+1: A.pop() | ||
else: X *= Z[i]+K; K += 1; X %= M | ||
print(X) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from math import * | ||
s, r, n, z = map(float, input().split()); n = round(n); z = round(z); ans = 0 | ||
for k in range(n+1): | ||
f = r/s | ||
if k*f*f*100 > z: continue | ||
if f <= 1/3: ans = k | ||
if 2 < k < 7 and (1-f)/sin(pi*(1-2/k)/2) >= 2*f/sin(2*pi/k): ans = k | ||
if k == 2 and f <= 1/2: ans = k | ||
if k == 1 and f <= 1: ans = k | ||
print(ans) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from functools import * | ||
N, L, *W = map(int, open(0).read().split()); W += [10**9] | ||
@cache | ||
def f(i, a, b, c, d): | ||
if not a<=b<=c<=d: return f(i, *sorted((a, b, c, d))) | ||
if a < 0 or b < 0 or c < 0 or d < 0: return -1 | ||
if W[i]+1 > max(a, b, c, d): return i | ||
return max(f(i+1, a-W[i]-1, b, c, d), f(i+1, a, b-W[i]-1, c, d), f(i+1, a, b, c-W[i]-1, d), f(i+1, a, b, c, d-W[i]-1)) | ||
print(f(0, *[L+1]*4)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from heapq import * | ||
N, *H = map(int, open(0).read().split()); H = sorted(H)[::-1] | ||
|
||
def f(x, n): | ||
Q = [(0, 1)]*n; z = w = 0 | ||
for h in H: | ||
if not Q or h+Q[0][0] > x: return 10**18 | ||
u, d = heappop(Q); z = max(z, u+h); w += d | ||
if d: heappush(Q, (u+h, 0)) | ||
return z*w | ||
|
||
Z = 10**18 | ||
for n in range(N//2, N+1): | ||
a, b = H[0], 2*H[0] | ||
while b-a>2: | ||
if f(μ:=b-(b-a)//3, n) > f(λ:=a+(b-a)//3, n): b = μ | ||
else: a = λ | ||
Z = min(Z, min(f(x, n) for x in range(a-2, b+3))) | ||
print(66*Z) # N ternary searches better than 2-layered ternary search |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
l = 'yuiophjklnm,.'; t, s = map(int, input().split()) | ||
S = input(); a = b = 0 | ||
for i in S: | ||
if i == ' ': a, b, = a+t, b+t | ||
elif i in l: a, b = a+t, b+1000 | ||
else: a, b = a+1000, b+t | ||
a, b = min(a, b+s), min(b, a+s) | ||
print(min(a, b)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from array import * | ||
m, n = map(int, input().split()); G = [{} for _ in range(m)]; V = [0]*m; S = [(0, -1)]; T = [array('b') for _ in range(m)] | ||
for _ in range(m-1): a, b, t = map(int, input().split()); G[a][b] = G[b][a] = t | ||
while S: | ||
u, p = S.pop() | ||
if V[u]: continue | ||
V[u] = 1 | ||
if p != -1: T[p].append(u) | ||
S.extend((v, u) for v in G[u] if u != p) | ||
L = max(map(len, T)); H = array('b', [-1]*(L*m*(n+1)*2)) | ||
def f(x, y, t, c): | ||
if y == len(T[x]) or t == 0: return 1 | ||
if H[(k:=(2*((n+1)*(L*x+y)+t)+c))] > -1: return H[k] | ||
A = 0; C = G[x][(Z:=T[x][y])] | ||
if c: | ||
ti = C | ||
while ti <= t: A = max(A, f(Z, 0, ti-C, c)+f(x, y+1, t-ti, 0)); ti += 1 | ||
ti = 2*C | ||
while ti <= t: A = max(A, f(Z, 0, ti-2*C, 0)+f(x, y+1, t-ti, c)); ti += 1 | ||
A = max(A, f(x, y+1, t, c)) # skip visiting to the y-th child of x) | ||
H[k] = A; return A | ||
print(f(0, 0, n, 1)-1) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import sys; input = sys.stdin.readline; from array import *; Z = 10**9+7 | ||
N, Q = map(int, input().split()); M = array('i', [-1]*N) | ||
for _ in range(Q): | ||
a, b = map(int, input().split()); a -= 1; b -= 1 | ||
if a < b: a, b = b, a | ||
M[a] = max(M[a], b) | ||
dp = array('i', [1]*(N+1)); P = 1; k = -1 | ||
for i in range(N): | ||
while k < M[i]: P -= dp[k]; k += 1 | ||
dp[i] = P%Z; P = 2*P%Z | ||
print(dp[-2]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sys; input = sys.stdin.readline; from bisect import * | ||
H = {} | ||
for i in range(int(input())): | ||
s = input().strip() | ||
if s not in H: H[s] = [] | ||
H[s].append(i) | ||
for _ in range(int(input())): | ||
X, s = input().strip().split(); X = int(X) | ||
r = bisect_left(H[s], X); D = 10**9 | ||
if r < len(H[s]): D = H[s][r]-X | ||
if r-1 < len(H[s]): D = min(D, H[s][r-1]-X, key=abs) | ||
print(D) |