s_id stringlengths 10 10 | p_id stringlengths 6 6 | u_id stringlengths 10 10 | date stringlengths 10 10 | language stringclasses 1 value | original_language stringclasses 11 values | filename_ext stringclasses 1 value | status stringclasses 1 value | cpu_time stringlengths 1 5 | memory stringlengths 1 7 | code_size stringlengths 1 6 | code stringlengths 1 539k |
|---|---|---|---|---|---|---|---|---|---|---|---|
s285623623 | p00114 | u462831976 | 1494417081 | Python | Python3 | py | Runtime Error | 0 | 0 | 672 | # -*- coding: utf-8 -*-
import sys
import os
import math
def lcm(a, b):
return (a * b) // math.gcd(a, b)
for s in sys.stdin:
a1, m1, a2, m2, a3, m3 = map(int, s.split())
if a1 == m1 == a2 == m2 == a3 == m3 == 0:
break
x = 1
y = 1
z = 1
x_num = 0
while True:
x = (a1 * x) % m1
x_num += 1
if x == 1:
break
y_num = 0
while True:
y = (a2 * y) % m2
y_num += 1
if y == 1:
break
z_num = 0
while True:
z = (a3 * z) % m3
z_num += 1
if z == 1:
break
a = lcm(x_num, y_num)
b = lcm(a, z_num)
print(b) |
s327677388 | p00114 | u462831976 | 1494417514 | Python | Python3 | py | Runtime Error | 0 | 0 | 529 | # -*- coding: utf-8 -*-
import sys
import os
import math
def lcm(a, b):
return (a * b) // math.gcd(a, b)
def interval(a, m):
cnt = 0
x = 1
while True:
x = (a * x) % m
cnt += 1
if x == 1:
return cnt
for s in sys.stdin:
a1, m1, a2, m2, a3, m3 = map(int, s.split())
if sum([a1, m1, a2, m2, a3, m3]) == 0:
break
x_num = interval(a1, m1)
y_num = interval(a2, m2)
z_num = interval(a3, m3)
a = lcm(x_num, y_num)
b = lcm(a, z_num)
print(b) |
s209755795 | p00114 | u960312159 | 1509522495 | Python | Python3 | py | Runtime Error | 0 | 0 | 458 | from math import gcd
while True:
a = list(map(int, input().split()))
if a.count(0) == 6:
break
x = a[0] % a[1]
ix = 1
while x != 1:
x = a[0] * x % a[1]
ix += 1
y = a[2] % a[3]
iy = 1
while y != 1:
y = a[2] * y % a[3]
iy += 1
z = a[4] % a[5]
iz = 1
while z != 1:
z = a[4] * z % a[5]
iz += 1
ixy = ix * iy // gcd(ix, iy)
print(ixy * iz // gcd(ixy, iz)) |
s358269672 | p00115 | u260980560 | 1437215843 | Python | Python | py | Runtime Error | 20 | 4356 | 927 | def solve(A, b):
for i in xrange(3):
if A[i][i] == 0.0:
for j in xrange(i+1, 3):
if A[j][i]!=0.0:
A[i], A[j] = A[j], A[i]
b[i], b[j] = b[j], b[i]
for j in xrange(3):
if i==j:
continue
a = A[j][i] / A[i][i]
for k in xrange(3):
A[j][k] -= a * A[i][k]
b[j] -= a * b[i]
for i in xrange(3):
b[i] /= A[i][i]
A[i][i] /= A[i][i]
u = map(float, raw_input().split())
e = map(float, raw_input().split())
o = map(float, raw_input().split())
p = map(float, raw_input().split())
q = map(float, raw_input().split())
A = [[p[i]-o[i], q[i]-o[i], e[i]-u[i]] for i in xrange(3)]
b = [e[i] - o[i] for i in xrange(3)]
solve(A, b)
s, t, x = b
j = lambda x: -0.0000001 < x < 1.0000001
if j(s) and j(t) and j(s+t) and j(x):
print "MISS"
else:
print "HIT" |
s406740749 | p00115 | u619785977 | 1471417408 | Python | Python3 | py | Runtime Error | 0 | 0 | 72 | hdhafsdlqshflahsfhjs
afjahflka
fhajkfaslkdfa
fjajkfhajkh
djhfjaseafaf
xz |
s246910115 | p00115 | u462831976 | 1494522912 | Python | Python3 | py | Runtime Error | 0 | 0 | 818 | # -*- coding: utf-8 -*-
import sys
import os
import math
import numpy as np
# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/
def length(v):
return math.sqrt(v[0] ** 2 + v[1] ** 2 + v[2] ** 2)
def dist(p0, p1):
return math.sqrt( (p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2 + (p0[2] - p1[2]) ** 2)
# me
p0 = np.array(list(map(int, input().split())))
# enemy
p1 = np.array(list(map(int, input().split())))
# barrier
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))
a = p1 - p0
b = A - B
c = A - C
d = A - p0
M = np.array([a, b, c]).T
tuv = np.linalg.solve(M, d)
t = tuv[0]
u = tuv[1]
v = tuv[2]
if 0 <= u <= 1 and 0 <= v <= 1 and 0 <= u + v <= 1:
print('MISS')
else:
print('HIT') |
s172363378 | p00115 | u462831976 | 1494525513 | Python | Python3 | py | Runtime Error | 20 | 7856 | 1045 | # -*- coding: utf-8 -*-
import sys
import os
import math
# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/
def det(a, b, c):
return + a[0] * b[1] * c[2] \
+ a[2] * b[0] * c[1] \
+ a[1] * b[2] * c[0] \
- a[2] * b[1] * c[0] \
- a[1] * b[0] * c[2] \
- a[0] * b[2] * c[1]
def sub(v0, v1):
# v0 - v1
return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])
# me
p0 = list(map(int, input().split()))
# enemy
p1 = list(map(int, input().split()))
# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)
denom = det(a, b, c)
if denom > -0.0000001:
t = det(d, b, c) / denom
u = det(a, d, c) / denom
v = det(a, b, d) / denom
lower = -0.0000001
upper = 1.0000001
if lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
print('MISS')
else:
print('HIT')
else:
print('HIT') |
s195147798 | p00115 | u462831976 | 1494525664 | Python | Python3 | py | Runtime Error | 20 | 7848 | 1033 | # -*- coding: utf-8 -*-
import sys
import os
import math
# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/
def det(a, b, c):
return + a[0] * b[1] * c[2] \
+ a[2] * b[0] * c[1] \
+ a[1] * b[2] * c[0] \
- a[2] * b[1] * c[0] \
- a[1] * b[0] * c[2] \
- a[0] * b[2] * c[1]
def sub(v0, v1):
# v0 - v1
return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])
# me
p0 = list(map(int, input().split()))
# enemy
p1 = list(map(int, input().split()))
# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)
denom = det(a, b, c)
lower = -0.0000001
upper = 1.0000001
if denom > lower:
t = det(d, b, c) / denom
u = det(a, d, c) / denom
v = det(a, b, d) / denom
if lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
print('MISS')
else:
print('HIT')
else:
print('HIT') |
s822302832 | p00115 | u462831976 | 1494530936 | Python | Python3 | py | Runtime Error | 20 | 7872 | 1224 | # -*- coding: utf-8 -*-
import sys
import os
import math
# refs
# https://shikousakugo.wordpress.com/2012/06/27/ray-intersection-2/
def det(a, b, c):
return + a[0] * b[1] * c[2] \
+ a[2] * b[0] * c[1] \
+ a[1] * b[2] * c[0] \
- a[2] * b[1] * c[0] \
- a[1] * b[0] * c[2] \
- a[0] * b[2] * c[1]
def sub(v0, v1):
# v0 - v1
return (v0[0] - v1[0], v0[1] - v1[1], v0[2] - v1[2])
# me
p0 = list(map(int, input().split()))
# enemy
p1 = list(map(int, input().split()))
# barrier
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
a = sub(p1, p0)
b = sub(A, B)
c = sub(A, C)
d = sub(A, p0)
EPS = 0.0000001
lower = -EPS
upper = 1 + EPS
denom = det(a, b, c)
if denom > lower:
t = det(d, b, c) / denom
u = det(a, d, c) / denom
v = det(a, b, d) / denom
# i am on barrier
if -EPS < t < EPS:
print('HIT')
# barrier is not between ours
elif t < 0:
print('HIT')
# hit barrier
elif lower < t < upper and lower <= u <= upper and lower <= v <= upper and lower <= u + v <= upper:
print('MISS')
else:
print('HIT')
else:
print('HIT') |
s893059137 | p00115 | u566872786 | 1511090200 | Python | Python3 | py | Runtime Error | 0 | 0 | 798 | dot = lambda a,b:sum([a[i]*b[i] for i in range(3)])
cross = lambda a,b:[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
m = lambda a,b:[a[i]-b[i] for i in range(3)]
l = lambda a:(a[0]**2+a[1]**2+a[2]**2)** 0.5
c = lambda a,b:[a*b[i] for i in range(3)]
def A():
L=[list(map(int,input().split())) for i in range(5)]
ab = m(L[1],L[0])
L2 = [m(L[3],L[2]),m(L[4],L[3]),m(L[2],L[4])]
n = cross(L2[0],L2[1])
if dot(ab,n) == 0:
return 'HIT'
xa = m(L[0],L[2])
xb = m(L[1],L[2])
if dot(n,xa) * dot(n,xb) > 0:
return 'HIT'
da = abs(dot(n,xa))/l(n)
db = abs(dot(n,xb))/l(n)
a = da / (da + db)
X = [c((1-a),xa)[i] + c(a,xb)[i] for i in range(3)]
for i in range(1,4):
if dot(n,cross(L2[i-1],m(X,L2[2+(i%3)]))) < 0:
return 'MISS'
return "HIT"
print(A()) |
s944689187 | p00115 | u300645821 | 1401883826 | Python | Python3 | py | Runtime Error | 70 | 14776 | 939 | #!/usr/bin/python
from fractions import Fraction
import sys
if sys.version_info[0]>=3: raw_input=input
def gauss(a):
if not a or len(a)==0: return None
n=len(a)
for i in range(n):
if a[i][i]==0:
for j in range(i+1,n):
if a[j][i]!=0:
for k in range(i,n+1): a[i][k]+=a[j][k]
break
for j in range(n):
if i!=j:
r = Fraction(a[j][i],a[i][i])
for k in range(i,n+1): a[j][k] = a[j][k] - a[i][k]*r
for i in range(n):
x=Fraction(a[i][i],1)
for j in range(len(a[i])):
a[i][j] /= x
return a
uaz=list(map(int,raw_input().split()))
enemy=[0]+[-x+y for x,y in zip(map(int,raw_input().split()),uaz)]
b0=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)]
b1=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)]
b2=[1]+[x-y for x,y in zip(map(int,raw_input().split()),uaz)]
sol=gauss(list(map(list,zip(b0,b1,b2,enemy,[1,0,0,0]))))
print('MISS' if sol and all(0<=e[-1]<=1 for e in sol) else 'HIT') |
s972625382 | p00116 | u912237403 | 1414939377 | Python | Python | py | Runtime Error | 0 | 0 | 410 | while 1:
h,w = map(int, raw_input().split())
if h==w==0: break
A = []
for i in range(h):
A.append(map(int,list(raw_input().replace(".", "1").replace("*", "0"))))
B = A[:]
C = []
for j in range(1,h):
m=[]
for i in range(j,h):
x=[e1&e2 for e1,e2 in zip(B[i-j],A[i])]
B[i-j]=x
m.append(max("".join(map(str,x)).split("0")))
C.append(len(max(m))*(j+1))
print max(C) |
s499357334 | p00116 | u912237403 | 1414939661 | Python | Python | py | Runtime Error | 0 | 0 | 420 | while 1:
h,w = map(int, raw_input().split())
if h==w==0: break
A = []
for i in range(h):
A.append(map(int, list(raw_input().replace(".", "1").replace("*", "0"))))
B = A[:]
C = []
for j in range(1,h):
m=[]
for i in range(j,h):
x = [e1 & e2 for e1, e2 in zip(B[i-j], A[i])]
B[i-j] = x
m.append(max("".join(map(str, x)).split("0")))
C.append(len(max(m))*(j+1))
print max(C) |
s649028099 | p00116 | u912237403 | 1414941454 | Python | Python | py | Runtime Error | 0 | 0 | 428 | import sys
while 1:
h,w = map(int, raw_input().split())
if h==w==0: break
A = []
for _ in [0]*h:
A.append(map(int, list(raw_input().replace(".", "1").replace("*", "0"))))
B = A[:]
C = []
for j in range(1,h):
m=[]
for i in range(j,h):
x = [e1 & e2 for e1, e2 in zip(B[i-j], A[i])]
B[i-j] = x
m.append(max("".join(map(str, x)).split("0")))
C.append(len(max(m))*(j+1))
print max(C) |
s744981245 | p00116 | u912237403 | 1414966687 | Python | Python | py | Runtime Error | 0 | 0 | 446 | while 1:
h,w = map(int, raw_input().split())
if h==w==0: break
A = [0]*h
for i in range(h):
x = raw_input().replace(".", "1").replace("*", "0")
A[i] = map(int, list(x))
B = A[:]
C = []
for j in range(1,h):
M = []
for i in range(j,h):
x = [e1 & e2 for e1, e2 in zip(B[i-j], A[i])]
B[i-j] = x
M.append(sorted("".join(map(str, x)).split("0"))[-1])
C.append(len(sorted(M)[-1])*(j+1))
print max(C) |
s639828553 | p00116 | u912237403 | 1415008479 | Python | Python | py | Runtime Error | 0 | 0 | 592 | def f(j,k):
tmp=j-C[k]
if tmp>M[k]: M[k]
return
while 1:
h,w = map(int, raw_input().split())
if h==w==0: break
M = [0]*(h+1)
a=[0]*w
for i in range(h):
x = raw_input()
b=[0]*w
sp=-1
C = [-1]*(h+1)
for j in range(w):
if x[j]=="*": c=0
else: c=a[j]+1
b[j]=c
dw=c-sp
if dw>0: C[sp+1:c+1]=[j]*dw
elif dw<0:
for k in range(c+1,sp+1): f(j,k)
C[c+1:sp+1]=[-1]*(-dw)
sp=c
for k in range(1,sp+1):
if C[k]>=0: M[k]=max(M[k],w-C[k])
a=b
s=max([M[i]*i for i in range(h+1) if M[i]>0])
print s |
s184242834 | p00116 | u912237403 | 1415008537 | Python | Python | py | Runtime Error | 0 | 0 | 596 | def f(j,k):
tmp=j-C[k]
if tmp>M[k]: M[k]=tmp
return
while 1:
h,w = map(int, raw_input().split())
if h==w==0: break
M = [0]*(h+1)
a=[0]*w
for i in range(h):
x = raw_input()
b=[0]*w
sp=-1
C = [-1]*(h+1)
for j in range(w):
if x[j]=="*": c=0
else: c=a[j]+1
b[j]=c
dw=c-sp
if dw>0: C[sp+1:c+1]=[j]*dw
elif dw<0:
for k in range(c+1,sp+1): f(j,k)
C[c+1:sp+1]=[-1]*(-dw)
sp=c
for k in range(1,sp+1):
if C[k]>=0: M[k]=max(M[k],w-C[k])
a=b
s=max([M[i]*i for i in range(h+1) if M[i]>0])
print s |
s365961694 | p00116 | u647766105 | 1381483573 | Python | Python | py | Runtime Error | 0 | 0 | 2559 | class Rect():
def __init__(self, x_range, y_range):
self.x_range = x_range
self.y_range = y_range
@property
def w(self):
return len(self.x_range)
@property
def h(self):
return len(self.y_range)
def __str__(self):
return "Rect({},{})".format(str(self.x_range),str(self.y_range))
def __contains__(self, pos):
x,y = pos
left,right = self.x_range[0],self.x_range[-1]
buttom,top = self.y_range[0],self.y_range[-1]
return left<=x<=right and buttom<=y<=top
def divide(self, pos):
x,y = pos
x_i = self.x_range.index(x)
y_i = self.y_range.index(y)
rects = [Rect(self.x_range[:x_i],self.y_range),
Rect(self.x_range[x_i+1:],self.y_range),
Rect(self.x_range,self.y_range[:y_i]),
Rect(self.x_range,self.y_range[y_i+1:])]
rem_list = [] #TEMP
for r in rects:
if r.x_range == [] or r.y_range == []:
rem_list.append(r)
for r in rem_list:
rects.remove(r)
return rects
def ge(H,W):
from collections import deque
q = deque([(0,0)])
while q:
x,y = q.popleft()
yield (x,y)
if y == 0 and x+1 < W:
q.append([x+1,y])
if y+1 < H:
q.append([x,y+1])
def solveA(field,H,W):
space = [[0]*(W+1) for _ in xrange(H)]
for x in xrange(W-1,-1,-1):
for y in xrange(H):
if field[y][x]==".":
space[y][x] = space[y][x+1]+1
ans = 0
x,y = 0,0
for x,y in ((xx,yy) for xx,yy in ge(H,W) if field[yy][xx] == "."):
mi = space[y][x]
for h in xrange(y,H):
if(field[h][x] == "*"):
break
mi = min(mi, space[h][x])
ans = max(ans, mi*(h-y+1))
if (W-x+1)*(H-y+1) < ans:
return ans
return ans
def solveB(field,H,W):
rects = [Rect(range(W),range(H))]
for x in xrange(W):
for y in (yy for yy in xrange(H) if field[yy][x] == "*"):
for r in filter(lambda rr:(x,y) in rr, rects):
rects.extend(r.divide((x,y)))
rects.remove(r)
return max(r.w*r.h for r in rects)
while True:
H,W = map(int, raw_input().split())
if (H,W) == (0,0):
break
field = [raw_input() for _ in xrange(H)]
count = sum(f.count("*") for f in field)
if count > 15:
print solveA(field,H,W)
else:
print solveB(field,H,W) |
s398839556 | p00116 | u104911888 | 1390903526 | Python | Python | py | Runtime Error | 0 | 0 | 794 | def get_rectangle_area(table, w):
maxv = 0
stack = []
table.append(0)
for i, rect in enumerate(table):
if stack == []:
stack.append((rect, i))
elif stack[-1][0] < rect:
stack.append((rect, i))
elif stack[-1][0] == rect:
pass
elif stack[-1][0] > rect:
while stack != [] and stack[-1][0] >= rect:
high, pos = stack.pop()
maxv = max(maxv, high*(i-pos))
stack.append((rect, pos))
return maxv
while True:
h, w = map(int, raw_input().split())
if h == w == 0:
break
mass = [raw_input() for i in range(h)]
table = histgram(mass, h, w)
ans = 0
for tab in table:
ans = max(ans, get_rectangle_area(tab, w))
print ans |
s844438818 | p00116 | u300645821 | 1392386118 | Python | Python | py | Runtime Error | 0 | 0 | 541 | #!/usr/bin/python
#http://www.checkio.org/mission/spaceship-landing-strip/ verifier.
def checkio(data):
y=len(data)
x=len(data[0])
m=[[0]*x for i in range(y)]
for j in range(y):
r=0
for i in range(x):
if data[j][i]=='.': r+=1
else: r=0
m[j][i]=r
r=0
for i in range(x):
for j in range(y):
M=9999999
for k in range(j,y):
M=min(M,m[k][i])
r=max(r,M*(k-j+1))
return r
while True:
x,y=[int(e) for e in raw_input().split()]
if y==0: break
data=[raw_input().rstrip() for i in range(y)]
print(checkio(data)) |
s731962099 | p00116 | u300645821 | 1392386234 | Python | Python | py | Runtime Error | 0 | 0 | 607 | #!/usr/bin/python
#http://www.checkio.org/mission/spaceship-landing-strip/ verifier.
def checkio(data):
y=len(data)
x=len(data[0])
m=[[0]*x for i in range(y)]
for j in range(y):
r=0
for i in range(x):
if data[j][i]=='.': r+=1
else: r=0
m[j][i]=r
r=0
for i in range(x):
for j in range(y):
M=9999999
for k in range(j,y):
M=min(M,m[k][i])
r=max(r,M*(k-j+1))
return r
if __name__=='__main__':
try:
while True:
x,y=[int(e) for e in raw_input().split()]
if y==0: break
data=[raw_input().rstrip() for i in range(y)]
print(checkio(data))
except EOFError:
pass |
s580455807 | p00117 | u844945939 | 1420528442 | Python | Python3 | py | Runtime Error | 0 | 0 | 712 | http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0117
INF = 1e12
def dijkstra(graph, source):
lg = len(graph)
unused = list(range(lg))
d = [INF] * (lg)
d[source] = 0
while unused:
v = min(unused, key=lambda u: d[u])
unused.remove(v)
for u in range(n + 1):
d[u] = min(d[u], d[v] + graph[v][u])
return d
n = int(input())
m = int(input())
cost = [[INF] * (n + 1) for i in range(n + 1)]
for i in range(m):
ai, bi, ci, di = map(int, input().split(','))
cost[ai][bi] = ci
cost[bi][ai] = di
x1, x2, y1, y2 = map(int, input().split(','))
d_go = dijkstra(cost, x1)[x2]
d_back = dijkstra(cost, x2)[x1]
print(y1 - y2 - d_go - d_back) |
s799111889 | p00117 | u873482706 | 1435475730 | Python | Python | py | Runtime Error | 0 | 0 | 1234 | import copy
def discomfort(dic, n):
global expenses
if expenses != None and sum(p_res) >= expenses:
return
if n == s_n and g_n in load:
expenses = sum(p_res)
Pirates.append(r-(sum(p_res)+p))
return
for v in dic[n]:
p_res.append(p_dic[(n,v)])
c_l_dic = copy.deepcopy(dic)
c_l_dic[n].remove(v)
c_l_dic[v].remove(n)
load.append(v)
discomfort(c_l_dic, v)
del p_res[-1]
del load[-1]
if __name__ == '__main__':
l_dic = {}
p_dic = {}
for line in open('s.txt').readlines():
n1, n2, p1, p2 = map(int, line.rstrip().split(','))
if not n1 in l_dic:
l_dic[n1] = [n2]
if not n2 in l_dic:
l_dic[n2] = [n1]
else:
l_dic[n2].append(n1)
else:
l_dic[n1].append(n2)
if not n2 in l_dic:
l_dic[n2] = [n1]
else:
l_dic[n2].append(n1)
p_dic[(n1,n2)] = p1
p_dic[(n2,n1)] = p2
s_n, g_n, r, p = map(int, raw_input().split(','))
p_res = []
load = [2]
expenses = None
Pirates = []
discomfort(l_dic, s_n)
print sorted(Pirates)[-1] |
s344389669 | p00117 | u542962065 | 1511273971 | Python | Python3 | py | Runtime Error | 0 | 0 | 554 | import numpy as np
n = int(input())
m = int(input())
road = np.full((n, n), np.inf)
for i in range(m):
r_in = list(map(int, input().split(",")))
road[r_in[0]-1, r_in[1]-1] = r_in[2]
road[r_in[1]-1, r_in[0]-1] = r_in[3]
s, g, v, p = map(int, input().split(","))
for k in range(n):
for i in range(n):
for j in range(n):
if i == j:
road[i, j] = 0
else:
road[i, j] = min(road[i, j], road[i, k] + road[k, j])
reward = int(v - road[s-1, g-1] - road[g-1, s-1] - p)
print(reward) |
s711452755 | p00117 | u542962065 | 1511273979 | Python | Python | py | Runtime Error | 0 | 0 | 554 | import numpy as np
n = int(input())
m = int(input())
road = np.full((n, n), np.inf)
for i in range(m):
r_in = list(map(int, input().split(",")))
road[r_in[0]-1, r_in[1]-1] = r_in[2]
road[r_in[1]-1, r_in[0]-1] = r_in[3]
s, g, v, p = map(int, input().split(","))
for k in range(n):
for i in range(n):
for j in range(n):
if i == j:
road[i, j] = 0
else:
road[i, j] = min(road[i, j], road[i, k] + road[k, j])
reward = int(v - road[s-1, g-1] - road[g-1, s-1] - p)
print(reward) |
s347709244 | p00117 | u658913995 | 1512630085 | Python | Python | py | Runtime Error | 0 | 0 | 772 | # The question itself is not diffifult, but the website only
# tested my code with two cases, so I am not sure whether the
# "accepted" is trustworthy.
# Note: math.inf > math.inf -> False
import math
V = int(input())
E = int(input())
fees = [[math.inf] * V for i in range(V)]
for i in range(V):
fees[i][i] = 0
for i in range(E):
a, b, c, d = map(int, input().split(','))
fees[a-1][b-1] = c
fees[b-1][a-1] = d
start, end, funding, cost = map(int, input().split(','))
for i in range(V):
for j in range(V):
for k in range(V):
if (fees[j][k] > fees[j][i] + fees[i][k]):
fees[j][k] = fees[j][i] + fees[i][k]
if (fees[start-1][end-1]==math.inf or fees[end-1][start-1]==math.inf):
print(0)
else:
print(funding-cost-fees[start-1][end-1]-fees[end-1][start-1]) |
s737683851 | p00118 | u633068244 | 1414860442 | Python | Python | py | Runtime Error | 0 | 0 | 455 | def solve(c,h,w,count):
if 0 <= h < H and 0 <= w < W:
if c in "#@*" and c == A[h][w]:
A[h][w] = count
solve(c,h+1,w,count)
solve(c,h-1,w,count)
solve(c,h,w+1,count)
solve(c,h,w-1,count)
while 1:
H,W = map(int,raw_input().split())
if H == W == 0:
break
A = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if str(A[h][w]) in "#@*":
solve(A[h][w],h ,w,count)
count += 1
print count |
s762746192 | p00118 | u633068244 | 1414860765 | Python | Python | py | Runtime Error | 0 | 0 | 456 | def solve(c,h,w,count):
if 0 <= h < H and 0 <= w < W:
if c in "#@*" and c == A[h][w]:
A[h][w] = count
solve(c,h+1,w,count)
solve(c,h-1,w,count)
solve(c,h,w+1,count)
solve(c,h,w-1,count)
while 1:
H,W = map(int,raw_input().split())
if H == W == 0:
break
A = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if str(A[h][w]) in "#@*":
solve(A[h][w],h ,w,count)
count += 1
print count |
s052077037 | p00118 | u633068244 | 1414915602 | Python | Python | py | Runtime Error | 0 | 0 | 467 | def solve(c,h,w,count):
if 0 <= h < H and 0 <= w < W:
if type(c) is not int and c == A[h][w]:
A[h][w] = count
solve(c,h+1,w,count)
solve(c,h-1,w,count)
solve(c,h,w+1,count)
solve(c,h,w-1,count)
while 1:
H,W = map(int,raw_input().split())
if H == W == 0:
break
A = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if type(A[h][w]) is not int:
solve(A[h][w],h ,w,count)
count += 1
print count |
s312140255 | p00118 | u633068244 | 1414920132 | Python | Python | py | Runtime Error | 0 | 0 | 447 | def solve(c,h,w,count):
if 0 <= h < H and 0 <= w < W:
if type(A[h][w]) is not int and c == A[h][w]:
A[h][w] = count
for dh,dw in [[1,0],[-1,0],[0,1],[0,-1]]:
solve(c,h+dh,w+dw,count)
while 1:
H,W = map(int,raw_input().split())
if H == W == 0:break
A = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if type(A[h][w]) is not int:
solve(A[h][w],h ,w,count)
count += 1
print count |
s764833390 | p00118 | u633068244 | 1414921929 | Python | Python | py | Runtime Error | 0 | 0 | 350 | def solve(c,h,w):
if A[h][w] == c:
A[h][w] = "X"
for dx,dy in zip((1,-1,0,0),(0,0,1,-1)):
if 0 <= h+dh < H and 0 <= w+dw < W:
solve(c,h+dh,w+dw)
while 1:
H,W = map(int,raw_input().split())
if H == W == 0: break
count = 0
for h in range(H):
for w in range(W):
if A[h][w] != "X":
solve(A[h][w],h,w)
count += 1
print count |
s641889171 | p00118 | u912237403 | 1415028743 | Python | Python | py | Runtime Error | 0 | 0 | 467 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[]
for i in range(H+2):
if i==0 or i==H+1:
A.append(list(" "*(W+2)))
else:
A.append(list(" "+raw_input()+" "))
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s945980272 | p00118 | u912237403 | 1415029593 | Python | Python | py | Runtime Error | 0 | 0 | 566 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[[[] for _ in range(W+2)] for _ in range(H+2)]
for i in range(H+2):
if i==0 or i==H+1:
for j in range(W+2): A[i][j]=" "
else:
s=" "+raw_input()+" "
for j in range(W+2): A[i][j]=s[j]
for e in A: print e
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s959930845 | p00118 | u912237403 | 1415029697 | Python | Python | py | Runtime Error | 0 | 0 | 574 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[[[] for _ in range(W+2)] for _ in range(H+2)]
for i in range(H+2):
if i==0 or i==H+1:
for j in range(W+2): A[i][j]=" "
else:
s=" "+raw_input().strip()+" "
for j in range(W+2): A[i][j]=s[j]
for e in A: print e
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s984888231 | p00118 | u912237403 | 1415029762 | Python | Python | py | Runtime Error | 0 | 0 | 560 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[[[] for _ in range(W+2)] for _ in range(H+2)]
for i in range(H+2):
if i==0 or i==H+1:
for j in range(W+2): A[i][j]=" "
else:
s=raw_input()
for j in range(1,W+1): A[i][j]=s[j]
for e in A: print e
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s773201372 | p00118 | u912237403 | 1415029813 | Python | Python | py | Runtime Error | 0 | 0 | 569 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[[[] for _ in range(W+2)] for _ in range(H+2)]
for i in range(H+2):
if i==0 or i==H+1:
for j in range(W+2): A[i][j]=" "
else:
s=raw_input().rstrip()
for j in range(1,W+1): A[i][j]=s[j]
for e in A: print e
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s172313361 | p00118 | u912237403 | 1415030147 | Python | Python | py | Runtime Error | 0 | 0 | 544 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[[[] for _ in range(W+2)] for _ in range(H+2)]
for i in range(H+2):
if i==0 or i==H+1:
for j in range(W+2): A[i][j]=" "
else:
s=" "+raw_input()+" "
for j in range(W+2): A[i][j]=s[j]
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s032894455 | p00118 | u912237403 | 1415030214 | Python | Python | py | Runtime Error | 0 | 0 | 537 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[[" " for _ in range(W+2)] for _ in range(H+2)]
for i in range(H+2):
if i==0 or i==H+1:
for j in range(W+2): A[i][j]=" "
else:
s=raw_input()
for j in range(W): A[i][j+1]=s[j]
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s285175966 | p00118 | u912237403 | 1415030401 | Python | Python | py | Runtime Error | 0 | 0 | 461 | def f(y,x,c0):
global A
c=A[y][x]
if c==" " or c!=c0:
return 0
else:
A[y][x]=" "
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[[" " for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
s=raw_input()
for j in range(W): A[i+1][j+1]=s[j]
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s307495629 | p00118 | u912237403 | 1415186687 | Python | Python | py | Runtime Error | 0 | 0 | 461 | def f(y,x,c0):
global A
c=A[y][x]
if c=="X" or c!=c0:
return 0
else:
A[y][x]="X"
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[["X" for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
s=raw_input()
for j in range(W): A[i+1][j+1]=s[j]
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s286869468 | p00118 | u912237403 | 1415186727 | Python | Python | py | Runtime Error | 0 | 0 | 479 | def f(y,x,c0):
global A
c=A[y][x]
if c=="X" or c!=c0:
return 0
else:
A[y][x]="X"
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[["X" for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
s=raw_input()
for j in range(W): A[i+1][j+1]=s[j]
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=A[i][j]
# c+=f(i,j,A[i][j])
print c |
s345176250 | p00118 | u912237403 | 1415187694 | Python | Python | py | Runtime Error | 0 | 0 | 509 | def f(y,x,c0):
global A
c=A[y][x]
if x==0 or x==W+1 or y==0 or y==H+1: return 0
if c=="X" or c!=c0:
return 0
else:
A[y][x]="X"
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[["X" for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
s=raw_input()
for j in range(W): A[i+1][j+1]=s[j]
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s865444531 | p00118 | u912237403 | 1415187764 | Python | Python | py | Runtime Error | 0 | 0 | 436 | if c=="X" or c!=c0:
return 0
else:
return 0
A[y][x]="X"
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[["X" for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
s=raw_input()
for j in range(W): A[i+1][j+1]=s[j]
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s658193095 | p00118 | u912237403 | 1415188300 | Python | Python | py | Runtime Error | 0 | 0 | 439 | def f(y,x,c0):
global A
c=A[y][x]
if c=='X' or c!=c0:
return 0
else:
A[y][x]='X'
for i,j in [[0,-1],[0,1],[-1,0],[1,0]]:
f(y+i,x+j,c0)
return 1
while 1:
H,W=map(int,raw_input().split())
if H==W==0: break
A=[['X' for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
A[i+1][1:W+1]=list(raw_input())
c=0
for i in range(1,H+1):
for j in range(1,W+1):
c+=f(i,j,A[i][j])
print c |
s533177826 | p00118 | u633068244 | 1417490356 | Python | Python | py | Runtime Error | 0 | 0 | 493 | def solve(h,w,count,c):
if 0 <= h < H and 0 <= w < W and A[h][w] == c:
A[h][w] = count
for dh,dw in zip([1,0,-1,0],[0,1,0,-1]):
solve(h+dh,w+dw,count,c)
while 1:
H,W = map(int,raw_input().split())
if H == W == 0: break
A = [list(raw_input()) for _ in range(H)]
count = 0
for h in range(H):
for w in range(W):
if type(A[h][w]) is not int:
solve(h,w,count,A[h][w])
count += 1
print count |
s300217311 | p00118 | u507118101 | 1418524437 | Python | Python | py | Runtime Error | 0 | 0 | 686 | def dfs(x,y,ch):
field[x][y] = '.'
for i in range(4):
nx = x+moveY[i]
ny = y+moveX[i]
if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
dfs(nx,ny,field[nx][ny])
if __name__ == '__main__':
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
H,W = map(int,raw_input().split(' '))
field = ['' for i in range(H)]
h = 0
while True:
s = raw_input()
if s == '0 0':
break
field[h] = list(s)
h += 1
correct =0
for i in range(H):
for j in range(W):
if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
dfs(i,j,field[i][j])
correct += 1
print correct |
s573123200 | p00118 | u507118101 | 1418524528 | Python | Python | py | Runtime Error | 0 | 0 | 686 | def dfs(x,y,ch):
field[x][y] = '.'
for i in range(4):
nx = x+moveY[i]
ny = y+moveX[i]
if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
dfs(nx,ny,field[nx][ny])
if __name__ == '__main__':
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
H,W = map(int,raw_input().split(' '))
field = ['' for i in range(H)]
h = 0
while True:
s = raw_input()
if s == '0 0':
break
field[h] = list(s)
h += 1
correct =0
for i in range(H):
for j in range(W):
if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
dfs(i,j,field[i][j])
correct += 1
print correct |
s689092585 | p00118 | u507118101 | 1418525266 | Python | Python | py | Runtime Error | 0 | 0 | 686 | def dfs(x,y,ch):
field[x][y] = '.'
for i in range(4):
nx = x+moveY[i]
ny = y+moveX[i]
if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
dfs(nx,ny,field[nx][ny])
if __name__ == '__main__':
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
H,W = map(int,raw_input().split(' '))
field = ['' for i in range(H)]
h = 0
while True:
s = raw_input()
if s == '0 0':
break
field[h] = list(s)
h += 1
correct =0
for i in range(H):
for j in range(W):
if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
dfs(i,j,field[i][j])
correct += 1
print correct |
s675314079 | p00118 | u507118101 | 1418525615 | Python | Python | py | Runtime Error | 0 | 0 | 641 | def dfs(x,y,ch):
field[x][y] = '.'
for i in range(4):
nx = x+moveY[i]
ny = y+moveX[i]
if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
dfs(nx,ny,field[nx][ny])
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
H,W = map(int,raw_input().split(' '))
field = ['' for i in range(H)]
h = 0
while True:
s = raw_input()
if s == '0 0':
break
field[h] = list(s)
h += 1
correct =0
for i in range(H):
for j in range(W):
if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
dfs(i,j,field[i][j])
correct += 1
print correct |
s622052543 | p00118 | u507118101 | 1418527795 | Python | Python | py | Runtime Error | 0 | 0 | 746 | def dfs(X,Y,ch):
stack.append([X,Y])
field[X][Y] = '.'
while len(stack) != 0:
x,y = stack.pop()
for i in range(4):
nx = x+moveY[i]
ny = y+moveX[i]
if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
field[nx][ny] = '.'
stack.append([nx,ny])
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
H,W = map(int,raw_input().split(' '))
field = ['' for i in range(H)]
h = 0
while True:
s = raw_input()
if s == '0 0':
break
field[h] = list(s)
h += 1
correct =0
for i in range(H):
for j in range(W):
if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
dfs(i,j,field[i][j])
correct += 1
print correct |
s548863796 | p00118 | u507118101 | 1418528360 | Python | Python | py | Runtime Error | 0 | 0 | 802 | def dfs(X,Y,ch):
stack.append([X,Y])
print stack
field[X][Y] = '.'
while len(stack) != 0:
x,y = stack.pop()
for i in range(4):
nx = x+moveY[i]
ny = y+moveX[i]
if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
field[nx][ny] = '.'
stack.append([nx,ny])
print stack
stack = []
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
H,W = map(int,raw_input().split(' '))
if H == 0 and W == 0:
break
field = ['' for i in range(H)]
h = 0
while True:
field[h] = list(raw_input())
h += 1
correct =0
for i in range(H):
for j in range(W):
if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
dfs(i,j,field[i][j])
correct += 1
print correct |
s835013502 | p00118 | u507118101 | 1418529080 | Python | Python | py | Runtime Error | 0 | 0 | 629 | def dfs(X,Y,ch):
field[X][Y] = '.'
for i in range(4):
nx = X+moveY[i]
ny = Y+moveX[i]
if (nx >= 0 and ny >= 0) and(nx < H and ny < W) and field[nx][ny] == ch:
if field[nx][ny] == '#' or field[nx][ny] == '*'or field[nx][ny] == '@':
dfs(nx,ny,field[nx][ny])
moveY = [-1,0,1,0]
moveX = [0,1,0,-1]
while True:
H,W = map(int,raw_input().split(' '))
if H == 0 and W == 0:
break
field = [list(raw_input()) for i in range(H)]
print field
correct =0
for i in range(H):
for j in range(W):
if field[i][j] == '@' or field[i][j] == '#'or field[i][j] == '*':
dfs(i,j,field[i][j])
correct += 1
print correct |
s865913861 | p00118 | u873482706 | 1435549513 | Python | Python | py | Runtime Error | 0 | 0 | 779 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
#right
wa(h, w+1, f)
#up
wa(h-1, w, f)
#left
wa(h, w-1, f)
#down
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s001468684 | p00118 | u873482706 | 1435549707 | Python | Python | py | Runtime Error | 0 | 0 | 724 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s991289936 | p00118 | u873482706 | 1435549778 | Python | Python | py | Runtime Error | 0 | 0 | 735 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s507746799 | p00118 | u873482706 | 1435550004 | Python | Python | py | Runtime Error | 0 | 0 | 762 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
mapp = []
for i in range(H):
mapp.append(list(raw_input()))
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s921184437 | p00118 | u873482706 | 1435550878 | Python | Python | py | Runtime Error | 0 | 0 | 746 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
mapp = [list(raw_input()[i*W:i*W+W]) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s812869007 | p00118 | u873482706 | 1435551023 | Python | Python | py | Runtime Error | 0 | 0 | 803 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
line = raw_input()
mapp = [list(line[i*W:i*W+W]) for i in range(H)]
for line in mapp:
print line
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s083351160 | p00118 | u873482706 | 1435551211 | Python | Python | py | Runtime Error | 0 | 0 | 770 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
line = raw_input()
mapp = [list(line[i*W:i*W+W]) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s052637293 | p00118 | u873482706 | 1435551645 | Python | Python | py | Runtime Error | 0 | 0 | 735 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
wa(h, w, '@')
elif mapp[h][w] == '#':
wa(h, w, '#')
elif mapp[h][w] == '*':
wa(h, w, '*')
else:
continue
count += 1
else:
print count |
s231867700 | p00118 | u873482706 | 1435552218 | Python | Python | py | Runtime Error | 0 | 0 | 750 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
count += 1
wa(h, w, '@')
elif mapp[h][w] == '#':
count += 1
wa(h, w, '#')
elif mapp[h][w] == '*':
count += 1
wa(h, w, '*')
else:
print count |
s565115978 | p00118 | u873482706 | 1435553559 | Python | Python | py | Runtime Error | 0 | 0 | 750 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split(' '))
if H == 0 and W == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
count += 1
wa(h, w, '@')
elif mapp[h][w] == '#':
count += 1
wa(h, w, '#')
elif mapp[h][w] == '*':
count += 1
wa(h, w, '*')
else:
print count |
s698947183 | p00118 | u873482706 | 1435553811 | Python | Python | py | Runtime Error | 0 | 0 | 747 | def wa(h, w, f):
if not (0 <= h <= H-1 and 0 <= w <= W-1):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
count += 1
wa(h, w, '@')
elif mapp[h][w] == '#':
count += 1
wa(h, w, '#')
elif mapp[h][w] == '*':
count += 1
wa(h, w, '*')
else:
print count |
s880935667 | p00118 | u873482706 | 1435553921 | Python | Python | py | Runtime Error | 0 | 0 | 741 | def wa(h, w, f):
if not (0 <= h < H and 0 <= w < W):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
count += 1
wa(h, w, '@')
elif mapp[h][w] == '#':
count += 1
wa(h, w, '#')
elif mapp[h][w] == '*':
count += 1
wa(h, w, '*')
else:
print count |
s424472831 | p00118 | u873482706 | 1435554042 | Python | Python | py | Runtime Error | 0 | 0 | 741 | def wa(h, w, f):
if not (0 <= h < H and 0 <= w < W):
return
elif mapp[h][w] != f:
return
else:
mapp[h][w] = '$'
wa(h, w+1, f)
wa(h-1, w, f)
wa(h, w-1, f)
wa(h+1, w, f)
while True:
W, H = map(int, raw_input().split())
if H == 0 and W == 0: break
mapp = [list(raw_input()) for i in range(H)]
count = 0
for h in range(H):
for w in range(W):
if mapp[h][w] == '@':
count += 1
wa(h, w, '@')
elif mapp[h][w] == '#':
count += 1
wa(h, w, '#')
elif mapp[h][w] == '*':
count += 1
wa(h, w, '*')
else:
print count |
s207314498 | p00118 | u736039489 | 1436312494 | Python | Python | py | Runtime Error | 0 | 0 | 882 | #! -*- coding:utf-8 -*-
while True:
H, W = map(int, raw_input().split(' '))
if H==0 and W==0:
break
#print H, W
data = []
for i in range(H):
data.append(list(raw_input()))
flg = [[0 for j in range(W)] for i in range(H)]
def search(i,j,mark):
# if i<0 or i>=H or j<0 or j>=W:
# break
if i+1 < H and flg[i+1][j] == 0 and data[i+1][j] == mark:
flg[i+1][j] = 1
search(i+1,j,mark)
if i-1 >= 0 and flg[i-1][j] == 0 and data[i-1][j] == mark:
flg[i-1][j] = 1
search(i-1,j,mark)
if j+1 < W and flg[i][j+1] == 0 and data[i][j+1] == mark :
flg[i][j+1] = 1
search(i,j+1,mark)
if j-1 >= 0 and flg[i][j-1] == 0 and data[i][j-1] == mark :
flg[i][j-1] = 1
search(i,j-1,mark)
count = 0
for i in range(H):
for j in range(W):
if flg[i][j] != 0:
continue
search(i,j,data[i][j])
count += 1
print count
# print data
# print flg |
s035595382 | p00118 | u736039489 | 1436313697 | Python | Python | py | Runtime Error | 0 | 0 | 889 | #! -*- coding:utf-8 -*-
while True:
H, W = map(int, raw_input().split(' '))
#print H, W
data = []
for i in range(H):
data.append(list(raw_input()))
flg = [[0 for j in range(W)] for i in range(H)]
def search(i,j,mark):
# if i<0 or i>=H or j<0 or j>=W:
# break
if i+1 < H and flg[i+1][j] == 0 and data[i+1][j] == mark:
flg[i+1][j] = 1
search(i+1,j,mark)
if i-1 >= 0 and flg[i-1][j] == 0 and data[i-1][j] == mark:
flg[i-1][j] = 1
search(i-1,j,mark)
if j+1 < W and flg[i][j+1] == 0 and data[i][j+1] == mark :
flg[i][j+1] = 1
search(i,j+1,mark)
if j-1 >= 0 and flg[i][j-1] == 0 and data[i][j-1] == mark :
flg[i][j-1] = 1
search(i,j-1,mark)
count = 0
for i in range(H):
for j in range(W):
if flg[i][j] != 0:
continue
search(i,j,data[i][j])
count += 1
if H==0 and W==0:
break
else:
print count
# print data
# print flg |
s850958551 | p00118 | u338932851 | 1440985807 | Python | Python | py | Runtime Error | 0 | 0 | 1349 | dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def dfs(i, j):
if (area[i][j] == '#'):
area[i][j] = "."
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if ((0 <= nx < W) and (0 <= ny < H) and (area[nx][ny] == '#')):
dfs(nx, ny)
elif (area[i][j] == '@'):
area[i][j] = "."
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if (0 <= nx < W and 0 <= ny < H and area[nx][ny] == '@'):
dfs(nx, ny)
elif (area[i][j] == '*'):
area[i][j] = "."
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if (0 <= nx < W and 0 <= ny < H and area[nx][ny] == '*'):
dfs(nx, ny)
while True:
H, W = map(int, raw_input().split())
area = [list(raw_input()) for i in range(H)]
if H == 0 and W == 0:
break
count = 0
for i in range(W):
for j in range(H):
if area[i][j] == '#':
dfs(i, j)
count += 1
if area[i][j] == '@':
dfs(i, j)
count += 1
if area[i][j] == '*':
dfs(i, j)
count += 1
else:
continue
print count |
s074114633 | p00118 | u338932851 | 1440985893 | Python | Python | py | Runtime Error | 0 | 0 | 1349 | dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def dfs(i, j):
if (area[i][j] == '#'):
area[i][j] = "."
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if ((0 <= nx < W) and (0 <= ny < H) and (area[nx][ny] == '#')):
dfs(nx, ny)
elif (area[i][j] == '@'):
area[i][j] = "."
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if (0 <= nx < W and 0 <= ny < H and area[nx][ny] == '@'):
dfs(nx, ny)
elif (area[i][j] == '*'):
area[i][j] = "."
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if (0 <= nx < W and 0 <= ny < H and area[nx][ny] == '*'):
dfs(nx, ny)
while True:
H, W = map(int, raw_input().split())
area = [list(raw_input()) for i in range(H)]
if H == 0 and W == 0:
break
count = 0
for i in range(W):
for j in range(H):
if area[i][j] == '#':
dfs(i, j)
count += 1
if area[i][j] == '@':
dfs(i, j)
count += 1
if area[i][j] == '*':
dfs(i, j)
count += 1
else:
continue
print count |
s873425394 | p00118 | u489809100 | 1448974867 | Python | Python | py | Runtime Error | 0 | 0 | 746 | def check(x, y, flag):
farm[x][y] = "$"
if farm[x + 1][y] != "$" and farm[x + 1][y] == flag : check(x + 1, y, flag)
if farm[x - 1][y] != "$" and farm[x - 1][y] == flag : check(x - 1, y, flag)
if farm[x][y + 1] != "$" and farm[x][y + 1] == flag : check(x, y + 1, flag)
if farm[x][y - 1] != "$" and farm[x][y - 1] == flag : check(x, y - 1, flag)
while True:
h,w = map(int, raw_input().split())
if h == 0 and w == 0 : break
farm = []
farm.append(list("$" * (w + 2)))
for i in range(0, h):
farm.append(list("$" + raw_input() + "$"))
farm.append(list("$" * (w + 2)))
count = 0
for i in range(0, h):
for j in range(0, w):
if farm[i + 1][j + 1] != "$":
check(i + 1, j + 1, farm[i + 1][j + 1])
count += 1
print count |
s319318407 | p00118 | u489809100 | 1448975059 | Python | Python | py | Runtime Error | 0 | 0 | 642 | def check(x, y, flag):
farm[x][y] = "$"
if farm[x + 1][y] == flag : check(x + 1, y, flag)
if farm[x - 1][y] == flag : check(x - 1, y, flag)
if farm[x][y + 1] == flag : check(x, y + 1, flag)
if farm[x][y - 1] == flag : check(x, y - 1, flag)
while True:
h,w = map(int, raw_input().split())
if h == 0 and w == 0 : break
farm = []
farm.append(list("$" * (w + 2)))
for i in range(0, h):
farm.append(list("$" + raw_input() + "$"))
farm.append(list("$" * (w + 2)))
count = 0
for i in range(0, h):
for j in range(0, w):
if farm[i + 1][j + 1] != "$":
check(i + 1, j + 1, farm[i + 1][j + 1])
count += 1
print count |
s755442666 | p00118 | u489809100 | 1448975281 | Python | Python | py | Runtime Error | 0 | 0 | 642 | def check(x, y, flag):
farm[x][y] = "$"
if farm[x + 1][y] == flag : check(x + 1, y, flag)
if farm[x - 1][y] == flag : check(x - 1, y, flag)
if farm[x][y + 1] == flag : check(x, y + 1, flag)
if farm[x][y - 1] == flag : check(x, y - 1, flag)
while True:
h,w = map(int, raw_input().split())
if h == 0 and w == 0 : break
farm = []
farm.append(list("$" * (h + 2)))
for i in range(0, w):
farm.append(list("$" + raw_input() + "$"))
farm.append(list("$" * (h + 2)))
count = 0
for i in range(0, w):
for j in range(0, h):
if farm[i + 1][j + 1] != "$":
check(i + 1, j + 1, farm[i + 1][j + 1])
count += 1
print count |
s924102865 | p00118 | u489809100 | 1448975480 | Python | Python | py | Runtime Error | 0 | 0 | 646 | def check(x, y, flag):
farm[x][y] = "$"
if farm[x + 1][y] == flag : check(x + 1, y, flag)
if farm[x - 1][y] == flag : check(x - 1, y, flag)
if farm[x][y + 1] == flag : check(x, y + 1, flag)
if farm[x][y - 1] == flag : check(x, y - 1, flag)
return 1
while True:
h,w = map(int, raw_input().split())
if h == 0 and w == 0 : break
farm = []
farm.append(list("$" * (w + 2)))
for i in range(0, h):
farm.append(list("$" + raw_input() + "$"))
farm.append(list("$" * (w + 2)))
count = 0
for i in range(0, h):
for j in range(0, w):
if farm[i + 1][j + 1] != "$":
count += check(i + 1, j + 1, farm[i + 1][j + 1])
print count |
s773344827 | p00118 | u489809100 | 1448975632 | Python | Python | py | Runtime Error | 0 | 0 | 687 | import sys
sys.setrecursionlimit(10000)
def check(x, y, flag):
farm[x][y] = "$"
if farm[x + 1][y] == flag : check(x + 1, y, flag)
if farm[x - 1][y] == flag : check(x - 1, y, flag)
if farm[x][y + 1] == flag : check(x, y + 1, flag)
if farm[x][y - 1] == flag : check(x, y - 1, flag)
return 1
while True:
h,w = map(int, raw_input().split())
if h == 0 and w == 0 : break
farm = []
farm.append(list("$" * (w + 2)))
for i in range(0, h):
farm.append(list("$" + raw_input() + "$"))
farm.append(list("$" * (w + 2)))
count = 0
for i in range(0, h):
for j in range(0, w):
if farm[i + 1][j + 1] != "$":
count += check(i + 1, j + 1, farm[i + 1][j + 1])
print count |
s548810327 | p00118 | u421925564 | 1461571868 | Python | Python3 | py | Runtime Error | 0 | 0 | 747 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return 1
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
n += dfs(j, i, list1[i][j])
print(n) |
s824789406 | p00118 | u421925564 | 1461571951 | Python | Python3 | py | Runtime Error | 0 | 0 | 747 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return 1
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
n += dfs(j, i, list1[i][j])
print(n) |
s432708699 | p00118 | u421925564 | 1461572070 | Python | Python3 | py | Runtime Error | 0 | 0 | 747 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return 1
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
n += dfs(j, i, list1[i][j])
print(n) |
s165281318 | p00118 | u421925564 | 1461572098 | Python | Python | py | Runtime Error | 0 | 0 | 747 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return 1
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
n += dfs(j, i, list1[i][j])
print(n) |
s499764544 | p00118 | u421925564 | 1461649461 | Python | Python3 | py | Runtime Error | 0 | 0 | 747 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return 1
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
n += dfs(j, i, list1[i][j])
print(n) |
s329196479 | p00118 | u421925564 | 1461653693 | Python | Python3 | py | Runtime Error | 0 | 0 | 1046 | h = w = 0
slist =[]
list1=[]
def dfs(f):
while True:
if len(slist) == 0:
return 1
coordinate= slist.pop()
#print(coordinate)
x = coordinate[0]
y = coordinate[1]
list1[y] = list1[y][:x] + '1' + list1[y][x + 1:]
if x + 1 < w:
if list1[y][x + 1] == f:
slist.append([x + 1,y])
if x - 1 >= 0:
if list1[y][x-1] == f:
slist.append([x - 1, y])
if y + 1 < h:
if list1[y + 1][x] == f:
slist.append([x, y + 1])
if y -1 >= 0:
if list1[y -1][x] == f:
slist.append([x, y - 1])
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
slist.append([j,i])
n += dfs(list1[i][j])
#print(list1)
print(n) |
s159535702 | p00118 | u421925564 | 1461653734 | Python | Python3 | py | Runtime Error | 0 | 0 | 1046 | h = w = 0
slist =[]
list1=[]
def dfs(f):
while True:
if len(slist) == 0:
return 1
coordinate= slist.pop()
#print(coordinate)
x = coordinate[0]
y = coordinate[1]
list1[y] = list1[y][:x] + '1' + list1[y][x + 1:]
if x + 1 < w:
if list1[y][x + 1] == f:
slist.append([x + 1,y])
if x - 1 >= 0:
if list1[y][x-1] == f:
slist.append([x - 1, y])
if y + 1 < h:
if list1[y + 1][x] == f:
slist.append([x, y + 1])
if y -1 >= 0:
if list1[y -1][x] == f:
slist.append([x, y - 1])
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
slist.append([j,i])
n += dfs(list1[i][j])
#print(list1)
print(n) |
s508481170 | p00118 | u421925564 | 1461653759 | Python | Python3 | py | Runtime Error | 0 | 0 | 1046 | h = w = 0
slist =[]
list1=[]
def dfs(f):
while True:
if len(slist) == 0:
return 1
coordinate= slist.pop()
#print(coordinate)
x = coordinate[0]
y = coordinate[1]
list1[y] = list1[y][:x] + '1' + list1[y][x + 1:]
if x + 1 < w:
if list1[y][x + 1] == f:
slist.append([x + 1,y])
if x - 1 >= 0:
if list1[y][x-1] == f:
slist.append([x - 1, y])
if y + 1 < h:
if list1[y + 1][x] == f:
slist.append([x, y + 1])
if y -1 >= 0:
if list1[y -1][x] == f:
slist.append([x, y - 1])
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
slist.append([j,i])
n += dfs(list1[i][j])
#print(list1)
print(n) |
s142838702 | p00118 | u421925564 | 1461654033 | Python | Python3 | py | Runtime Error | 0 | 0 | 1046 | h = w = 0
slist =[]
list1=[]
def dfs(f):
while True:
if len(slist) == 0:
return 1
coordinate= slist.pop()
#print(coordinate)
x = coordinate[0]
y = coordinate[1]
list1[y] = list1[y][:x] + '1' + list1[y][x + 1:]
if x + 1 < w:
if list1[y][x + 1] == f:
slist.append([x + 1,y])
if x - 1 >= 0:
if list1[y][x-1] == f:
slist.append([x - 1, y])
if y + 1 < h:
if list1[y + 1][x] == f:
slist.append([x, y + 1])
if y -1 >= 0:
if list1[y -1][x] == f:
slist.append([x, y - 1])
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
slist.append([j,i])
n += dfs(list1[i][j])
#print(list1)
print(n) |
s204894645 | p00118 | u421925564 | 1461654818 | Python | Python3 | py | Runtime Error | 0 | 0 | 760 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return 1
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
n += dfs(j, i, list1[i][j])
print(n)
list1=[] |
s086812647 | p00118 | u421925564 | 1461654979 | Python | Python3 | py | Runtime Error | 0 | 0 | 760 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return 1
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
n += dfs(j, i, list1[i][j])
print(n)
list1=[] |
s540132425 | p00118 | u421925564 | 1461655447 | Python | Python3 | py | Runtime Error | 0 | 0 | 774 | h = 0
w = 0
list1 = []
def dfs(x, y, f):
list1[y] = list1[y][:x] + '1' + list1[y][x+1:]
if y - 1 >= 0:
if list1[y - 1][x] == f:
dfs(x, y - 1, f)
if y + 1 < h:
if list1[y + 1][x] == f:
dfs(x, y + 1, f)
if x - 1 >= 0:
if list1[y][x - 1] == f:
dfs(x - 1, y, f)
if x + 1 < w:
if list1[y][x + 1] == f:
dfs(x + 1, y, f)
return
while True:
h, w = list(map(lambda x: int(x),input().split(" ")))
if 0 in (h, w):
break
n = 0
for i in range(0, h):
list1.append(input())
for i in range(0, h):
for j in range(0, w):
if list1[i][j] != '1':
dfs(j, i, list1[i][j])
n+=1
print(n)
list1=[] |
s596529673 | p00118 | u884495090 | 1461750786 | Python | Python | py | Runtime Error | 0 | 0 | 657 | #!/usr/bin/env python
matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
def dfs(x,y,fruit):
visited.append((x,y))
for v in vec:
nx = x + v[0]
ny = y + v[1]
if not (nx,ny) in visited and nx in xrange(w) and ny in xrange(h):
if matrix[ny][nx] == fruit:
dfs(nx,ny,fruit)
while True:
h,w = map(int,raw_input().rstrip().split(" "))
if h == 0 and w == 0:
break
matrix = []
visited = []
ans = 0
for i in xrange(h):
s = raw_input().rstrip()
matrix.append(list(s))
for i in xrange(h):
for j in xrange(w):
if not (j,i) in visited:
dfs(j,i,matrix[i][j])
ans+=1
print ans |
s974924382 | p00118 | u884495090 | 1461751088 | Python | Python | py | Runtime Error | 0 | 0 | 657 | #!/usr/bin/env python
matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
def dfs(x,y,fruit):
visited.append((x,y))
for v in vec:
nx = x + v[0]
ny = y + v[1]
if not (nx,ny) in visited and nx in xrange(w) and ny in xrange(h):
if matrix[ny][nx] == fruit:
dfs(nx,ny,fruit)
while True:
h,w = map(int,raw_input().rstrip().split(" "))
if h == 0 and w == 0:
break
matrix = []
visited = []
ans = 0
for i in xrange(h):
s = raw_input().rstrip()
matrix.append(list(s))
for i in xrange(h):
for j in xrange(w):
if not (j,i) in visited:
dfs(j,i,matrix[i][j])
ans+=1
print ans |
s419661467 | p00118 | u884495090 | 1461751428 | Python | Python | py | Runtime Error | 0 | 0 | 698 | #!/usr/bin/env python
import sys
sys.setrecursionlimit(10000)
matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
def dfs(x,y,fruit):
visited.append((x,y))
for v in vec:
nx = x + v[0]
ny = y + v[1]
if not (nx,ny) in visited and nx in xrange(w) and ny in xrange(h):
if matrix[ny][nx] == fruit:
dfs(nx,ny,fruit)
while True:
h,w = map(int,raw_input().rstrip().split(" "))
if h == 0 and w == 0:
break
matrix = []
visited = []
ans = 0
for i in xrange(h):
s = raw_input().rstrip()
matrix.append(list(s))
for i in xrange(h):
for j in xrange(w):
if not (j,i) in visited:
dfs(j,i,matrix[i][j])
ans+=1
print ans |
s804996133 | p00118 | u884495090 | 1461752357 | Python | Python | py | Runtime Error | 0 | 0 | 737 | #!/usr/bin/env python
import sys
sys.setrecursionlimit(10000)
matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
h = 0
w = 0
def dfs(x,y,fruit):
global visited
visited.append((x,y))
for v in vec:
nx = x + v[0]
ny = y + v[1]
if (not (nx,ny) in visited) and nx in xrange(w) and ny in xrange(h):
if matrix[ny][nx] == fruit:
dfs(nx,ny,fruit)
return 0
while True:
h,w = map(int,raw_input().rstrip().split(" "))
if h == 0 and w == 0:
break
matrix = []
visited = []
ans = 0
for i in xrange(h):
s = raw_input().rstrip()
matrix.append(list(s))
for i in xrange(h):
for j in xrange(w):
if not (j,i) in visited:
dfs(j,i,matrix[i][j])
ans+=1
print ans |
s373504365 | p00118 | u884495090 | 1461755424 | Python | Python | py | Runtime Error | 0 | 0 | 753 | #!/usr/bin/env python
matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
h = 0
w = 0
def dfs(x,y,fruit):
#visited.append((x,y))
visited[y][x] = 1
for v in vec:
nx = x + v[0]
ny = y + v[1]
if nx in xrange(w) and ny in xrange(h):
if visited[ny][nx]==0 and matrix[ny][nx] == fruit:
dfs(nx,ny,fruit)
return 0
while True:
h,w = map(int,raw_input().split())
if h == 0 and w == 0:
break
# print h,w
matrix = []
visited = []
ans = 0
for i in xrange(h):
s = raw_input().rstrip()
matrix.append(list(s))
visited.append([0]*w)
for i in xrange(h):
for j in xrange(w):
#if not (j,i) in visited:
if visited[i][j] == 0:
dfs(j,i,matrix[i][j])
ans+=1
print ans |
s952960747 | p00118 | u884495090 | 1461755480 | Python | Python | py | Runtime Error | 0 | 0 | 793 | #!/usr/bin/env python
import sys
sys.setrecursionlimit(10000)
matrix = []
vec = [[1,0],[-1,0],[0,1],[0,-1]]
visited =[]
h = 0
w = 0
def dfs(x,y,fruit):
#visited.append((x,y))
visited[y][x] = 1
for v in vec:
nx = x + v[0]
ny = y + v[1]
if nx in xrange(w) and ny in xrange(h):
if visited[ny][nx]==0 and matrix[ny][nx] == fruit:
dfs(nx,ny,fruit)
return 0
while True:
h,w = map(int,raw_input().split())
if h == 0 and w == 0:
break
# print h,w
matrix = []
visited = []
ans = 0
for i in xrange(h):
s = raw_input().rstrip()
matrix.append(list(s))
visited.append([0]*w)
for i in xrange(h):
for j in xrange(w):
#if not (j,i) in visited:
if visited[i][j] == 0:
dfs(j,i,matrix[i][j])
ans+=1
print ans |
s038087022 | p00118 | u685815919 | 1473650415 | Python | Python | py | Runtime Error | 0 | 0 | 635 | dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
field = []
H, W = 0, 0
def solver(x, y, symbol):
global field, H, W
if x < 0 or y < 0 or x >= H or y >= W:
return
for dx, dy in dxy:
if x+dx < 0 or y+dy < 0 or x+dx >= H or y+dy >= W:
continue
if field[x+dx][y+dy] == symbol:
field[x+dx][y+dy] = '.'
solver(x+dx, y+dy, symbol)
while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
field = [list(raw_input()) for i in range(H)]
ans = 0
for x in xrange(H):
for y in xrange(W):
if field[x][y] != '.':
solver(x, y, field[x][y])
ans += 1
print ans |
s820051097 | p00118 | u685815919 | 1473651135 | Python | Python | py | Runtime Error | 0 | 0 | 636 | dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
field = []
H, W = 0, 0
def solver(x, y, symbol):
global field, H, W
if x < 0 or y < 0 or x >= H or y >= W:
return
for dx, dy in dxy:
if x+dx < 0 or y+dy < 0 or x+dx >= H or y+dy >= W:
continue
if field[x+dx][y+dy] == symbol:
field[x+dx][y+dy] = '.'
solver(x+dx, y+dy, symbol)
while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
field = [list(raw_input()) for i in range(H)]
ans = 0
for x in xrange(H):
for y in xrange(W):
if field[x][y] != '.':
solver(x, y, field[x][y])
ans += 1
print ans |
s276510888 | p00118 | u685815919 | 1473652992 | Python | Python | py | Runtime Error | 0 | 0 | 752 | dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
field = []
H, W = 0, 0
q = queue.Queue()
def solver(x, y, symbol):
global q, field, H, W
while True:
if x < 0 or y < 0 or x >= H or y >= W:
continue
for dx, dy in dxy:
if x+dx < 0 or y+dy < 0 or x+dx >= H or y+dy >= W:
continue
if field[x+dx][y+dy] == symbol:
field[x+dx][y+dy] = '.'
q.put([x+dx, y+dy])
data = q.get()
if data is None:
return
x, y = data)
while True:
H, W = map(int, raw_input().split())
if H == 0 and W == 0:
break
field = [list(raw_input()) for i in range(H)]
ans = 0
for x in xrange(H):
for y in xrange(W):
if field[x][y] != '.':
solver(x, y, field[x][y])
ans += 1
print ans |
s235387219 | p00118 | u727466163 | 1473696383 | Python | Python | py | Runtime Error | 0 | 0 | 582 | count=0
a_0=[]
a_1=[]
mode=0
init_input=raw_input().split()
n=init_input[0]
m=init_input[1]
a_0=raw_input().split()
for i in range(m):
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
while n>0:
if mode==0:
a_0=raw_input().split()
for i in range(m):
if a_0[i]!=a_1[i]:
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
else:
a_1=raw_input().split()
for i in range(m):
if a_1[i]!=a_0[i]:
if i==0:
count+=1
else:
if a_1[i]!=a_1[i-1]:
count+=1
mode=0
n-=1
print count |
s252762473 | p00118 | u393305246 | 1473696584 | Python | Python | py | Runtime Error | 0 | 0 | 582 | count=0
a_0=[]
a_1=[]
mode=0
init_input=raw_input().split()
n=init_input[0]
m=init_input[1]
a_0=raw_input().split()
for i in range(m):
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
while n>0:
if mode==0:
a_0=raw_input().split()
for i in range(m):
if a_0[i]!=a_1[i]:
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
else:
a_1=raw_input().split()
for i in range(m):
if a_1[i]!=a_0[i]:
if i==0:
count+=1
else:
if a_1[i]!=a_1[i-1]:
count+=1
mode=0
n-=1
print count |
s308200377 | p00118 | u393305246 | 1473696927 | Python | Python | py | Runtime Error | 0 | 0 | 592 | count=0
a_0=[]
a_1=[]
mode=0
init_input=map(int, raw_input().split())
n=init_input[0]
m=init_input[1]
a_0=raw_input().split()
for i in range(m):
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
while n>0:
if mode==0:
a_0=raw_input().split()
for i in range(m):
if a_0[i]!=a_1[i]:
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
else:
a_1=raw_input().split()
for i in range(m):
if a_1[i]!=a_0[i]:
if i==0:
count+=1
else:
if a_1[i]!=a_1[i-1]:
count+=1
mode=0
n-=1
print count |
s710827057 | p00118 | u393305246 | 1473697441 | Python | Python | py | Runtime Error | 0 | 0 | 592 | count=0
a_0=[]
a_1=[]
mode=0
init_input=map(int, raw_input().split())
n=init_input[0]
m=init_input[1]
line=input()
a_0=list(line)
for i in range(m):
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
while n>0:
line=input()
if mode==0:
a_0=list(line)
for i in range(m):
if a_0[i]!=a_1[i]:
if i==0:
count+=1
else:
if a_0[i]!=a_0[i-1]:
count+=1
mode=1
n-=1
else:
a_1=list(line)
for i in range(m):
if a_1[i]!=a_0[i]:
if i==0:
count+=1
else:
if a_1[i]!=a_1[i-1]:
count+=1
mode=0
n-=1
print count |
s231035398 | p00118 | u350804311 | 1473921229 | Python | Python3 | py | Runtime Error | 0 | 0 | 713 | while True:
H, W = list(map(int, input().split()))
if H == 0 and W == 0:
break
field = []
for i in range(H):
field.append(list(input()))
ans = 0
def field_count(x, y):
fruit = field[x][y]
field[x][y] = "."
for dx in [-1, 0, 1]:
nx = x + dx
if 0 <= nx < H and field[nx][y] == fruit:
field_count(nx, y)
for dy in [-1, 0, 1]:
ny = y + dy
if 0 <= ny < W and field[x][ny] == fruit:
field_count(x, ny)
for i in range(H):
for j in range(W):
if field[i][j] != ".":
field_count(i, j)
ans += 1
print(str(ans)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.