input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
return int(input())
def MI():
return map(int,input().sp... | from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
import random
def I():
return int(input())
def MI():
return map(int,input().sp... | p02839 |
from collections import deque
from copy import copy
row, column = list(map(int, input().split()))
map1 = [list(map(int, input().split())) for _ in range(row)]
map2 = [list(map(int, input().split())) for _ in range(row)]
map_ = [[n1 - n2 for n1, n2 in zip(row1, row2)] for row1, row2 in zip(map1, map2)]
n = map... | R, C = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(R)]
B = [list(map(int, input().split())) for _ in range(R)]
dp = [0] * C
dp[0] = s = 1 << 6400
for row_a, row_b in zip(A, B):
for i, (a, b) in enumerate(zip(row_a, row_b)):
d = abs(a - b)
if i > ... | p02839 |
def examE():
H, W = LI()
A = [LI() for _ in range(H)]
B = [LI() for _ in range(H)]
Diff = [[0] * W for _ in range(H)]
M = 0
for i in range(H):
for j in range(W):
m = abs(A[i][j] - B[i][j])
Diff[i][j] = m
M += m
dp = [[0] * (W + 1) for _ ... | def examE():
H, W = LI()
A = [LI() for _ in range(H)]
B = [LI() for _ in range(H)]
Diff = [[0] * W for _ in range(H)]
M = 0
for i in range(H):
for j in range(W):
m = abs(A[i][j] - B[i][j])
Diff[i][j] = m
M += m
dp = [[0] * (W + 1) for _ ... | p02839 |
import sys
input = sys.stdin.buffer.readline
from collections import deque
def main():
H,W = list(map(int,input().split()))
p = [[0 for _ in range(W)] for _ in range(H)]
point = [[[] for _ in range(W)] for _ in range(H)]
for i in range(H):
a = list(map(int,input().split()))
... | import sys
input = sys.stdin.buffer.readline
def main():
H,W = list(map(int,input().split()))
point = [[0]*W for _ in range(H)]
for i in range(H):
a = list(map(int,input().split()))
for j in range(W):
point[i][j] += a[j]
for i in range(H):
b = list... | p02839 |
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
return sys.stdin.readline()[:-1]
def ruiseki(lst):
return [0]+list(accumulate(lst))
sys.setrecurs... | import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]
kouho = [[0] * (w) for _ in range(h)]
delta = abs(AA[0][0] - BB[0][0])
kouho[0][0] |= 1 << delta
for y in ra... | p02839 |
h,w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
kanousei = [[[0] * (100 ** 3) for i in range(w)] for j in range(h)]
kanousei[0][0][abs(a[0][0]-b[0][0])] = 1
kanousei[0][0][abs(b[0][0]-a[0][0])] = 1
for RangeFromZero... | h,w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
kanousei = [[[0] * (100 ** 2) for i in range(w)] for j in range(h)]
kanousei[0][0][abs(a[0][0]-b[0][0])] = 1
kanousei[0][0][abs(b[0][0]-a[0][0])] = 1
for RangeFromZero... | p02839 |
import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
grid = [None for _ in range(h)]
poss = [[set() for x in range(w)] for y in range(h)]
tmp = [list(map(int, input().split())) for _ in range(h * 2)]
for i, (l1, l2) in enumerate(zip(tmp, tmp[h:])):
grid[i] = [abs(x - y) for x, y... | import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [[0] * w for _ in range(h)]
poss[0][0... | p02839 |
import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [[0] * w for _ in range(h)]
poss[0][0... | import sys
input = sys.stdin.readline
def main():
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
g = [list(abs(x - y) for x, y in zip(l1, l2)) for l1, l2 in zip(a, b)]
poss = [0] * w
poss[0] |= 1 << 6... | p02839 |
import sys
input = sys.stdin.readline
def main():
H, W = list(map(int, input().split()))
P = W+1
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
L = 80*80
dp = [[False]*(L+1) for _ in range((W+1)*(H+1))]
for h in rang... | import sys
input = sys.stdin.readline
def main():
H, W = list(map(int, input().split()))
P = W+1
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
L = 80*80
dp = [[False]*(L+1) for _ in range((W+1)*(H+1))]
dp[P+1][abs(A... | p02839 |
h,w = list(map(int,input().split()))
al = []
for _ in range(h):
a = list(map(int,input().split()))
al.append(a)
bl = []
for _ in range(h):
b = list(map(int,input().split()))
bl.append(b)
abl = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
for j in range(w):
abl... | h,w = list(map(int,input().split()))
bitdp = [[0 for j in range(w)] for i in range(h)]
al = []
bl = []
for _ in range(h):
a = list(map(int,input().split()))
al.append(a)
for _ in range(h):
b = list(map(int,input().split()))
bl.append(b)
abl = [[] for i in range(h)]
for i in range(h):
for j ... | p02839 |
import sys
input = sys.stdin.readline
H,W=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(H)]
B=[list(map(int,input().split())) for i in range(H)]
SA=[[0]*W for i in range(H)]
for i in range(H):
for j in range(W):
SA[i][j]=abs(A[i][j]-B[i][j])
DP=[[0 for i ... | import sys
input = sys.stdin.readline
H,W=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(H)]
B=[list(map(int,input().split())) for i in range(H)]
SA=[[0]*W for i in range(H)]
for i in range(H):
for j in range(W):
SA[i][j]=abs(A[i][j]-B[i][j])
DP=[[0 for i ... | p02839 |
import sys
def main():
input = sys.stdin.readline
h, w = list(map(int, input().split()))
A = []
AB = []
for i in range(h):
row = list(map(int, input().split()))
A.append(row)
for i in range(h):
row = [abs(A[i][j] - int(b)) for j, b in enumerate(input().split())]
AB.append(row)
... | import sys
def main():
input = sys.stdin.readline
h, w = list(map(int, input().split()))
A = []
AB = []
A_append = A.append
AB_append = AB.append
for i in range(h):
row = list(map(int, input().split()))
A_append(row)
for i in range(h):
row = [abs(A[i][j] - int(b)) for j, b in enu... | p02839 |
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
return sys.stdin.readline().rstrip()
def main():
H,W=list(map(int,input().split()))
A=[[] for _ in range(H)]
B=[[] for _ in range(H)]
C=[[0]*W for _ in range(H)]
for i in range(H):
A[i]=list(map(int,input().spli... | import sys
sys.setrecursionlimit(10**9)
INF = 10**18
def input():
return sys.stdin.readline().rstrip()
def main():
H, W = list(map(int, input().split()))
A = [[] for _ in range(H)]
B = [[] for _ in range(H)]
C = [[0] * W for _ in range(H)]
minusdigit = 80 * 80 * 2
for i in... | p02839 |
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect,copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1
h,w=list(map(int,input().split()))
A=[list(map(int,input().split(... | #!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect,copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1
h,w=list(map(int,input().split()))
A=[tuple(map(int,input().split... | p02839 |
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
Diff = [[False] * (W + 1) for _ in range(H + 1)]
M = 0
for i in range(H):
for j in range(W):
m = abs(A[i][j] - B[i][j])
Diff[i][j] = m
... | H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
Diff = [[0] * (W + 1) for _ in range(H + 1)]
M = 0
for i in range(H):
for j in range(W):
m = abs(A[i][j] - B[i][j])
Diff[i][j] = m
... | p02839 |
def main():
# import sys
# readline = sys.stdin.readline
# readlines = sys.stdin.readlines
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
M = 0
grid = [[0] * W for _ in range(H... | def main():
# import sys
# readline = sys.stdin.readline
# readlines = sys.stdin.readlines
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
M = 0
grid = [[0] * W for _ in range(H... | p02839 |
def main():
# import sys
# readline = sys.stdin.readline
# readlines = sys.stdin.readlines
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
M = 0
grid = [[0] * W for _ in range(H... | def main():
# import sys
# readline = sys.stdin.readline
# readlines = sys.stdin.readlines
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
M = 0
grid = [[0] * W for _ in range(H... | p02839 |
e=enumerate
(h,w),*a=[list(map(int,t.split()))for t in open(0)]
dp=[0]*w
c=12800
for i,a in e(list(zip(a,a[h:]))):
for j,(x,y)in e(list(zip(*a))):
x=abs(x-y)
t=0
if j:t|=dp[j-1]<<x|dp[j-1]>>x
if i:t|=dp[j]<<x|dp[j]>>x
dp[j]=t if i+j else 2**c<<x
*a,=list(map(int,(bin(dp[w-1])[2:]).zfill... | def main():
e=enumerate
(h,w),*a=[list(map(int,t.split()))for t in open(0)]
dp=[0]*w
c=12800
for i,a in e(list(zip(a,a[h:]))):
for j,(x,y)in e(list(zip(*a))):
x=abs(x-y)
t=0
if j:t|=dp[j-1]<<x|dp[j-1]>>x
if i:t|=dp[j]<<x|dp[j]>>x
dp[j]=t if i+j else 2**c<<x
*a,=... | p02839 |
def p_e():
h, w = list(map(int, input().split()))
t = [list(map(int, input().split())) for _ in range(h)]
m = 0
for i in range(h):
*b, = list(map(int, input().split()))
for j, e in enumerate(b):
t[i][j] = abs(t[i][j] - e)
if m < abs(t[i][j] - e):
... | def p_e():
from itertools import product
h, w = list(map(int, input().split()))
t1 = [list(map(int, input().split())) for _ in range(h)]
t2 = [list(map(int, input().split())) for _ in range(h)]
# pythonでbitsetを用いる->boolのDPで2進数の1をTrue, 0をFalseとして扱う
# 右にxシフト = その値にx足した値 (10001)<<4 -> (1... | p02839 |
def p_e():
from itertools import product
h, w = list(map(int, input().split()))
t1 = [list(map(int, input().split())) for _ in range(h)]
t2 = [list(map(int, input().split())) for _ in range(h)]
# pythonでbitsetを用いる->boolのDPで2進数の1をTrue, 0をFalseとして扱う
# 右にxシフト = その値にx足した値 (10001)<<4 -> (1... | def p_e():
h, w = list(map(int, input().split()))
t1 = [list(map(int, input().split())) for _ in range(h)]
t2 = [list(map(int, input().split())) for _ in range(h)]
# pythonでbitsetを用いる->boolのDPで2進数の1をTrue, 0をFalseとして扱う
# 右にxシフト = その値にx足した値 (10001)<<4 -> (100010000)
m = 160 * 80
d... | p02839 |
H,W = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
B = [list(map(int,input().split())) for i in range(H)]
C = [[] for i in range(H)]
for i,(arow,brow) in enumerate(zip(A,B)):
for a,b in zip(arow,brow):
d = abs(a-b)
C[i].append(d)
dp = [set() for i... | H,W = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
B = [list(map(int,input().split())) for i in range(H)]
C = [[] for i in range(H)]
for i,(arow,brow) in enumerate(zip(A,B)):
for a,b in zip(arow,brow):
d = abs(a-b)
C[i].append(d)
ofs = (H+W)*100
... | p02839 |
H,W = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
B = [list(map(int,input().split())) for i in range(H)]
C = [[] for i in range(H)]
for i,(arow,brow) in enumerate(zip(A,B)):
for a,b in zip(arow,brow):
d = abs(a-b)
C[i].append(d)
ofs = (H+W)*100
... | H,W = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
B = [list(map(int,input().split())) for i in range(H)]
C = [[abs(a-b) for a,b in zip(arow,brow)] for arow,brow in zip(A,B)]
ofs = 80*(H+W)
dp = [[0]*W for _ in range(H)]
dp[0][0] = (1<<(ofs+C[0][0])) | (1<<(ofs-C[0][0]))... | p02839 |
def main():
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
C = [[0] * W for _ in range(H)]
for h in range(H):
for w in range(W):
C[h][w] = abs(A[h][w] - B[h][w])
... | def main():
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
C = [[0] * W for _ in range(H)]
for h in range(H):
for w in range(W):
C[h][w] = abs(A[h][w] - B[h][w])
... | p02839 |
import sys
input=sys.stdin.readline
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
dp = [[[False for i in range(80 * h + 80 * w + 1)] for _ in range(1 + w)] for j in range(1 + h)]
# dp[i][j][k]=マスの(i,... | # Atcoder Problem Solving
H,W=list(map(int,input().split()))
c=[list(map(int,input().split())) for i in range(H)]
b=[list(map(int,input().split())) for i in range(H)]
a=[[0 for i in range(W)] for j in range(H)]
for i in range(H):
for j in range(W):
a[i][j]=abs(c[i][j]-b[i][j])
dp=[[0 fo... | p02839 |
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
arr = [set() for _ in range(W)]
arr[0].add(A[0][0] - B[0][0])
for x in range(1, W):
s = arr[x]
d = A[0][x] - B[0][x]
for n in arr[x-1]:
s.... | H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
arr = [set() for _ in range(W)]
arr[0].add(0)
for y in range(H):
nextarr = [set() for _ in range(W)]
Ay = A[y]
By = B[y]
dh = H - y - 1
f... | p02839 |
h,w = list(map(int,input().split()))
A = []
for _ in range(h):
a = list(map(int,input().split()))
A.append(a)
B = []
for _ in range(h):
b = list(map(int,input().split()))
B.append(b)
g = [[0]*(w+1) for _ in range(h+1)]
m = 0
for i in range(1,h+1):
for j in range(1,w+1):
g[i][j] ... | H, W = list(map(int, input().split()))
A = [None]*H
for i in range(H):
A[i] = list(map(int, input().split()))
B = [None]*H
for i in range(H):
B[i] = list(map(int, input().split()))
C = [[None]*W for _ in range(H)]
for i in range(H):
for j in range(W):
C[i][j] = abs(A[i][j]-B[i][j])
K ... | p02839 |
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
h,w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ma = 80*2*80
DP = [[[0]*ma for i in range(w)] for i in range(h)]
for i in range(h)... | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
h,w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ma = 80*2*80
DP = [[[0]*ma for i in range(w)] for i in range(h)]
for i in range(h)... | p02839 |
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
h,w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ma = 80*2*80
DP = [[[0]*ma for i in range(w)] for i in range(h)]
for i in range(h)... | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
h,w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
ma = 80*80+2
DP = [[[0]*ma for i in range(w)] for i in range(h)]
for i in range(h)... | p02839 |
def x():
return list(map(int,input().split()))
v=list
c=abs
r=range
h,w=x()
p=v(r(h))
a=[v(x())for i in p]
b=[v(x())for i in p]
m=13120
D=[[[0]*m for i in r(w)]for i in p]
for i in p:
for j in r(w):
k=c(a[i][j]-b[i][j])
if i|j:
for l in r((i+j+1)*80+1):
e=c(l-k)
D[i][j][l]=D[i][j-1][e]... | h,w = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(h)]
b = [list(map(int, input().split())) for i in range(h)]
# zeroは真ん中にする
ma = 80*2*80
DP = [[0]*w for i in range(h)]
for i in range(h):
for j in range(w):
k = abs(a[i][j]-b[i][j])
if i|j:
... | p02839 |
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
return list(map(int,input().split()))
def m(): #複数文字
return list(map(int,input().split()))
def onem(): #Nとかの取得
return int(eval(input()))
def s(x): ... | import sys
input = sys.stdin.readline
h, w = list(map(int, input().split()))
inf = float('INF')
A = []
B = []
for i in range(h):
line = list(map(int, input().split()))
A.append(line)
for i in range(h):
line = list(map(int, input().split()))
B.append(line)
D = [[0]*w for i in range(... | p02839 |
import bisect
import collections
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
q = collections.deque()
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = 0
for i in range(H):
for... | import bisect
import collections
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
q = collections.deque()
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = 0
for i in range(H):
for... | p02839 |
import bisect
import collections
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
q = collections.deque()
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = 0
for i in range(H):
for... | import bisect
import collections
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
q = collections.deque()
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = 0
for i in range(H):
for... | p02839 |
import bisect
import collections
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
q = collections.deque()
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = 0
for i in range(H):
for... |
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = (H+W)*80
dp = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
for ... | p02839 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
h, w = list(map(int, input().split()))
A = [list(map(int, input().split()))for i in range(h)]
B = [list(map(int, input().split()))for i in range(h)]
abss = [[abs(A[i][j]-B[i][j])for j in range(w)] for i in range(h)]
... | import sys
def input(): return sys.stdin.readline().rstrip()
def main():
h, w = list(map(int, input().split()))
A = [list(map(int, input().split()))for i in range(h)]
B = [list(map(int, input().split()))for i in range(h)]
abss = [[abs(A[i][j]-B[i][j])for j in range(w)] for i in range(h)]
... | p02839 |
import sys
input = sys.stdin.readline
I=lambda:int(eval(input()))
MI=lambda:list(map(int,input().split()))
LI=lambda:list(map(int,input().split()))
H,W=MI()
A=[LI() for _ in [0]*H]
B=[LI() for _ in [0]*H]
M=80*(H+W)
dp=[[[False]*(M+1) for _ in [0]*W] for _ in [0]*H]
dp[0][0][0]=True
m=M
for h in range... | import sys
input = sys.stdin.readline
MI=lambda:list(map(int,input().split()))
LI=lambda:list(map(int,input().split()))
H,W=MI()
A=[LI() for _ in [0]*H]
B=[LI() for _ in [0]*H]
G=[[set() for i in range(W)] for j in range(H)]
G[0][0].add(0)
for h in range(H):
for w in range(W):
d=A[h][w]-B[h... | p02839 |
import sys
def main():
input = sys.stdin.readline
H,W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
S = (80+80)*80//2
dp = [[[0]*(S+1) for _ in range(W)] for __ in range(H)]
dp[0][0]... | import sys
def main():
input = sys.stdin.readline
H,W = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = 160*80
dp =... | p02839 |
import sys
def main():
input = sys.stdin.readline
H,W=list(map(int, input().split()))
A=[list(map(int, input().split())) for _ in range(H)]
B=[list(map(int, input().split())) for _ in range(H)]
mx=80*(80+80)
C=[[A[i][j]-B[i][j] for j in range(W)] for i in range(H)]
dp=[[[0]*(mx*2+1... | import sys
def main():
input = sys.stdin.readline
H,W=list(map(int, input().split()))
A=[list(map(int, input().split())) for _ in range(H)]
B=[list(map(int, input().split())) for _ in range(H)]
mx=80*(H+W)
C=[[abs(A[i][j]-B[i][j]) for j in range(W)] for i in range(H)]
dp=[[0 for _ ... | p02839 |
import sys
def main():
input = sys.stdin.readline
H,W=list(map(int, input().split()))
A=[list(map(int, input().split())) for _ in range(H)]
B=[list(map(int, input().split())) for _ in range(H)]
mx=80*(H+W)
C=[[abs(A[i][j]-B[i][j]) for j in range(W)] for i in range(H)]
dp=[[0 for _ ... | import sys
def main():
input = sys.stdin.readline
H,W=list(map(int, input().split()))
A=[list(map(int, input().split())) for _ in range(H)]
B=[list(map(int, input().split())) for _ in range(H)]
mx=80*(H+W)
C=[[abs(A[i][j]-B[i][j]) for j in range(W)] for i in range(H)]
dp=[[0 for _ ... | p02839 |
def main():
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]
B = [[int(i) for i in input().split()] for _ in range(H)]
M = (H + W) * 80 + 1
u = [[False] * M for _ in range(W)]
v = [[False] * M for _ in range(W)]
v[0][0] = True
f... | def main():
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]
B = [[int(i) for i in input().split()] for _ in range(H)]
M = (H + W) * 80 + 1
u = [[False] * M for _ in range(W)]
v = [[False] * M for _ in range(W)]
F = [False] * M
... | p02839 |
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush... | def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush... | p02839 |
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)... | import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)... | p02839 |
def main():
B_MAX = (80 + 80 - 1) * 80
H, W = list(map(int, input().split(' ')))
A = [list(map(int, input().split(' '))) for _ in range(H)]
B = [list(map(int, input().split(' '))) for _ in range(H)]
dp = [[[0 for _ in range(B_MAX + 1)] for _ in range(W)] for _ in range(H)]
dp[0][0][abs(A[0... | def main():
B_MAX = (80 + 80 - 1) * 80 // 2
H, W = list(map(int, input().split(' ')))
A = [list(map(int, input().split(' '))) for _ in range(H)]
B = [list(map(int, input().split(' '))) for _ in range(H)]
dp = [[[0 for _ in range(B_MAX + 1)] for _ in range(W)] for _ in range(H)]
dp[0][0][ab... | p02839 |
h, w = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(h)]
b = [list(map(int, input().split())) for _ in range(h)]
k_max = 81 * (h + w)
dp = [[[0] * (k_max+1) for _ in range(w+1)] for _ in range(h+1)]
for i in range(h + 1):
dp[i][0][0] = 1
for j in range(w + 1):
d... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H,W = list(map(int,readline().split()))
A = [list(map(int,readline().split())) for _ in range(H)]
B = [list(map(int,readline().split())) for _ in range(H)]
X = (H + W) * 80
# X点持った状態から始める
dp ... | p02839 |
import sys
input = sys.stdin.readline
h,w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
grid = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
for j in range(w):
grid[i][j] = abs(a[i][j]-b[i][j])
... | h,w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
grid = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
for j in range(w):
grid[i][j] = abs(a[i][j]-b[i][j])
dp = [[0 for j in range(w)] for k in ra... | p02839 |
def getval():
h,w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
return h,w,a,b
def main(h,w,a,b):
dp = []
for i in range(w):
dp.append([False for j in range(1+160*(i+1))])
dp... | def getval():
h,w = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(h)]
b = [list(map(int,input().split())) for i in range(h)]
return h,w,a,b
def main(h,w,a,b):
dp = []
for i in range(w):
dp.append([False for j in range(1+160*(i+1))])
dp... | p02839 |
h,w = list(map(int,input().split()))
a = []
b = []
for i in range(h):
a1 = list(map(int,input().split()))
a.append(a1)
for i in range(h):
b1 = list(map(int,input().split()))
b.append(b1)
l = [[] for i in range(h)]
for i in range(h):
for j in range(w):
l[i].append(abs(a[i][j]-b[i]... | h,w = list(map(int,input().split()))
a = []
b = []
for i in range(h):
a1 = list(map(int,input().split()))
a.append(a1)
for i in range(h):
b1 = list(map(int,input().split()))
b.append(b1)
l = [[] for i in range(h)]
for i in range(h):
for j in range(w):
l[i].append(abs(a[i][j]-b[i]... | p02839 |
H, W = list(map(int, input().split()))
AB = []
for i in range(H):
AB.append(list(map(int, input().split())))
for i in range(H):
AB[i] = [abs(AB[i][j] - int(b)) for j, b in enumerate(input().split())]
K = 80*H*W
dp = [[[False]*K for w in range(W)] for h in range(H)]
dp[0][0][abs(AB[0][0])] = True
fo... | H, W = list(map(int, input().split()))
AB = []
for i in range(H):
AB.append(list(map(int, input().split())))
for i in range(H):
AB[i] = [abs(AB[i][j] - int(b)) for j, b in enumerate(input().split())]
K = 80*(H + W)
dp = [[[False]*K for w in range(W)] for h in range(H)]
dp[0][0][abs(AB[0][0])] = True
... | p02839 |
H, W = list(map(int, input().split()))
AB = []
max_ab = 0
for i in range(H):
AB.append(list(map(int, input().split())))
max_ab = max(max_ab, max(AB[-1]))
for i in range(H):
AB[i] = [abs(AB[i][j] - int(b)) for j, b in enumerate(input().split())]
K = max_ab*(H + W) + 1
dp = [[[False]*K for w in range(W... | H, W = list(map(int, input().split()))
AB = []
max_ab = 0
for i in range(H):
AB.append(list(map(int, input().split())))
max_ab = max(max_ab, max(AB[-1]))
for i in range(H):
AB[i] = [abs(AB[i][j] - int(b)) for j, b in enumerate(input().split())]
base = max_ab*(H + W)
dp = [[1 << base for w in range(W)... | p02839 |
import sys
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
D = [[0]*W for i in range(H)]
mx = 1
for i in range(H):
for j in range(W):
D[i][j] = abs(A[i][j]-B[i][j])
... | import sys
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(H)]
B = [list(map(int, input().split())) for i in range(H)]
D = [[0]*W for i in range(H)]
for i in range(H):
for j in range(W):
D[i][j] = abs(A[i][j]-B[i][j])
buf = 80*... | p02839 |
import sys
from collections import defaultdict
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A, B = [None] * H, [None] * H
for i in range(H):
A[i] = list(map(int, input().split()))
for i in range(H):
B[i] = list(map(int, input().split()))
C = [[abs(A[i][j] - B[i][j]) for j in range(... | import sys
input = sys.stdin.readline
H, W = list(map(int, input().split()))
A, B = [None] * H, [None] * H
for i in range(H):
A[i] = list(map(int, input().split()))
for i in range(H):
B[i] = list(map(int, input().split()))
C = [[abs(A[i][j] - B[i][j]) for j in range(W)] for i in range(H)]
M = 80*(80+80... | p02839 |
#!/usr/bin/env python3
import sys
INF = float("inf")
def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):
base = [[None]*W for _ in range(H)]
for h in range(H):
for w in range(W):
base[h][w] = abs(A[h][w]-B[h][w])
table = [[0 for _ in range(W)] for _ in ra... | #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):
base = [[abs(A[h][w]-B[h][w]) for w in range(W)] for h in range(H)]
mx = (1 << 12800) - 1
table = [[0]*W for _ in range(H)]
table[0][0] = (1 << (6400 + base[0][0])) | (1... | p02839 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | p02839 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | p02839 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | p02839 |
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
H, W = list(map(int, readline().split()))
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, rea... | p02839 |
import sys
input = sys.stdin.readline
H,W = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
B = [list(map(int,input().split())) for i in range(H)]
C = [[0]*W for i in range(H)]
M = 0
for h in range(H):
for w in range(W):
C[h][w] = abs(A[h][w] - B[h][w])... | import sys
input = sys.stdin.readline
H,W = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
B = [list(map(int,input().split())) for i in range(H)]
C = [[0]*W for i in range(H)]
M = 0
for h in range(H):
for w in range(W):
C[h][w] = abs(A[h][w] - B[h][w])... | p02839 |
import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]
kouho = [[set() for _ in range(w)] for _ in range(h)]
delta = AA[0][0] - BB[0][0]
kouho[0][0].add(delta)
kou... | import sys
input = sys.stdin.buffer.readline
h, w = list(map(int, input().split()))
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]
kouho = [[set() for _ in range(w)] for _ in range(h)]
delta = AA[0][0] - BB[0][0]
kouho[0][0].add(delta)
k... | p02839 |
import sys
from heapq import heappush, heapify
def solve():
file_input = sys.stdin
N, R, L = list(map(int, file_input.readline().split()))
hq = []
m = {}
for i in range(1, N + 1):
team = [0, i, 0]
heappush(hq, team)
m[i] = team
time = 0
for l... | import sys
from heapq import heappush, heappop
def solve():
file_input = sys.stdin
N, R, L = list(map(int, file_input.readline().split()))
hq = []
m = {}
for i in range(1, N + 1):
team = [0, i, 0]
heappush(hq, team)
m[i] = team
time = 0
for l... | p00277 |
import sys
from heapq import heappush, heappop, heapreplace
def solve():
file_input = sys.stdin
N, R, L = list(map(int, file_input.readline().split()))
pq = [[0, i, 0] for i in range(1, N + 1)]
m = dict(list(zip(list(range(1, N + 1)), pq)))
pre_t = 0
for line in file_input:... | import sys
from heapq import heappush, heappop, heapreplace
def solve():
file_input = sys.stdin
N, R, L = list(map(int, file_input.readline().split()))
pq = [[0, i] for i in range(1, N + 1)]
m = dict(list(zip(list(range(1, N + 1)), pq)))
time = [0] * (N + 1)
INVALID = -1
... | p00277 |
n, r, l = list(map(int, input().split()))
leaf_num = 1
while leaf_num < n:
leaf_num *= 2
tree = [None] * (leaf_num * 2 - 1)
for i in range(n):
tree[leaf_num - 1 + i] = (i, 0)
def set_value(index):
if leaf_num - 1 <= index <= leaf_num * 2 - 2:
return tree[index]
t1 = set_value(index * 2 + 1)
... | import sys
input = sys.stdin.readline
def main():
n, r, l = list(map(int, input().split()))
leaf_num = 1
while leaf_num < n:
leaf_num *= 2
INF = 10 ** 20
tree = [None] * (leaf_num * 2 - 1)
save = [0] * n
for i in range(n):
tree[leaf_num - 1 + i] = i
def set_value(index):
... | p00277 |
n, r, l = list(map(int, input().split()))
point, time = [], []
for i in range(n):
point.append(0)
time.append(0)
now, tv = 0, 0
for i in range(r):
d, t, x = list(map(int, input().split()))
time[tv] += t - now
now = t
point[d-1] += x
m = sorted(point, reverse=True)[0]
i = ... | n, r, l = list(map(int, input().split()))
point, time = [], []
rev = {0: []}
for i in range(n):
point.append(0)
time.append(0)
rev[0].append(i)
now, tv = 0, 0
for i in range(r):
d, t, x = list(map(int, input().split()))
time[tv] += t - now
now = t
rev[point[d-1]].remove(d-1)
... | p00277 |
n,r,l=list(map(int,input().split()))
log=[list(map(int,input().split())) for i in range(r)]
log.insert(0,[1,0,0])
log.append([1,l,0])
id_t=[0]*n
id_x=[0]*n
max_id=0
for i in range(1,r+2):
cur_id=log[i][0]-1
id_t[max_id]+=log[i][1]-log[i-1][1]
id_x[cur_id]+=log[i][2]
if log[i][2]<0:
max_id=id_x.index(m... | n,r,l=list(map(int,input().split()))
log=[list(map(int,input().split())) for i in range(r)]
log.insert(0,[1,0,0])
log.append([1,l,0])
id_t=[0]*n
id_x=[0]*n
max_id=0
for i in range(1,r+2):
cur_id=log[i][0]-1
id_t[max_id]+=log[i][1]-log[i-1][1]
id_x[cur_id]+=log[i][2]
if cur_id==max_id and log[i][2]<0:
... | p00277 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0282
"""
import sys
from sys import stdin
from heapq import heappop, heappush
input = stdin.readline
pq = [] # list of entries arranged in a heap
entry_finder = {} # mapping of tasks... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0282
"""
import sys
from sys import stdin
from heapq import heappop, heappush
input = stdin.readline
pq = [] # list of entries arranged in a heap
entry_finder = {} # mapping of tasks... | p00277 |
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0282
"""
import sys
from sys import stdin
from heapq import heappop, heappush
input = stdin.readline
pq = [] # list of entries arranged in a heap
entry_finder = {} # mapping of tasks... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0282
"""
import sys
from sys import stdin
from heapq import heappop, heappush
input = stdin.readline
pq = [] # list of entries arranged in a heap
entry_finder = {} # mapping of tasks... | p00277 |
import heapq
def d_manhattan(node_list):
s = 0
for i in range(9):
x_goal = i%3
y_goal = i//3
x_now = (node_list[i] - 1)%3
y_now = (node_list[i] - 1)//3
if y_now == -1:
y_now = 2
dx = abs(x_now - x_goal)
dy = abs(y_now - y_goal)
... | import heapq
def d_manhattan(node_list):
s = 0
for i in range(9):
x_goal = i%3
y_goal = i//3
x_now = (node_list[i] - 1)%3
y_now = (node_list[i] - 1)//3
if y_now == -1:
y_now = 2
dx = abs(x_now - x_goal)
dy = abs(y_now - y_goal)
... | p02245 |
import copy
def movable_state(state):
x, y = None, None
for i in range(3):
for j in range(3):
if state[i][j] == 0:
x, y = i, j
break
rsts = []
for r, c in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
if 0 <= r and r < 3 and 0 <= c an... | import copy
def movable_state(state):
x, y = None, None
for i in range(3):
for j in range(3):
if state[3*i+j] == 0:
x, y = i, j
break
rsts = []
for r, c in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
if 0 <= r and r < 3 and 0 <= c a... | p02245 |
from collections import deque, OrderedDict
class Puzzle:
def __init__(self, field=None, path=''):
self.f = field
self.space = None
for i in range(9):
if self.f[i] == 9:
self.space = i
self.path = path
def __lt__(self, pzl): # <
fo... | from collections import deque, OrderedDict
class Puzzle:
def __init__(self, field=None, path=''):
self.f = field
self.space = None
for i in range(9):
if self.f[i] == 9:
self.space = i
self.path = path
def __lt__(self, pzl): # <
fo... | p02245 |
from heapq import heappop, heappush
from copy import deepcopy
class Board:
def __init__(self, size, nums):
self.size = size
self.nums = nums
self.code = self._code()
def __eq__(self, other):
return self.code == other.code
def __lt__(self, other):
ret... | from heapq import heappop, heappush
from copy import deepcopy
class Board:
def __init__(self, size, nums):
self.size = size
self.nums = nums
self.code = self._code()
def __eq__(self, other):
return self.code == other.code
def __lt__(self, other):
ret... | p02245 |
import sys;
import queue;
def iterative(i,j,c_depth,c_puz):
if(puzzleCheck(c_puz)):
global finding
finding = 1
print(c_depth)
if(finding == 1 or (c_depth+HS(c_puz)) > depth):
return
if(i != 0):
iterative(i-1,j,c_depth+1,swapPuz(c_puz[0:],i,j,i-1,j))
... | import sys;
import queue;
def iterative(i,j,c_depth,c_puz):
if(puzzleCheck(c_puz)):
global finding
finding = 1
print(c_depth)
if(finding == 1 or (c_depth+HS(c_puz)) > depth):
return
if(i != 0):
iterative(i-1,j,c_depth+1,swapPuz(c_puz[0:],i,j,i-1,j))
... | p02245 |
import sys;
import queue;
def iterative(i,j,c_depth,c_puz):
if(puzzleCheck(c_puz)):
global finding
finding = 1
print(c_depth)
if(finding == 1 or (c_depth+HS(c_puz)) > depth or (c_depth+simpleHS(c_puz)) > depth):
return
if(i != 0 and finding != 1):
iter... | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(0,i,j,puz))
global finding
while len(q):
items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
c_puz = items[3]
if(puzzleCheck(c_puz)):
fin... | p02245 |
import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(0,i,j,puz))
global finding
while len(q):
items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
c_puz = items[3]
if(puzzleCheck(c_puz)):
fin... | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(0,i,j,0,puz))
global finding
while len(q):
items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]
if(puzzl... | p02245 |
import sys;
import heapq
def iterative(i,j):
q = []
q.append((simpleHS(puz),0,i,j,0,puz))
global finding
while len(q):
items = q.pop()
c_dWithH = items[0]
c_depth = items[1]
_i = items[2]
_j = items[3]
prev_move = items[4]
c_puz = ... | import sys;
import heapq
def iterative(i,j):
q = []
q.append((simpleHS(puz),0,i,j,0,puz))
global finding
while len(q):
items = q.pop(0)
c_dWithH = items[0]
c_depth = items[1]
_i = items[2]
_j = items[3]
prev_move = items[4]
c_puz =... | p02245 |
import sys;
import heapq
def iterative(i,j):
q = []
q.append((sumCost(costs),0,i,j,0,puz,costs))
global finding
while len(q):
items = q.pop(0)
cost = items[0]
c_depth = items[1]
_i = items[2]
_j = items[3]
prev_move = items[4]
c_pu... | import sys;
import heapq
def iterative(i,j):
q = []
q.append((simpleHS(puz),0,i,j,0,puz))
global finding
while len(q):
items = q.pop(0)
c_dWithH = items[0]
c_depth = items[1]
_i = items[2]
_j = items[3]
prev_move = items[4]
c_puz =... | p02245 |
import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(simpleHS(puz),(0,i,j,0,puz)))
global finding
while len(q):
c_dWithH, items = q.pop(0)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]... | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(sumcost,(0,i,j,0,puz)))
global finding
while len(q):
c_dWithH, items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[... | p02245 |
import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(sumcost,(0,i,j,0,puz)))
global finding
while len(q):
c_dWithH, items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[... | import sys;
import heapq
def iterative(i,j):
q = []
heapq.heappush(q,(sumcost,(0,i,j,0,puz)))
global finding
while len(q):
cost, items = heapq.heappop(q)
c_depth = items[0]
_i = items[1]
_j = items[2]
prev_move = items[3]
c_puz = items[4]
... | p02245 |
from collections import deque
from copy import deepcopy, copy
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
N = 3
def MAIN():
MAP = tuple(sum([input().split() for _ in range(N)], []))
y0, x0 = divmod(MAP.index("0"), N)
goal = ('1', '2', '3', '4', '5', '6', '7', '8', '0')
ans = 0
dp = deque([[y0, x... | from collections import deque
from copy import deepcopy, copy
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
N = 3
def g(i, j, a):
t = a // (10 ** j) % 10
return a - t * (10 ** j) + t * (10 ** i)
def MAIN():
m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0... | p02245 |
from heapq import heapify, heappush, heappop
from collections import deque
from copy import deepcopy, copy
N = 3
m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}
def g(i, j, a):
if i > j:
i, j = j, i
return a[:i] + a[j] + a[i + 1:j]... | from collections import deque
N = 3
def g(i, j, a):
if i > j:
i, j = j, i
return a[:i] + a[j] + a[i + 1:j] + a[i] + a[j + 1:]
goal = "123456780"
def solve():
m = {8:{7, 5}, 7:{8, 6, 4}, 6:{7, 3}, 5:{8, 4, 2}, 4:{7, 5, 3, 1}, 3:{6, 4, 0}, 2:{5, 1}, 1:{4, 2, 0}, 0:{3, 1}}
MAP = "".join(in... | p02245 |
import sys, itertools
f = sys.stdin
start = [line.split() for line in f]
start = tuple(int(x) for y in start for x in y)
end =(1, 2, 3, 4, 5, 6,7, 8, 0)
d = {start:0}
def next_board(b):
brank = b.index(0)
if brank % 3:
yield b[:brank - 1] + (b[brank], b[brank - 1]) + b[brank + 1:]
if... | from sys import stdin
readline = stdin.readline
adjacent = (
(1, 3), # 0
(0, 2, 4), # 1
(1, 5), # 2
(0, 4, 6), # 3
(1, 3, 5, 7), # 4
(2, 4, 8), # 5
(3, 7), # 6
(4, 6, 8), # 7
(5, 7) # 8
)
def next_board(board, space, ... | p02245 |
# -*- coding: utf-8 -*-
from collections import deque
import copy
class Puzzle(list):
def __init__(self):
list.__init__(self)
self.space = None
self.path = ""
def __hash__(self):
return hash(str(self[:]))
if __name__ == '__main__':
N = 3
N2 =... | # -*- coding: utf-8 -*-
from collections import deque
import copy
class Puzzle(list):
def __init__(self):
list.__init__(self)
self.space = None
self.path = ""
def __hash__(self):
return hash(str(self[:]))
if __name__ == '__main__':
N = 3
N2 =... | p02245 |
# -*- coding: utf-8 -*-
from collections import deque
import copy
class Puzzle(list):
def __init__(self):
list.__init__(self)
self.space = None
self.path = ""
def __hash__(self):
return hash(str(self[:]))
if __name__ == '__main__':
N = 3
N2 =... | # -*- coding: utf-8 -*-
from collections import deque
import copy
class Puzzle(list):
def __init__(self):
list.__init__(self)
self.space = None
self.path = ""
def __hash__(self):
return hash(str(self[:]))
if __name__ == '__main__':
N = 3
N2 =... | p02245 |
import copy
def hashnum(state):
num = 0
for i in range(3):
for j in range(3):
num *= 10
num += state[i][j]
return num
answer = 123456780
ini_state = []
for i in range(3):
temp = [int(n) for n in input().split(" ")]
if 0 in temp:
zero_x, zero_y =... | import copy
def hashnum(state):
num = 0
for i in range(3):
for j in range(3):
num *= 10
num += state[i][j]
return num
answer = 123456780
ini_state = []
for i in range(3):
temp = [int(n) for n in input().split(" ")]
if 0 in temp:
zero_x, zero_y =... | p02245 |
import copy
def hashnum(state):
num = 0
for i in range(3):
for j in range(3):
num *= 10
num += state[i][j]
return num
answer = 123456780
ini_state = []
for i in range(3):
temp = [int(n) for n in input().split(" ")]
if 0 in temp:
zero_x, zero_y =... | import copy
def hashnum(state):
num = 0
for i in range(3):
for j in range(3):
num *= 10
num += state[i][j]
return num
answer = 123456780
ini_state = []
for i in range(3):
temp = [int(n) for n in input().split(" ")]
if 0 in temp:
zero_x, zero_y =... | p02245 |
# 8 Puzzle
import copy
z = 0
[N, d] = [3, 0]
check_flag = [[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4],
[2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1],
[3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2],
[4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3],
[3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4... | # 8 Puzzle
import copy
[N, d] = [3, 0]
start = []
goal = [[i + j*N for i in range(1, N + 1)] for j in range(N)]
goal[2][2] = 0
for i in range(N):
start.append(list(map(int, input().split())))
def manhattan(value, pairs):
h = 0
if value == 1:
h = (pairs[0] + pairs[1])
if value =... | p02245 |
v,e = list(map(int, input().split()))
adj = [list(map(int, input().split())) for i in range(e)]
adj.sort(key = lambda x:x[2])
group = [[i] for i in range(v)]
key = [i for i in range(v)]
sum = 0
for i,j,k in adj:
if key[i] != key[j]:
h = key[j]
group[key[i]] += group[h]
sum += k
... | def root(x):
if par[x] == x:
return x
par[x] = root(par[x])
return par[x]
def same(x, y):
return root(x) == root(y)
def unite(x, y):
x = root(x)
y = root(y)
par[x] = y
v,e = list(map(int, input().split()))
adj = [list(map(int, input().split())) for i in range(e)]
a... | p02364 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6
output:
5
"""
import sys
import heapq as hp
WHITE, GRAY, BLACK = 0, 1, 2
def generate_adj_table(v_table):
for each in v_table:
v_from, v_to, edge_weight = list... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6
output:
5
"""
import sys
import heapq as hp
WHITE, GRAY, BLACK = 0, 1, 2
def generate_adj_table(v_table):
for each in v_table:
v_from, v_to, edge_weight = list... | p02364 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6
output:
5
"""
import sys
from operator import attrgetter
class Edge(object):
__slots__ = ('source', 'target', 'weight')
def __init__(self):
self.weight = f... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6
output:
5
"""
import sys
import heapq as hp
WHITE, GRAY, BLACK = 0, 1, 2
def generate_adj_table(v_table):
for each in v_table:
v_from, v_to, edge_weight = list... | p02364 |
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6
output:
5
"""
import sys
from operator import attrgetter
class Edge(object):
__slots__ = ('source', 'target', 'weight')
def __init__(self):
self.weight = f... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6
output:
5
"""
import sys
from operator import attrgetter
class Edge(object):
__slots__ = ('source', 'target', 'weight')
def __init__(self):
self.weight = f... | p02364 |
import sys
class UnionFind:
def __init__(self, node_size):
self._node = node_size
self.par = [i for i in range(self._node)]
self.rank = [0] * self._node
def find(self, ver):
if self.par[ver] == ver:
return ver
else:
self.par[ver] = ... | import sys
class UnionFind:
def __init__(self, node_size):
self._node = node_size
self.par = [i for i in range(self._node)]
self.rank = [0] * self._node
def find(self, ver):
if self.par[ver] == ver:
return ver
else:
self.par[ver] = ... | p02364 |
import sys
def kruskal(v_count: int, edges: list) -> int:
tree = [-1]*v_count
def get_root(x):
if tree[x] < 0:
return x
tree[x] = get_root(tree[x])
return tree[x]
def unite(x, y):
x, y = get_root(x), get_root(y)
if x != y:
big,... | import sys
from itertools import islice
def kruskal(v_count: int, edges: list) -> int:
tree = [-1]*v_count
def get_root(x):
if tree[x] < 0:
return x
tree[x] = get_root(tree[x])
return tree[x]
def unite(a):
x, y = get_root(a[1]), get_root(a[2])
... | p02364 |
from heapq import heappush, heappop
class Prim:
""" find minimum spanning tree by Prim's algorithm
"""
def __init__(self, V, E, start=0, INF=10**9):
""" V: the number of vertexes
E: adjacency list (undirected graph)
start: start vertex
INF: Infinity cost... | class UnionFindTree:
"""Disjoint-Set Data Structure
Union-Find Tree
used in SRM505 div.2 900
"""
def __init__(self, n):
self.par = list(range(n)) # parent
self.rank = [0] * n # depth of tree
def find(self, x):
if self.par[x] == x:
re... | p02364 |
class UnionFindTree:
"""Disjoint-Set Data Structure
Union-Find Tree
used in SRM505 div.2 900
"""
def __init__(self, n):
self.par = list(range(n)) # parent
self.rank = [0] * n # depth of tree
def find(self, x):
if self.par[x] == x:
re... | class UnionFindTree:
"""Disjoint-Set Data Structure
Union-Find Tree
used in SRM505 div.2 900
"""
def __init__(self, n):
self.par = list(range(n)) # parent
self.rank = [0] * n # depth of tree
def find(self, x):
if self.par[x] == x:
re... | p02364 |
import array
import collections
import heapq
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
INF = 2 ** 31 - 1
NO_VERTEX = -1
# Prim?????§??????0?????????????°???¨?????¨????±???????
def compute_mst_prim(max_v, adj_list):
# pred[u]?????????u???????????¨???????????????????????¨??... | import heapq
from collections import defaultdict
INF = float('inf')
V, E = list(map(int, input().split()))
Adj_list = defaultdict(set)
for i in range(E):
s, t, w = list(map(int, input().split()))
Adj_list[s].add((t, w))
Adj_list[t].add((s, w))
def prim(x):
d = [INF] * x
d[0]... | p02364 |
import heapq
def prim(g, v):
for vi in range(v):
g[vi].sort()
cost = 0
heap = iter(g[0])
rest_tree = set(range(1, v))
while rest_tree:
d, u = next(heap)
if u in rest_tree:
cost += d
rest_tree -= {u}
heap = heapq.merge(heap... | def kruskal(g, size):
g.sort(key=itemgetter(2), reverse=True)
uf = union_find(size)
tree = []
while len(tree) < size - 1:
u, v, d = g.pop()
if not uf.union(u, v):
tree.append((u, v, d))
return tree
class union_find:
def __init__(self, size):
self.... | p02364 |
# -*- coding: utf-8 -*-
V, E = list(map(int, input().split()))
weight = []
for i in range(E):
s, t, w = list(map(int, input().split()))
weight.append((s,t,w))
weight.sort(key = lambda x: x[2])
parent = [i for i in range(V)]
def find(x):
if parent[x] == x:
return x
else:
return find(p... | # -*- coding: utf-8 -*-
V, E = list(map(int, input().split()))
weight = []
for i in range(E):
s, t, w = list(map(int, input().split()))
weight.append((s,t,w))
weight.sort(key = lambda x: x[2])
parent = [i for i in range(V)]
def find(x):
if parent[x] == x:
return x
else:
return find(p... | p02364 |
from collections import defaultdict
import heapq
vertices,edges = list(map(int,input().split(" ")))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
source,target,w = list(map(int,input().split(" ")))
link[source] = link.get(source,set()) | {ta... | from collections import defaultdict
import heapq
vertices,edges = list(map(int,input().split(" ")))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
source,target,w = list(map(int,input().split(" ")))
link[source] = link.get(source,set()) | {ta... | p02364 |
from collections import defaultdict
import heapq
vertices,edges = list(map(int,input().split(" ")))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
source,target,w = list(map(int,input().split(" ")))
link[source] = link.get(source,set()) | {ta... | from collections import defaultdict
import heapq
vertices, edges = (int(n) for n in input().split(" "))
conn = defaultdict(set)
weight = defaultdict(dict)
for i in range(edges):
v1, v2, w = (int(n) for n in input().split(" "))
conn[v1] |= {v2}
conn[v2] |= {v1}
weight[v1][v2] = w
weight[v2]... | p02364 |
import sys
class UnionFind():
def __init__(self, n):
self.n = n
self.p = [i for i in range(n + 5)]
self.rank = [0 for i in range(n + 5)]
def find_set(self, x):
if self.p[x] != x:
self.p[x] = self.find_set(self.p[x])
return self.p[x]
def u... | import sys
class UnionFind:
def __init__(self, nvertices):
self.rank = [1] * (nvertices + 5)
self.p = [i for i in range(nvertices + 5)]
def find_set(self, u):
if u != self.p[u]:
self.p[u] = self.find_set(self.p[u])
return self.p[u]
def unite(sel... | p02364 |
X, A = list(map(int, input().split()))
if X < A:
print('0')
else:
print('10') | X, A = list(map(int, input().split()))
if X < A:
print((0))
else:
print((10))
| p02999 |
x, a = list(map(int, input().split()))
if x < a:
print((0))
if x >= a:
print((10)) | def main():
x, a = list(map(int, input().split()))
if x < a:
print((0))
else:
print((10))
if __name__ == '__main__':
main() | p02999 |
x,a=list(map(int,input().split()));print(((x>=a)*10)) | x,a=input().split();print(((x>=a)*10)) | p02999 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.