-
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
7beac79
commit d5750c0
Showing
12 changed files
with
807 additions
and
498 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,7 @@ | ||
import sys; input = sys.stdin.readline; K = ((-1, -1), (0, -2), (0, -1), (1, -1)); from collections import *; from array import *; R, C = map(int, input().split()); M = [input().strip() for _ in range(R)]; D = array('i', [-1]*R*C); Q = deque([0]); D[0] = 0 | ||
while Q: | ||
rc = Q.popleft(); r, c = divmod(rc, C) | ||
if r == R-1: print(D[rc]+1), exit(0) | ||
for dr, dc in K: | ||
if r+dr>-1 and M[r+dr][(c+dc)%C]<'M'>M[r+dr][(c+dc+1)%C] and D[p:=(r+dr)*C+(c+dc)%C] < 0: Q.append(p); D[p] = D[rc]+1 | ||
print(-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,20 @@ | ||
def mul(a, b): | ||
c = [[0]*4 for _ in range(4)] | ||
for i in range(4): | ||
for j in range(4): | ||
c[i][j] = 0 | ||
for k in range(4): c[i][j] += a[i][k]*b[k][j] | ||
c[i][j] %= 10000 | ||
return c | ||
|
||
def matpow(mat, n): | ||
if n == 1: return mat | ||
elif n % 2: return mul(mat, matpow(mat, n-1)) | ||
return matpow(mul(mat, mat), n//2) | ||
|
||
# https://oeis.org/A001169 | ||
def f(n): | ||
M = ((0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1), (0, 4, -7, 5)); x = (1, 2, 6, 19) | ||
if n < 5: return x[n-1] | ||
A = matpow(M, n-4)[3]; return sum(A[i]*x[i] for i in range(4))%10000 | ||
for _ in range(int(input())): print(f'Case {_+1}:', f(int(input()))) |
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,14 @@ | ||
import sys; input = sys.stdin.readline | ||
while True: | ||
try: X, Y, Z, N = map(int, input().split()); ok = 1; V = 0 | ||
except: break | ||
A = [[*map(int, input().split())] for _ in range(N)]; S = [[*map(int, input().split())] for _ in range(N)] | ||
for i in range(N): | ||
if not ok: break | ||
sx, sy, sz, ex, ey, ez = S[i]; cx, cy, cz = A[i]; V += (ex-sx+1)*(ey-sy+1)*(ez-sz+1) | ||
if not (sx<=cx<=ex<=X and sy<=cy<=ey<=Y and sz<=cz<=ez<=Z): ok = 0; break | ||
for j in range(i): | ||
tx, ty, tz, fx, fy, fz = S[j] | ||
if min(ex, fx) >= max(sx, tx) and min(ey, fy) >= max(sy, ty) and min(ez, fz) >= max(sz, tz): ok = 0; break | ||
ok &= V==X*Y*Z | ||
print('YNEOS'[1-ok::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,11 @@ | ||
import sys; input = sys.stdin.readline; from array import * | ||
while True: | ||
R, C, N = map(int, input().split()) | ||
if R < 1: break | ||
Z = 0; D = array('b', [1]*R); E = array('b', [1]*C); F = array('b', [1]*(R+C)); G = array('b', [1]*(R+C)) | ||
for _ in range(N): r, c = map(int, input().split()); r -= 1; c -= 1; D[r] = 0; E[c] = 0; F[r+c] = 0; G[r-c+C] = 0 | ||
E = array('h', (i for i in range(C) if E[i])) | ||
for r in array('h', (i for i in range(R) if D[i])): | ||
for c in E: | ||
if F[r+c] and G[r-c+C]: Z += 1 | ||
print(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,22 @@ | ||
import sys; input = sys.stdin.readline; sys.setrecursionlimit(11**4); reg = {} | ||
def parse(l, r): | ||
if e[l] == '"': return e[l+1:r-1] | ||
if e[l] != '`': return reg[e[l:r]] | ||
s = ''; p = l+1 | ||
while p < r-1: | ||
if e[p] != '$' or (e[p] == '$' and e[p+1] != '{'): | ||
s += e[p]; p += 1 | ||
if len(s) > 10**4: return '?' | ||
else: | ||
q = p+2; b = 1 | ||
while b: | ||
if e[q] == '{': b += 1 | ||
elif e[q] == '}': b -= 1 | ||
q += 1 | ||
s += parse(p+2, q-1); p = q | ||
if len(s) > 10**4 or (s and s[-1] == '?'): return '?' | ||
if len(s) > 10**4 or (s and s[-1] == '?'): return '?' | ||
return s | ||
while (s:=input().strip()[:-1])[0] != 'e': | ||
if s[0] == 'v': vn, *e = s[4:].split(' = '); e = ' = '.join(e); reg[vn] = parse(0, len(e)) | ||
else: e = s[6:]; print(parse(0, len(e))) |
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,5 @@ | ||
D, W, C = map(int, input().split()) | ||
while True: | ||
if (E:=min((W%C or C)/(L:=(W+C-1)//C*2-1), D)*L) > W: print(0); break | ||
D -= E/L; W -= E | ||
if D <= 0: print(W); break |
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,2 @@ | ||
#include<iostream> | ||
int n,a,x;main(){std::cin>>n;for(int i;i<n;i++){std::cin>>x;a+=(2-n+x)%2;}std::cout<<(a?"Ja":"Nej");} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
N=int(input());A=sum(int(input())%2for _ in'.'*N);print('NJeaj'[(N==1>A)|(N==2>2-A)|(N==3>A)::2]) | ||
N=int(input());print('NJeaj'[any((N-int(input()))%2for _ in'.'*N)::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 @@ | ||
N,*a=$<.map &:to_i;$><<(a.sum{|c|(N-c)%2}>0?'Ja':'Nej') |
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 array import *; from collections import * | ||
N, T, S = map(int, input().split()); A = deque(); L = array('i'); M = C = 0; W = deque() | ||
for _ in range(N): l, r = map(int, input().split()); A.append((l, r)); L.append(l) | ||
for i in L: | ||
while W and W[0][0] < i: l, r = W.popleft(); C -= r-l | ||
while A: | ||
if i+S <= A[0][0]: break | ||
if i >= A[0][1]: A.popleft() | ||
elif i+S < A[0][1]: l, r = A.popleft(); W.append((l, i+S)); A.appendleft((i+S, r)); C += i+S-l | ||
else: W.append(A.popleft()); C += W[-1][1]-W[-1][0] | ||
if M < C: M = C | ||
print(S-M) |