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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s381502199 | p01225 | u798803522 | 1470063748 | Python | Python3 | py | Runtime Error | 0 | 0 | 1107 | trial = int(f.input())
nums,words = [],[]
for s in range(trial):
nums = [[int(n)] for n in f.input().split(" ")]
words = [n for n in f.input().rstrip("\n").split(" ")]
for t in range(9):
nums[t].append(words[t])
nums = sorted(nums,key=lambda x:(x[1],x[0]),reverse=False)
n,color,cnt,samecnt,ans = nums[0][0],nums[0][1],1,1,0
for t in range(1,9):
#print(cnt,samecnt,ans)
if samecnt == 3:
samecnt,cnt,n,color = 1,1,nums[t][0],nums[t][1]
ans += 1
elif cnt == 3:
samecnt,cnt,n,color = 1,1,nums[t][0],nums[t][1]
ans += 1
else:
if color != nums[t][1]:
n,color,cnt,samecnt = nums[t][0],nums[t][1],1,1
elif n == nums[t][0]:
samecnt += 1
elif n == nums[t][0] - 1:
n,samecnt = nums[t][0],1
cnt += 1
else:
print(0)
break
else:
#print(cnt,ans)
if ans == 2 and (samecnt == 3 or cnt == 3):
print(1)
else:
print(0) |
s528230372 | p01225 | u104171359 | 1487387103 | Python | Python3 | py | Runtime Error | 0 | 0 | 1557 | #!usr/bin/env python3
import sys
def main():
WINNING_HANDS = [
'111', '222', '333', '444', '555', '666', '777', '888', '999',
'123', '234', '345', '456', '567', '678', '789'
]
num_of_datasets = int(sys.stdin.readline().strip('\n'))
datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
results = list()
for dataset in range(num_of_datasets):
n_set = [num for num in sys.stdin.readline().strip('\n').split()]
c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
for idx, colour in enumerate(c_set):
if colour == 'R':
datasets[dataset]['R'].append(n_set[idx])
elif colour == 'G':
datasets[dataset]['G'].append(n_set[idx])
elif colour == 'B':
datasets[dataset]['B'].append(n_set[idx])
match_count = int()
for rgb_key in datasets[dataset]:
nums = sorted(datasets[dataset][rgb_key])
for hand in WINNING_HANDS:
if hand[0] and hand[1] and hand[2] in ''.join(nums):
match_count += 1
for digit in hand:
nums.pop(nums.index(digit))
if match_count == 3:
results.append(1)
continue
if dataset < num_of_datasets-1 and match_count != 3:
results.append(0)
for result in results:
print(result)
if __name__ == '__main__':
main() |
s217360903 | p01225 | u104171359 | 1487387490 | Python | Python3 | py | Runtime Error | 0 | 0 | 1616 | #!usr/bin/env python3
import sys
def main():
WINNING_HANDS = [
'111', '222', '333', '444', '555', '666', '777', '888', '999',
'123', '234', '345', '456', '567', '678', '789'
]
num_of_datasets = int(sys.stdin.readline().strip('\n'))
datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
results = list()
for dataset in range(num_of_datasets):
n_set = [num for num in sys.stdin.readline().strip('\n').split()]
c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
for idx, colour in enumerate(c_set):
if colour == 'R':
datasets[dataset]['R'].append(n_set[idx])
elif colour == 'G':
datasets[dataset]['G'].append(n_set[idx])
elif colour == 'B':
datasets[dataset]['B'].append(n_set[idx])
match_count = int()
for rgb_key in datasets[dataset]:
nums = sorted(datasets[dataset][rgb_key])
for hand in WINNING_HANDS:
if hand[0] and hand[1] and hand[2] in ''.join(nums):
match_count += 1
nums.pop(nums.index(hand[0]))
nums.pop(nums.index(hand[1]))
nums.pop(nums.index(hand[2]))
if match_count == 3:
results.append(1)
continue
if dataset < num_of_datasets-1 and match_count != 3:
results.append(0)
for result in results:
print(result)
if __name__ == '__main__':
main() |
s596295607 | p01225 | u886729200 | 1523251541 | Python | Python3 | py | Runtime Error | 0 | 0 | 1098 |
a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append(map(int, input().split()))
else:
a.append(map(str, input().split()))
for i in range(M):
#data = [[2,2,2,3,3,3,1,1,1],["R","G","B","R","G","B","R","G","B"]]
data = a[i*2:(i+1)*2]
data_df = pd.DataFrame(data)
data_df = data_df.sort_values(1,axis=1)
#print(i)
#print(data_df,"\n")
rgb_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
rgb_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(r == 2 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
print("0")
else:
print("0")
|
s953963477 | p01225 | u886729200 | 1523251686 | Python | Python3 | py | Runtime Error | 0 | 0 | 1098 |
a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append(map(int, input().split()))
else:
a.append(map(str, input().split()))
for i in range(M):
#data = [[2,2,2,3,3,3,1,1,1],["R","G","B","R","G","B","R","G","B"]]
data = a[i*2:(i+1)*2]
data_df = pd.DataFrame(data)
data_df = data_df.sort_values(1,axis=1)
#print(i)
#print(data_df,"\n")
rgb_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
rgb_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(r == 2 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
print("0")
else:
print("0")
|
s599868568 | p01225 | u886729200 | 1523251696 | Python | Python3 | py | Runtime Error | 0 | 0 | 1098 |
a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append(map(int, input().split()))
else:
a.append(map(str, input().split()))
for i in range(M):
#data = [[2,2,2,3,3,3,1,1,1],["R","G","B","R","G","B","R","G","B"]]
data = a[i*2:(i+1)*2]
data_df = pd.DataFrame(data)
data_df = data_df.sort_values(1,axis=1)
#print(i)
#print(data_df,"\n")
rgb_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
rgb_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(r == 2 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
print("0")
else:
print("0")
|
s689102932 | p01225 | u886729200 | 1523251975 | Python | Python3 | py | Runtime Error | 0 | 0 | 1102 |
a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append(map(int, input().split()))
else:
a.append(map(str, input().split()))
for i in range(M):
data = a[i*2:(i+1)*2]
data_df = pd.DataFrame(data)
data_df = data_df.sort_values(1,axis=1)
#print(i)
#print(data_df,"\n")
rgb_count = 0
value_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
rgb_count+=1
if r == 2:
value_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(value_count == 3 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
print("0")
else:
print("0")
|
s686564074 | p01225 | u886729200 | 1523253612 | Python | Python3 | py | Runtime Error | 0 | 0 | 1209 | a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append([int(i) for i in input().split()])
else:
a.append([i for i in input().split()])
for i in range(M):
data = a[i*2:(i+1)*2]
print(data)
data_df = pd.DataFrame(data)
data_df = data_df.sort_values((i*2)+1,axis=1)#่ฒใฝใผใ
#print(i)
#print(data_df,"\n")
rgb_count = 0
value_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values((i*2),axis=1)
r = (int(data3.iloc[:,0][(i*2)])+int(data3.iloc[:,2][(i*2)]))/int(data3.iloc[:,1][(i*2)])
if data3.iloc[:,0][(i*2)+1] == data3.iloc[:,1][(i*2)+1] == data3.iloc[:,2][(i*2)+1]:
rgb_count+=1
if r == 2:
value_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(value_count == 3 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][(i*2)] != 8 and data_df.iloc[:,1][(i*2)] != 9 and data_df.iloc[:,3][(i*2)] != 1):
print("0")
else:
print("0")
|
s699657518 | p01225 | u886729200 | 1523253912 | Python | Python3 | py | Runtime Error | 0 | 0 | 1127 | a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append([int(i) for i in input().split()])
else:
a.append([i for i in input().split()])
for i in range(M):
data = a[i*2:(i+1)*2]
data_df = pd.DataFrame(data)
data_df = data_df.sort_values(1,axis=1)#่ฒใฝใผใ
#print(i)
#print(data_df,"\n")
rgb_count = 0
value_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
rgb_count+=1
if r == 2:
value_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(value_count == 3 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
print("0")
else:
print("0")
|
s814220352 | p01225 | u886729200 | 1523253926 | Python | Python3 | py | Runtime Error | 0 | 0 | 1127 | a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append([int(i) for i in input().split()])
else:
a.append([i for i in input().split()])
for i in range(M):
data = a[i*2:(i+1)*2]
data_df = pd.DataFrame(data)
data_df = data_df.sort_values(1,axis=1)#่ฒใฝใผใ
#print(i)
#print(data_df,"\n")
rgb_count = 0
value_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
rgb_count+=1
if r == 2:
value_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(value_count == 3 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
print("0")
else:
print("0")
|
s511424974 | p01225 | u886729200 | 1523253935 | Python | Python3 | py | Runtime Error | 0 | 0 | 1127 | a = []
M = int(input())
for i in range(M*2):
if(i%2==0):
a.append([int(i) for i in input().split()])
else:
a.append([i for i in input().split()])
for i in range(M):
data = a[i*2:(i+1)*2]
data_df = pd.DataFrame(data)
data_df = data_df.sort_values(1,axis=1)#่ฒใฝใผใ
#print(i)
#print(data_df,"\n")
rgb_count = 0
value_count = 0
for j in range(3):
data3 = data_df.iloc[:,3*j:3*(j+1)].sort_values(0,axis=1)
r = (data3.iloc[:,0][0]+data3.iloc[:,2][0])/data3.iloc[:,1][0]
if data3.iloc[:,0][1] == data3.iloc[:,1][1] == data3.iloc[:,2][1]:
rgb_count+=1
if r == 2:
value_count+=1
#print(data3.iloc[:,0][1])
#print("1 = ",data3.iloc[:,1][1])
#print("2 = ",data3.iloc[:,2][1])
#print(data3)
#print("r = ",r)
if(value_count == 3 and rgb_count == 3):#้ฃ็ชใพใใฏๅใๅคใใใคใๅใ่ฒ
print("1")
elif(data_df.iloc[:,0][0] != 8 and data_df.iloc[:,1][0] != 9 and data_df.iloc[:,3][0] != 1):
print("0")
else:
print("0")
|
s836373456 | p01225 | u584093205 | 1526736454 | Python | Python3 | py | Runtime Error | 0 | 0 | 182 | 5
1 2 3 3 4 5 7 7 7
R R R R R R G G G
1 2 2 3 4 4 4 4 5
R R R R R R R R R
1 2 3 4 4 4 5 5 5
R R B R R R R R R
1 1 1 3 4 5 6 6 6
R R B G G G R R R
2 2 2 3 3 3 1 1 1
R G B R G B R G B
|
s449410712 | p01225 | u584093205 | 1526736962 | Python | Python | py | Runtime Error | 0 | 0 | 883 | T = int(input())
for i in range(T):
num = list(map(int, input().split()))
coler = input().split()
groups = [[], [], []]
for i, c in enumerate(coler):
if c == "R":
groups[0].append(num[i])
elif c == "G":
groups[1].append(num[i])
else:
groups[2].append(num[i])
for group in groups:
while len(group) != 0 and len(group) % 3 == 0:
tmp = group[:]
group.sort()
i = group[0]
if group.count(i) >= 3:
for _ in range(3):
group.remove(i)
if i + 1 in group and i + 2 in group:
for j in range(3):
group.remove(i + j)
if tmp == group:
break
if len(groups[0]) == len(groups[1]) == len(groups[2]) == 0:
print(1)
else:
print(0)
|
s932488474 | p01225 | u584093205 | 1526737021 | Python | Python | py | Runtime Error | 0 | 0 | 883 | T = int(input())
for i in range(T):
num = list(map(int, input().split()))
coler = input().split()
groups = [[], [], []]
for i, c in enumerate(coler):
if c == "R":
groups[0].append(num[i])
elif c == "G":
groups[1].append(num[i])
else:
groups[2].append(num[i])
for group in groups:
while len(group) != 0 and len(group) % 3 == 0:
tmp = group[:]
group.sort()
i = group[0]
if group.count(i) >= 3:
for _ in range(3):
group.remove(i)
if i + 1 in group and i + 2 in group:
for j in range(3):
group.remove(i + j)
if tmp == group:
break
if len(groups[0]) == len(groups[1]) == len(groups[2]) == 0:
print(1)
else:
print(0)
|
s112023459 | p01227 | u925390121 | 1540204182 | Python | Python3 | py | Runtime Error | 0 | 0 | 494 | #include <iostream>
#include <algorithm>
using namespace std;
int x[1000000];
int distance[1000000];
int main() {
int all_length;
cin >> n >> k;
for (int i=0; i<n; ++i) {
cin >> x[i];
}
if (n==1) {
cout << 0;
}
else {
all_length = x[n-1] - x[0];
for (int i=0; i<n-1; ++i) {
distance[i] = x[i+1] - x[i];
}
sort(distance, distance+n);
for (int i=0; i<k-1; ++i) {
all_length = all_length - distance[n-1-i];
}
}
cout << all_length;
}
|
s848167158 | p01227 | u025180675 | 1540206895 | Python | Python3 | py | Runtime Error | 0 | 0 | 252 | while True:
N,K = map(int, input().strip().split(" "))
X = list(map(int,input().strip().split(" ")))
L = [X[i+1] - X[i] for i in range(0,N-1)]
L.sort()
print(L)
s = 0
for i in range(0,N-K):
s = s + L[i]
print(s)
|
s784442467 | p01227 | u025180675 | 1540207055 | Python | Python3 | py | Runtime Error | 0 | 0 | 239 | while True:
N,K = map(int, input().strip().split(" "))
X = list(map(int,input().strip().split(" ")))
L = [X[i+1] - X[i] for i in range(0,N-1)]
L.sort()
s = 0
for i in range(0,N-K):
s = s + L[i]
print(s)
|
s273711631 | p01227 | u698762975 | 1555928319 | Python | Python3 | py | Runtime Error | 0 | 0 | 201 | n,k=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
for i in range(n-1):
l1.append(l[i+1]-l[i])
l1=sorted(l1)
for i in range(k-1):
del l1[-1]
s=0
for i in l1:
s+=i
print(s)
|
s808070605 | p01227 | u698762975 | 1555928385 | Python | Python3 | py | Runtime Error | 0 | 0 | 257 | t=int(input())
for j in range(t):
n,k=map(int,input().split())
l=list(map(int,input().split()))
l1=[]
for i in range(n-1):
l1.append(l[i+1]-l[i])
l1=sorted(l1)
for i in range(k-1):
del l1[-1]
s=0
for i in l1:
s+=i
print(s)
|
s092344601 | p01227 | u026821956 | 1555929350 | Python | Python3 | py | Runtime Error | 0 | 0 | 359 | N = int(input())
for i in range(N):
n,k = map(int,input().split())
L = list(map(int,input().split()))
if n <= k:
print(0)
else:
A = []
for j in range(1,N):
A.append(L[i]-L[i-1])
A.sort()
A.reverse()
S = L[N-1]-L[0]
for l in range(k-1):
S -= A[l]
print(S)
|
s107154738 | p01227 | u026821956 | 1555929569 | Python | Python3 | py | Runtime Error | 0 | 0 | 359 | N = int(input())
for i in range(N):
n,k = map(int,input().split())
L = list(map(int,input().split()))
if n <= k:
print(0)
else:
A = []
for j in range(1,n):
A.append(L[i]-L[i-1])
A.sort()
A.reverse()
S = L[n-1]-L[0]
for l in range(k-1):
S -= A[l]
print(S)
|
s375433342 | p01227 | u910909659 | 1555929670 | Python | Python3 | py | Runtime Error | 0 | 0 | 296 | def croad():
n,k = map(int,input().split())
x = list(map(int,input().split()))
y = []
for i in range(n-1):
y.append(x[i+1]-x[i])
y.sort()
y.reverse()
while k>1:
y.pop(0)
k -= 1
print(sum(y))
a = int(input())
for i in range(a):
croad()
|
s207925274 | p01227 | u910909659 | 1555930855 | Python | Python3 | py | Runtime Error | 0 | 0 | 386 | def croad():
n,k = map(int,input().split())
if n == 1:
print(0)
else:
x = list(map(int,input().split()))
y = []
for i in range(n-1):
y.append(x[i+1]-x[i])
y.sort()
y.reverse()
while k>1 and len(y)>0:
y.pop(0)
k -= 1
print(sum(y))
a = int(input())
for i in range(a):
croad()
|
s803568850 | p01227 | u715278210 | 1555931750 | Python | Python3 | py | Runtime Error | 0 | 0 | 547 | o = int(input())
x = 0
while x < o+1: #ๆๅใฎๆฐๅญใฏ้ๅใฎใฎๆฐ
N,K = map(int,input().strip().split(' '))
X = list(map(int,input().strip().split(' ')))#ใชในใใไฝใ
for i in range(N):
X.sort()
a = X[N-1] - X[0] #ๅ
จไฝใฎ้ทใ
Y = [0]*(N-1) #ๅๅฎถใฎ้ใฎ่ท้ขใฎ้ๅ
for j in range(N-1):
Y[j] = X[j+1] - X[j]
Y.sort()
Z = a
for i in range(K-1): #ไธ็ช้ ใ๏ผๅคงใใ๏ผใฎใK-1ๅๅคใ
Z = a - Y[N-1-i-1]
print(Z)
x = x+1
|
s705815999 | p01227 | u715278210 | 1555931792 | Python | Python3 | py | Runtime Error | 0 | 0 | 545 | o = int(input())
x = 0
while x < o+1: #ๆๅใฎๆฐๅญใฏ้ๅใฎใฎๆฐ
N,K = map(int,input().strip().split(' '))
X = list(map(int,input().strip().split(' ')))#ใชในใใไฝใ
for i in range(N):
X.sort()
a = X[N-1] - X[0] #ๅ
จไฝใฎ้ทใ
Y = [0]*(N-1) #ๅๅฎถใฎ้ใฎ่ท้ขใฎ้ๅ
for j in range(N-1):
Y[j] = X[j+1] - X[j]
Y.sort()
Z = a
for i in range(K-1): #ไธ็ช้ ใ๏ผๅคงใใ๏ผใฎใK-1ๅๅคใ
Z = a - Y[N-1-i]
print(Z)
x = x+1
|
s847381717 | p01227 | u797636303 | 1555931889 | Python | Python3 | py | Runtime Error | 0 | 0 | 259 | N,K=map(int, input().strip().split())
X=list(map(int, input().strip().split()))
X.sort(reverse=True)
print(X)
Y=[]
for i in range(len(X)-1):
Y.append(X[i]-X[i+1])
Y.sort(reverse=True)
del Y[:K-1]
print(Y)
a=0
for i in range(len(Y)):
a=a+Y[i]
print(a)
|
s431024157 | p01227 | u715278210 | 1555932107 | Python | Python3 | py | Runtime Error | 0 | 0 | 547 | o = int(input())
x = 0
while x < o+1: #ๆๅใฎๆฐๅญใฏ้ๅใฎใฎๆฐ
N,K = map(int,input().strip().split(' '))
X = list(map(int,input().strip().split(' ')))#ใชในใใไฝใ
for i in range(N):
X.sort()
a = X[N-1] - X[0] #ๅ
จไฝใฎ้ทใ
Y = [0]*(N-1) #ๅๅฎถใฎ้ใฎ่ท้ขใฎ้ๅ
for j in range(N-1):
Y[j] = X[j+1] - X[j]
Y.sort()
Z = a
for i in range(K-1): #ไธ็ช้ ใ๏ผๅคงใใ๏ผใฎใK-1ๅๅคใ
Z = a - Y[N-1-1-i]
print(Z)
x = x+1
|
s940515672 | p01227 | u715278210 | 1555932259 | Python | Python3 | py | Runtime Error | 0 | 0 | 547 | o = int(input())
x = 0
while x < o+1: #ๆๅใฎๆฐๅญใฏ้ๅใฎใฎๆฐ
N,K = map(int,input().strip().split(' '))
X = list(map(int,input().strip().split(' ')))#ใชในใใไฝใ
for i in range(N):
X.sort()
a = X[N-1] - X[0] #ๅ
จไฝใฎ้ทใ
Y = [0]*(N-1) #ๅๅฎถใฎ้ใฎ่ท้ขใฎ้ๅ
for j in range(N-1):
Y[j] = X[j+1] - X[j]
Y.sort()
Z = a
for i in range(K-1): #ไธ็ช้ ใ๏ผๅคงใใ๏ผใฎใK-1ๅๅคใ
Z = Z - Y[N-1-1-i]
print(Z)
x = x+1
|
s082017247 | p01227 | u715278210 | 1555932419 | Python | Python3 | py | Runtime Error | 0 | 0 | 547 | o = int(input())
x = 0
while x < o+1: #ๆๅใฎๆฐๅญใฏ้ๅใฎใฎๆฐ
N,K = map(int,input().strip().split(' '))
X = list(map(int,input().strip().split(' ')))#ใชในใใไฝใ
for i in range(N):
X.sort()
a = X[N-1] - X[0] #ๅ
จไฝใฎ้ทใ
Y = [0]*(N-1) #ๅๅฎถใฎ้ใฎ่ท้ขใฎ้ๅ
for j in range(N-1):
Y[j] = X[j+1] - X[j]
Y.sort()
Z = a
for i in range(K-1): #ไธ็ช้ ใ๏ผๅคงใใ๏ผใฎใK-1ๅๅคใ
Z = Z - Y[N-1-1-i]
print(Z)
x = x+1
|
s710787463 | p01227 | u715278210 | 1555932754 | Python | Python3 | py | Runtime Error | 0 | 0 | 572 | o = int(input())
x = 0
while x < o+1: #ๆๅใฎๆฐๅญใฏ้ๅใฎใฎๆฐ
N,K = map(int,input().strip().split(' '))
X = list(map(int,input().strip().split(' ')))#ใชในใใไฝใ
if N =< K:
K = N
for i in range(N):
X.sort()
a = X[N-1] - X[0] #ๅ
จไฝใฎ้ทใ
Y = [0]*(N-1) #ๅๅฎถใฎ้ใฎ่ท้ขใฎ้ๅ
for j in range(N-1):
Y[j] = X[j+1] - X[j]
Y.sort()
Z = a
for i in range(K-1): #ไธ็ช้ ใ๏ผๅคงใใ๏ผใฎใK-1ๅๅคใ
Z = Z - Y[N-1-1-i]
print(Z)
x = x+1
|
s445718393 | p01227 | u772853944 | 1556084540 | Python | Python3 | py | Runtime Error | 0 | 0 | 422 | def f(n,k,x):
dis = [x[i+1]-x[i] for i in range(n-1)]#้ฃใๅใๅฎถใฎ่ท้ขใ่ชฟในใ
dis.sort()#้ป็ทใฎๆฐ-1ใ ใ้ฃใๅใๅฎถๅๅฃซใฎ้ป็ทใ้
็ฝฎใใชใใฆ่ฏใ
return sum(dis[:n-k])#้ฃใๅใๅฎถใฎ่ท้ขใๅคงใใ้ ใซkใผ1ๅใฏ้ป็ทใ้
็ฝฎใใชใ
t = int(input())
for i in range(t):
n,k = map(int,input().split())
x = list(map(int,input().split()))
print(ans)
|
s633023416 | p01227 | u715278210 | 1556593901 | Python | Python3 | py | Runtime Error | 0 | 0 | 571 | = int(input())
x = 0
while x < o+1: #ๆๅใฎๆฐๅญใฏ้ๅใฎใฎๆฐ
N,K = map(int,input().strip().split(' '))
X = list(map(int,input().strip().split(' ')))#ใชในใใไฝใ
if N < K:
K = N
for i in range(N):
X.sort()
a = X[N-1] - X[0] #ๅ
จไฝใฎ้ทใ
Y = [0]*(N-1) #ๅๅฎถใฎ้ใฎ่ท้ขใฎ้ๅ
for j in range(N-1):
Y[j] = X[j+1] - X[j]
Y.sort()
Z = a
for i in range(K-1): #ไธ็ช้ ใ๏ผๅคงใใ๏ผใฎใK-1ๅๅคใ
Z = Z - Y[N-1-1-i]
print(Z)
x = x+1
|
s844888725 | p01227 | u798803522 | 1470238746 | Python | Python3 | py | Runtime Error | 0 | 0 | 316 | trial = int(input())
for t in range(trial):
housecnt,elec = (int(n) for n in input().split(" "))
house = [int(n) for n in input().split(" ")]
maxlist = []
for h in range(housecnt-1):
maxlist.append(house[h+1]-house[h])
for p in range(elec-1):
maxlist.pop()
print(sum(maxlist)) |
s112947219 | p01227 | u798803522 | 1470238893 | Python | Python3 | py | Runtime Error | 0 | 0 | 349 | trial = int(input())
for t in range(trial):
housecnt,elec = (int(n) for n in input().split(" "))
house = [int(n) for n in input().split(" ")]
maxlist = []
for h in range(housecnt-1):
maxlist.append(house[h+1]-house[h])
maxlist.sort()
for p in range(min(housecnt,elec-1)):
maxlist.pop()
print(sum(maxlist)) |
s931549460 | p01227 | u724548524 | 1525534414 | Python | Python3 | py | Runtime Error | 0 | 0 | 424 | for i in range(int(input())):
n, k = map(int, input().split())
d = list(map(int, input().split()))
if k >= n:
print(0)
elif k == 1:
d.sort()
print(d[-1] - d[0])
else:
k = [0] * (k - 1)
d.sort()
for i in range(1, n):
if d[i] - d[i - 1] > k[0]:
k[0] = d[i] - d[i - 1]
k.sort()
print(d[-1] - d[0] - sum(k))
|
s766212331 | p01227 | u584093205 | 1526738657 | Python | Python3 | py | Runtime Error | 0 | 0 | 311 | T = int(input())
for t in range(T):
n, k = map(int, input().split())
X = list(map(int, input().split()))
mid = [X[i] - X[i - 1] for i in range(1, n)]
mid.sort(reverse = True)
ans = sum(mid)
for i in range(k-1):
ans -= mid[i]
if ans == 0:
break
print(ans)
|
s295219396 | p01230 | u647766105 | 1430234309 | Python | Python | py | Runtime Error | 19930 | 20224 | 2036 | def main():
while True:
N, M, Z = map(int, raw_input().split())
if N == 0:
break
L = []
for _ in xrange(M):
s, d = map(int, raw_input().split())
L += [(s, d), (d, s)]
L.sort()
mat = Matrix(2*M, 2*M)
for i, (pre, cur1) in enumerate(L):
for j, (cur2, nex) in enumerate(L):
if cur1 != cur2 or pre == nex:
continue
mat[i][j] = 1
init_mat = Matrix(2*M, 2*M)
for i, (cur, nex) in enumerate(L):
if cur != 1:
continue
for j in xrange(len(L)):
init_mat[j][i] = 1
fin_mat = init_mat * mat ** (Z-1)
for e, (cur, nex) in zip(fin_mat[0], L):
if nex == N and e == 1:
print "yes"
break
else:
print "no"
class Matrix(list):
def __init__(self, r, c, init=None):
self.r, self.c = r, c
list.__init__(self, [[0]*c for _ in xrange(r)])
if init:
for i, r in enumerate(init):
for j, e in enumerate(r):
self[i][j] = e
def __repr__(self):
return "\n".join(map(str, self))
def __mul__(self, mat):
if self.r != mat.r or self.c != mat.c:
raise Exception
ret = Matrix(self.r, self.c)
for i, r in enumerate(self):
for j, c in enumerate(zip(*mat)):
ret[i][j] = sum(e1 * e2 for e1, e2 in zip(r, c))
return ret
@classmethod
def get_im(cls, n):
ret = Matrix(n, n)
for i in xrange(n):
ret[i][i] += 1
return ret
def __pow__(self, n):
if self.r != self.c:
raise Exception
ret = Matrix.get_im(self.r)
x = Matrix(self.r, self.c, self)
while n > 0:
if (n & 1):
ret = ret * x
x = x * x
n >>= 1
return ret
if __name__ == "__main__":
main() |
s189598790 | p01230 | u647766105 | 1430234872 | Python | Python | py | Runtime Error | 19930 | 4952 | 2119 | def main():
while True:
N, M, Z = map(int, raw_input().split())
if N == 0:
break
L = []
for _ in xrange(M):
s, d = map(int, raw_input().split())
L += [(s, d), (d, s)]
L.sort()
mat = Matrix(2*M, 2*M)
for i, (pre, cur1) in enumerate(L):
for j, (cur2, nex) in enumerate(L):
if cur1 != cur2 or pre == nex:
continue
mat[i][j] = 1
init_mat = Matrix(2*M, 2*M)
for i, (cur, nex) in enumerate(L):
if cur != 1:
continue
for j in xrange(len(L)):
init_mat[j][i] = 1
fin_mat = init_mat * mat ** (Z-1)
for e, (cur, nex) in zip(fin_mat[0], L):
if nex == N and e == 1:
print "yes"
break
else:
print "no"
class Matrix(list):
def __init__(self, r, c, init=None):
self.r, self.c = r, c
list.__init__(self, [[0]*c for _ in xrange(r)])
if init:
for i, r in enumerate(init):
for j, e in enumerate(r):
self[i][j] = e
def __repr__(self):
return "\n".join(map(str, self))
def __mul__(self, mat):
if self.r != mat.r or self.c != mat.c:
raise Exception
ret = Matrix(self.r, self.c)
for i, r in enumerate(self):
for j, c in enumerate(zip(*mat)):
# ret[i][j] = sum(e1 * e2 for e1, e2 in zip(r, c))
ret[i][j] = 1 if sum(e1 * e2 for e1, e2 in zip(r, c)) > 0 else 0
return ret
@classmethod
def get_im(cls, n):
ret = Matrix(n, n)
for i in xrange(n):
ret[i][i] += 1
return ret
def __pow__(self, n):
if self.r != self.c:
raise Exception
ret = Matrix.get_im(self.r)
x = Matrix(self.r, self.c, self)
while n > 0:
if (n & 1):
ret = ret * x
x = x * x
n >>= 1
return ret
if __name__ == "__main__":
main() |
s533525264 | p01230 | u647766105 | 1430235176 | Python | Python | py | Runtime Error | 19930 | 4968 | 2141 | def main():
while True:
N, M, Z = map(int, raw_input().split())
print N, M, Z
if N == 0:
break
L = []
for _ in xrange(M):
s, d = map(int, raw_input().split())
L += [(s, d), (d, s)]
L.sort()
mat = Matrix(2*M, 2*M)
for i, (pre, cur1) in enumerate(L):
for j, (cur2, nex) in enumerate(L):
if cur1 != cur2 or pre == nex:
continue
mat[i][j] = 1
init_mat = Matrix(2*M, 2*M)
for i, (cur, nex) in enumerate(L):
if cur != 1:
continue
for j in xrange(len(L)):
init_mat[j][i] = 1
fin_mat = init_mat * mat ** (Z-1)
for e, (cur, nex) in zip(fin_mat[0], L):
if nex == N and e == 1:
print "yes"
break
else:
print "no"
class Matrix(list):
def __init__(self, r, c, init=None):
self.r, self.c = r, c
list.__init__(self, [[0]*c for _ in xrange(r)])
if init:
for i, r in enumerate(init):
for j, e in enumerate(r):
self[i][j] = e
def __repr__(self):
return "\n".join(map(str, self))
def __mul__(self, mat):
if self.r != mat.r or self.c != mat.c:
raise Exception
ret = Matrix(self.r, self.c)
for i, r in enumerate(self):
for j, c in enumerate(zip(*mat)):
# ret[i][j] = sum(e1 * e2 for e1, e2 in zip(r, c))
ret[i][j] = 1 if any(e1 * e2 for e1, e2 in zip(r, c)) > 0 else 0
return ret
@classmethod
def get_im(cls, n):
ret = Matrix(n, n)
for i in xrange(n):
ret[i][i] += 1
return ret
def __pow__(self, n):
if self.r != self.c:
raise Exception
ret = Matrix.get_im(self.r)
x = Matrix(self.r, self.c, self)
while n > 0:
if (n & 1):
ret = ret * x
x = x * x
n >>= 1
return ret
if __name__ == "__main__":
main() |
s739942426 | p01230 | u647766105 | 1430238021 | Python | Python | py | Runtime Error | 19930 | 5040 | 2211 | from itertools import izip as zip
def main():
while True:
N, M, Z = map(int, raw_input().split())
if N == 0:
break
L = []
for _ in xrange(M):
s, d = map(int, raw_input().split())
L += [(s, d), (d, s)]
L.sort()
mat = Matrix(2*M, 2*M)
for i, (pre, cur1) in enumerate(L):
for j, (cur2, nex) in enumerate(L):
if cur1 != cur2 or pre == nex:
continue
mat[i][j] = 1
init_mat = Matrix(2*M, 2*M)
for i, (cur, nex) in enumerate(L):
if cur != 1:
continue
for j in xrange(len(L)):
init_mat[j][i] = 1
fin_mat = init_mat * mat ** (Z-1)
for e, (cur, nex) in zip(fin_mat[0], L):
if nex == N and e == 1:
print "yes"
break
else:
print "no"
class Matrix(list):
def __init__(self, r, c, init=None):
self.r, self.c = r, c
list.__init__(self, [[0]*c for _ in xrange(r)])
if init:
for i, r in enumerate(init):
for j, e in enumerate(r):
self[i][j] = e
def __repr__(self):
return "\n".join(map(str, self))
def __mul__(self, mat):
if self.r != mat.r or self.c != mat.c:
raise Exception
ret = Matrix(self.r, self.c)
for i, r in enumerate(self):
for j, c in enumerate(zip(*mat)):
# ret[i][j] = sum(e1 * e2 for e1, e2 in zip(r, c))
ret[i][j] = any(e1 and e2 for e1, e2 in zip(r, c))
return ret
@classmethod
def get_im(cls, n):
ret = Matrix(n, n)
for i in xrange(n):
ret[i][i] += 1
return ret
def __pow__(self, n):
import sys
if self.r != self.c:
raise Exception
ret = Matrix.get_im(self.r)
x = Matrix(self.r, self.c, self)
while n > 0:
#print n
#sys.stdout.flush()
if (n & 1):
ret = ret * x
x = x * x
n >>= 1
return ret
if __name__ == "__main__":
main() |
s836908522 | p01230 | u647766105 | 1430239156 | Python | Python | py | Runtime Error | 19930 | 5024 | 2278 | from itertools import izip as zip
def main():
while True:
N, M, Z = map(int, raw_input().split())
if N == 0:
break
L = []
for _ in xrange(M):
s, d = map(int, raw_input().split())
L += [(s, d), (d, s)]
#L.sort()
mat = Matrix(2*M, 2*M)
for i, (pre, cur1) in enumerate(L):
for j, (cur2, nex) in enumerate(L):
if cur1 != cur2 or pre == nex:
continue
mat[i][j] = 1
init_mat = Matrix(2*M, 2*M)
for i, (cur, nex) in enumerate(L):
if cur != 1:
continue
for j in xrange(len(L)):
init_mat[j][i] = 1
fin_mat = init_mat * mat ** (Z-1)
for e, (cur, nex) in zip(fin_mat[0], L):
if nex == N and e == 1:
print "yes"
break
else:
print "no"
class Matrix(list):
def __init__(self, r, c, init=None):
self.r, self.c = r, c
list.__init__(self, [[0]*c for _ in xrange(r)])
if init:
for i, r in enumerate(init):
for j, e in enumerate(r):
self[i][j] = e
def __repr__(self):
return "\n".join(map(str, self))
def __mul__(self, mat):
#if self.r != mat.c or self.c != mat.r:
# raise Exception
#ret = Matrix(self.r, self.c)
#for i, r in enumerate(self):
# for j, c in enumerate(zip(*mat)):
# ret[i][j] = sum(e1 * e2 for e1, e2 in zip(r, c))
# ret[i][j] = any(e1 * e2 for e1, e2 in zip(r, c))
#return ret
ret = ((any(e1 * e2 for e1, e2 in zip(r, c)) for c in zip(*mat)) for r in self)
return Matrix(self.r, self.c, ret)
@classmethod
def get_im(cls, n):
ret = Matrix(n, n)
for i in xrange(n):
ret[i][i] += 1
return ret
def __pow__(self, n):
if self.r != self.c:
raise Exception
ret = Matrix.get_im(self.r)
x = Matrix(self.r, self.c, self)
while n > 0:
if (n & 1):
ret = ret * x
x = x * x
n >>= 1
return ret
if __name__ == "__main__":
main() |
s875794745 | p01230 | u647766105 | 1430241048 | Python | Python | py | Runtime Error | 19930 | 5020 | 2281 | from itertools import izip as zip
def main():
while True:
N, M, Z = map(int, raw_input().split())
if N == 0:
break
L = []
for _ in xrange(M):
s, d = map(int, raw_input().split())
L += [(s, d), (d, s)]
#L.sort()
mat = Matrix(2*M, 2*M)
for i, (pre, cur1) in enumerate(L):
for j, (cur2, nex) in enumerate(L):
if cur1 != cur2 or pre == nex:
continue
mat[i][j] = 1
init_mat = Matrix(2*M, 2*M)
for i, (cur, nex) in enumerate(L):
if cur != 1:
continue
for j in xrange(len(L)):
init_mat[j][i] = 1
fin_mat = init_mat * mat ** (Z-1)
for e, (cur, nex) in zip(fin_mat[0], L):
if nex == N and e == 1:
print "yes"
break
else:
print "no"
class Matrix(list):
def __init__(self, r, c, init=None):
self.r, self.c = r, c
list.__init__(self, [[0]*c for _ in xrange(r)])
if init:
for i, r in enumerate(init):
for j, e in enumerate(r):
self[i][j] = e
def __repr__(self):
return "\n".join(map(str, self))
def __mul__(self, mat):
#if self.r != mat.c or self.c != mat.r:
# raise Exception
#ret = Matrix(self.r, self.c)
#for i, r in enumerate(self):
# for j, c in enumerate(zip(*mat)):
# ret[i][j] = sum(e1 * e2 for e1, e2 in zip(r, c))
# ret[i][j] = any(e1 * e2 for e1, e2 in zip(r, c))
#return ret
ret = ((any(e1 and e2 for e1, e2 in zip(r, c)) for c in zip(*mat)) for r in self)
return Matrix(self.r, self.c, ret)
@classmethod
def get_im(cls, n):
ret = Matrix(n, n)
for i in xrange(n):
ret[i][i] += 1
return ret
def __pow__(self, n):
if self.r != self.c:
raise Exception
ret = Matrix.get_im(self.r)
x = Matrix(self.r, self.c, self)
while n > 0:
if (n & 1):
ret = ret * x
x = x * x
n >>= 1
return ret
if __name__ == "__main__":
main() |
s123644436 | p01253 | u266872031 | 1437058113 | Python | Python | py | Runtime Error | 39870 | 4520 | 631 | while(1):
[N,T]=[int(x) for x in raw_input().split()]
if T==0:
break
else:
RB=raw_input()
probold=[0 for i in range(N+6)]
probnew=[0 for i in range(N+6)]
for i in range(N):
if RB[i]=='R':
probold[i]=1
else:
probold[i]=0
for i in range(6):
probold[N+i]=probold[i]
for j in range(T):
for i in range(N):
probnew[i]=1./6*sum(probold[i+1:i+7])
for i in range(6):
probnew[N+i]=probnew[i]
probold[:]=probnew[:]
print max(probnew) |
s909051601 | p01253 | u266872031 | 1437058578 | Python | Python | py | Runtime Error | 39860 | 4532 | 701 | while(1):
[N,T]=[int(x) for x in raw_input().split()]
if T==0:
break
else:
RB=raw_input()
probold=[0 for i in range(N+6)]
probnew=[0 for i in range(N+6)]
for i in range(N):
if RB[i]=='R':
probold[i]=1
else:
probold[i]=0
for i in range(6):
probold[N+i]=probold[i]
for j in range(T):
if max(probold)-min(probold)<1e-10:
break
for i in range(N):
probnew[i]=1./6*sum(probold[i+1:i+7])
for i in range(6):
probnew[N+i]=probnew[i]
probold[:]=probnew[:]
print max(probold) |
s621883827 | p01255 | u266872031 | 1435599555 | Python | Python | py | Runtime Error | 0 | 0 | 1631 | def crosscheck(line1,line2):
a1=line1[0]
a2=line1[1]
b1=line2[0]
b2=line2[1]
t1=line1[2]-line1[0]
t2=line1[3]-line1[1]
s1=line2[2]-line2[0]
s2=line2[3]-line2[1]
if -t1*s2+t2*s1!=0:
k=((b1-a1)*-s2+(b2-a2)*s1)*1./(-t1*s2+t2*s1)
j=((b1-a1)*-t2+(b2-a2)*t1)*1./(-t1*s2+t2*s1)
if 0<=k and 1>=k and 0<=j and 1>=j:
return 1
else:
if (b1-a1)*t2==(b2-a2)*t1 and ((0<=(b1-a1) and t1>=(b1-a1)) or (0<=(b2-a2) and t2>=(b2-a2))):
return 1
return 0
while(1):
N=int(raw_input())
if N==0:
break
else:
floor=[[]]
S=int(raw_input())
st=[]
for j in range(S):
st.append([int(x) for x in raw_input().split()])
for j in range(S-1):
floor[0].append(st[j]+st[j+1])
for s in range(1,N):
floornow=0
st=[]
linenow=[]
jn=0
S=int(raw_input())
for j in range(S):
st.append([int(x) for x in raw_input().split()])
for j in range(S-1):
linenow.append(st[j]+st[j+1])
while (1):
for ln in linenow:
if crosscheck(ln,floor[floornow][jn]):
floornow+=1
jn=0
break
jn+=1
if floornow==len(floor):
floor.append(linenow)
break
elif jn==len(floor[floornow]):
floor[floornow]+=linenow
break
print len(floor) |
s987837914 | p01267 | u383876854 | 1444130421 | Python | Python | py | Runtime Error | 0 | 0 | 5 | fvasg |
s722037631 | p01267 | u633333374 | 1502717147 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s425125127 | p01267 | u633333374 | 1502717159 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s989772791 | p01267 | u633333374 | 1502717219 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s499033527 | p01267 | u633333374 | 1502717234 | Python | Python | py | Runtime Error | 0 | 0 | 398 | while 1:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s854714247 | p01267 | u633333374 | 1502717606 | Python | Python | py | Runtime Error | 0 | 0 | 353 | N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s738660747 | p01267 | u633333374 | 1502717816 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s732642257 | p01267 | u633333374 | 1502717851 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s906218815 | p01267 | u633333374 | 1502717856 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s677939083 | p01267 | u633333374 | 1502717860 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s463135907 | p01267 | u633333374 | 1502717865 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s484167805 | p01267 | u633333374 | 1502717868 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s956983026 | p01267 | u633333374 | 1502717927 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s253851015 | p01267 | u633333374 | 1502718592 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s724604292 | p01267 | u633333374 | 1502718655 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s653989589 | p01267 | u633333374 | 1502718702 | Python | Python | py | Runtime Error | 0 | 0 | 398 | while 1:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s093760567 | p01267 | u633333374 | 1502718767 | Python | Python | py | Runtime Error | 0 | 0 | 401 | while True:
N,A,B,C,X = map(int,raw_input().split())
if N == A == B == C == X == 0:break
sum = 0
Z = 0
Y = [int(x) for x in raw_input().split()]
if (X in Y) == True:
Y.remove(X)
while Z == 0:
if sum == 10000:
sum = -2
Z = 1
sum += 1
X = (A*X+B)%C
if X == Y[0]:
Y.pop(0)
if len(Y) == 0:
Z = 1
print sum |
s746768889 | p01267 | u922450532 | 1529060104 | Python | Python3 | py | Runtime Error | 0 | 0 | 608 | while True:
a = input()
a = a.split(" ")
b = []
for i in a:
b.append(int(i))
if b[0] == 0 and b[1] == 0 and b[2] == 0 and b[3] == 0 and b[4] == 0:
break
c = input()
c = c.split(" ")
d = []
for i in c:
d.append(int(i))
if b[4] == d[0]:
print(0)
continue
ans = 2
for i in d:
for e in range(10000):
x = (b[1] * b[4] + b[2]) % b[3]
if x == i:
b[4] = x
break
b[4] = x
ans = ans + 1
if ans >= 10001:
ans = -1
print(ans)
|
s528402281 | p01267 | u922450532 | 1529060317 | Python | Python3 | py | Runtime Error | 0 | 0 | 607 | while True:
a = input()
a = a.split(" ")
b = []
for i in a:
b.append(int(i))
if b[0] == 0 and b[1] == 0 and b[2] == 0 and b[3] == 0 and b[4] == 0:
break
c = input()
c = c.split(" ")
d = []
for i in c:
d.append(int(i))
if b[4] == d[0]:
print(0)
continue
ans = 2
for i in d:
for e in range(10000):
x = (b[1] * b[4] + b[2]) % b[3]
if x == i:
b[4] = x
break
b[4] = x
ans = ans + 1
if ans >= 10001:
ans = -1
print(ans)
|
s177100691 | p01267 | u922450532 | 1529119505 | Python | Python3 | py | Runtime Error | 0 | 0 | 521 | while True:
a = input()
if a == "0 0 0 0 0":
break
a = a.split(" ")
b = []
for i in a:
b.append(int(i))
c = input()
c = c.split(" ")
d = []
for i in c:
d.append(int(i))
if b[4] == d[0]:
print(0)
continue
ans = 0
x = b[4]
for i in d:
for e in range(10000):
x = (b[1] * x + b[2]) % b[3]
ans = ans + 1
if x == i:
break
if ans >= 10001:
ans = -1
print(ans)
|
s022734444 | p01267 | u922450532 | 1529152705 | Python | Python3 | py | Runtime Error | 0 | 0 | 522 | while True:
a = input()
if a == "0 0 0 0 0":
break
a = a.split(" ")
b = []
for i in a:
b.append(int(i))
c = input()
c = c.split(" ")
d = []
for i in c:
d.append(int(i))
if b[4] == d[0]:
print(0)
continue
ans = 0
x = b[4]
for i in d:
for e in range(10001):
x = (b[1] * x + b[2]) % b[3]
ans = ans + 1
if x == i:
break
if ans >= 10001:
ans = -1
print(ans)
|
s056381519 | p01267 | u922450532 | 1529210247 | Python | Python3 | py | Runtime Error | 0 | 0 | 605 | while True:
a = input()
# if a == "0 0 0 0 0":
# break
a = a.split(" ")
b = []
sum = 0
for i in a:
b.append(int(i))
sum += int(i)
print(sum)
if sum == 0:
break
c = input()
c = c.split(" ")
d = []
for i in c:
d.append(int(i))
if b[4] == d[0]:
print(0)
continue
ans = 0
x = b[4]
for i in d:
for e in range(10001):
x = (b[1] * x + b[2]) % b[3]
ans = ans + 1
if x == i:
break
if ans >= 10001:
ans = -1
print(ans)
|
s922100545 | p01267 | u922450532 | 1529211006 | Python | Python3 | py | Runtime Error | 0 | 0 | 627 | while True:
a = input()
# if a == "0 0 0 0 0":
# break
a = a.split(" ")
b = []
sum = 0
for i in a:
b.append(int(i))
sum += int(i)
if sum == 0:
break
c = input()
c = c.split(" ")
d = []
for i in c:
d.append(int(i))
if b[4] == d[0]:
print(0)
continue
ans = 0
x = b[4]
for i in d:
for e in range(10001):
x = (b[1] * x + b[2]) % b[3]
print("x: " ,x)
ans = ans + 1
if x == i:
break
if ans >= 10001:
ans = -1
print(ans)
quit()
|
s440204937 | p01267 | u136916346 | 1530083654 | Python | Python3 | py | Runtime Error | 0 | 0 | 374 | f=lambda A,x,B,C:(A*x+B)%C
while 1:
N,A,B,C,X=map(int,raw_input().split())
if not N and not A and not B and not C and not X:break
Y=list(map(int,raw_input().split()))
T=X
c=[[] for _ in range(N)]
sl=0
for i in range(10005):
if T==Y[sl]:
sl+=1
if sl==N:break
T=f(A,T,B,C)
if i>10000:i=-1
print(i)
|
s293735814 | p01267 | u621997536 | 1387288356 | Python | Python | py | Runtime Error | 0 | 0 | 4 | null |
s254463271 | p01268 | u731235119 | 1422008499 | Python | Python | py | Runtime Error | 0 | 0 | 656 | import math
def sieve (n):
prime = [0,0]
prime += [1 for i in range(n-1)]
ub = math.sqrt(n) + 1
d = 2
while d <= ub:
if prime[d] == 0:
d += 1
continue
prod = 2
while d * prod <= n:
prime[d*prod] = 0
prod += 1
d += 1
return prime
prime = sieve(2*10**5)
while 1:
N,P = map(int,raw_input().split())
if (N,P) == (0,0):
break
prime_ub = P
prime_list = []
prime_num = 0
inc = N + 1
while prime_num < prime_ub :
if prime[inc] == 1:
prime_num += 1
prime_list.append(inc)
inc += 1
sum_list = []
for i in range(prime_num):
sum_list += [prime_list[i] + p for p in prime_list[i:]]
sum_list.sort()
print sum_list[P-1] |
s006053923 | p01268 | u685815919 | 1481253093 | Python | Python | py | Runtime Error | 40000 | 6660 | 643 | def getLargePrime(n,k):
primes=[2]
result=[]
if n<2: result.append(2)
i=3
while True:
isValid=True
for e in primes:
if i%e==0:
isValid=False
break
if i<e**2: break
if isValid: primes.append(i)
if isValid and n<i: result.append(i)
if len(result)>k: break
i+=2
return result
while True:
n,p=map(int,raw_input().split())
if n==-1: break
ps=getLargePrime(n,p)
re=[]
for i in xrange(len(ps)):
for j in xrange(i,len(ps)):
re.append(ps[i]+ps[j])
re=sorted(re)
print re[p-1] |
s523227252 | p01269 | u855199458 | 1530075814 | Python | Python3 | py | Runtime Error | 0 | 0 | 873 | # -*- coding: utf-8 -*-
from heapq import heappop, heappush
from collections import defaultdict
def inpl(): return list(map(int, input().split()))
N, M, L = inpl()
while N:
G = [[] for _ in range(N+1)]
for _ in range(M):
a, b, d, e = inpl()
G[a].append([b, d, e])
G[b].append([a, d, e])
Q = [[0, 0, 1]] # bandits, distance, where
visited = defaultdict(lambda : False)
visited[(0, 0, 1)] = True
while Q:
e, d, p = heappop(Q)
if p == N:
print(e)
break
for q, dd, de in G[p]:
if d + dd <= L and not visited[(e, d+dd, q)]:
heappush(Q, (e, d+dd, q))
visited[(e, d+dd, q)] = True
if not visited[(e+de, d, q)]:
heappush(Q, (e+de, d, q))
visited[(e+de, d, q)] = True
N, M, L = inpl()
|
s748965934 | p01270 | u269391636 | 1527487416 | Python | Python3 | py | Runtime Error | 0 | 0 | 1230 | while(True):
N = int(input())
if N == 0:
quit()
data = []
emp = [[0,10**9]]
for _____ in range(N):
tmp = input().split()
if tmp[0] == "W":
c,k = int(tmp[1]),int(tmp[2])
while(k):
if (emp[0][1]-emp[0][0]) > k:
data.append([c,[emp[0][0],emp[0][0]+k]])
emp[0] = [emp[0][0]+k,emp[0][1]]
print(emp)
break
elif (emp[0][1]-emp[0][0]) == k:
data.append([c,[emp[0][0],emp[0][0]+k]])
del(emp[0])
break
else:
data.append([c,emp[0]])
k -= (emp[0][1]-emp[0][0])
del(emp[0])
elif tmp[0] == "D":
for i in range(len(data)):
ifdata = [i[1] for i in data if i[0] == int(tmp[1])]
data = [i for i in data if i[0] != int(tmp[1])]
emp += ifdata
emp.sort()
else:
ans = -1
s = int(tmp[1])
for i in data:
if i[1][0]<=s<i[1][1]:
ans = i[0]
print(ans)
print()
|
s043623554 | p01270 | u269391636 | 1527487620 | Python | Python3 | py | Runtime Error | 0 | 0 | 1199 | while(True):
N = int(input())
if N == 0:
quit()
data = []
emp = [[0,10**9]]
for _____ in range(N):
tmp = input().split()
if tmp[0] == "W":
c,k = int(tmp[1]),int(tmp[2])
while(k):
if (emp[0][1]-emp[0][0]) > k:
data.append([c,[emp[0][0],emp[0][0]+k]])
emp[0] = [emp[0][0]+k,emp[0][1]]
break
elif (emp[0][1]-emp[0][0]) == k:
data.append([c,[emp[0][0],emp[0][0]+k]])
del(emp[0])
break
else:
data.append([c,emp[0]])
k -= (emp[0][1]-emp[0][0])
del(emp[0])
elif tmp[0] == "D":
for i in range(len(data)):
ifdata = [i[1] for i in data if i[0] == int(tmp[1])]
data = [i for i in data if i[0] != int(tmp[1])]
emp += ifdata
emp.sort()
else:
ans = -1
s = int(tmp[1])
for i in data:
if i[1][0]<=s<i[1][1]:
ans = i[0]
print(ans)
print()
|
s537791103 | p01270 | u269391636 | 1527490481 | Python | Python3 | py | Runtime Error | 0 | 0 | 1255 | while(True):
N = int(input())
if N == 0:
quit()
data = []
emp = [[0,2 * 10**9]]
for _____ in range(N):
tmp = input().split()
if tmp[0] == "W":
c,k = int(tmp[1]),int(tmp[2])
while(k):
if (emp[0][1]-emp[0][0]) > k:
data.append([c,[emp[0][0],emp[0][0]+k]])
emp[0] = [emp[0][0]+k,emp[0][1]]
break
elif (emp[0][1]-emp[0][0]) == k:
data.append([c,[emp[0][0],emp[0][0]+k]])
del(emp[0])
break
else:
data.append([c,emp[0]])
k -= (emp[0][1]-emp[0][0])
del(emp[0])
elif tmp[0] == "D":
for i in range(len(data)):
emp += [i[1] for i in data if i[0] == int(tmp[1])]
data = [i for i in data if i[0] != int(tmp[1])]
emp.sort()
else:
ans = True
s = int(tmp[1])
for i in data:
if i[1][0]<=s<i[1][1]:
print(i[0])
ans = False
break
if ans:
print(-1)
print()
|
s733787994 | p01270 | u269391636 | 1527491495 | Python | Python3 | py | Runtime Error | 0 | 0 | 1255 | while(True):
N = int(input())
if N == 0:
quit()
data = []
emp = [[0,2 * 10**9]]
for _____ in range(N):
tmp = input().split()
if tmp[0] == "W":
c,k = int(tmp[1]),int(tmp[2])
while(k):
if (emp[0][1]-emp[0][0]) > k:
data.append([c,[emp[0][0],emp[0][0]+k]])
emp[0] = [emp[0][0]+k,emp[0][1]]
break
elif (emp[0][1]-emp[0][0]) == k:
data.append([c,[emp[0][0],emp[0][0]+k]])
del(emp[0])
break
else:
data.append([c,emp[0]])
k -= (emp[0][1]-emp[0][0])
del(emp[0])
elif tmp[0] == "D":
for i in range(len(data)):
emp += [i[1] for i in data if i[0] == int(tmp[1])]
data = [i for i in data if i[0] != int(tmp[1])]
emp.sort()
else:
ans = True
s = int(tmp[1])
for i in data:
if i[1][0]<=s<i[1][1]:
print(i[0])
ans = False
break
if ans:
print(-1)
print()
|
s969097558 | p01271 | u633068244 | 1425051279 | Python | Python | py | Runtime Error | 19940 | 126692 | 1287 | dwh = zip([1,0,-1,0,],[0,1,0,-1])
while 1:
W,H = map(int,raw_input().split())
if W == 0: break
A,B = [],[]
for loop in xrange(H):
a,b = raw_input().split()
A.append(list(a))
B.append(list(b))
for h in xrange(H):
for w in xrange(W):
if A[h][w] == "L": wl ,hl = w,h
if B[h][w] == "R": wr ,hr = w,h
if A[h][w] == "%": wlg,hlg = w,h
if B[h][w] == "%": wrg,hrg = w,h
visited = [[[[False]*W for i in xrange(H)] for j in xrange(W)] for k in xrange(H)]
visited[hl][wl][hr][wr] = True
que = [[wl,hl,wr,hr]]
while que:
wl,hl,wr,hr = que.pop(0)
if (wl,hl) == (wlg,hlg) and (wr,hr) == (wrg,hrg):
print "Yes"
break
for dw,dh in dwh:
nwl,nhl = min(W-1,max(0,wl+dw)), min(H-1,max(0,hl+dh))
if A[nhl][nwl] == "#": nwl,nhl = wl,hl
nwr,nhr = min(W-1,max(0,wr-dw)), min(H-1,max(0,hr+dh))
if B[nhr][nwr] == "#": nwr,nhr = wr,hr
if not visited[nhl][nwl][nhr][nwr]:
if ((nwl,nhl) == (wlg,hlg)) + ((nwr,nhr) == (wrg,hrg)) == 1: continue
visited[nhl][nwl][nhr][nwr] = True
que.append([nwl,nhl,nwr,nhr])
else:
print "No" |
s170110765 | p01271 | u633068244 | 1425051380 | Python | Python | py | Runtime Error | 19940 | 127328 | 1327 | from collections import deque
dwh = zip([1,0,-1,0,],[0,1,0,-1])
while 1:
W,H = map(int,raw_input().split())
if W == 0: break
A,B = [],[]
for loop in xrange(H):
a,b = raw_input().split()
A.append(list(a))
B.append(list(b))
for h in xrange(H):
for w in xrange(W):
if A[h][w] == "L": wl ,hl = w,h
if B[h][w] == "R": wr ,hr = w,h
if A[h][w] == "%": wlg,hlg = w,h
if B[h][w] == "%": wrg,hrg = w,h
visited = [[[[False]*W for i in xrange(H)] for j in xrange(W)] for k in xrange(H)]
visited[hl][wl][hr][wr] = True
que = deque([[wl,hl,wr,hr]])
while que:
wl,hl,wr,hr = que.popleft()
if (wl,hl) == (wlg,hlg) and (wr,hr) == (wrg,hrg):
print "Yes"
break
for dw,dh in dwh:
nwl,nhl = min(W-1,max(0,wl+dw)), min(H-1,max(0,hl+dh))
if A[nhl][nwl] == "#": nwl,nhl = wl,hl
nwr,nhr = min(W-1,max(0,wr-dw)), min(H-1,max(0,hr+dh))
if B[nhr][nwr] == "#": nwr,nhr = wr,hr
if not visited[nhl][nwl][nhr][nwr]:
if ((nwl,nhl) == (wlg,hlg)) + ((nwr,nhr) == (wrg,hrg)) == 1: continue
visited[nhl][nwl][nhr][nwr] = True
que.append([nwl,nhl,nwr,nhr])
else:
print "No" |
s842155172 | p01271 | u685815919 | 1479106967 | Python | Python | py | Runtime Error | 40000 | 323072 | 1243 | from Queue import Queue
def isValid(W,H,x,y):
return 0<=x and x<H and 0<=y and y<W
def walking(L,R,start):
vec=[(1,0,1,0),(-1,0,-1,0),(0,1,0,-1),(0,-1,0,1)]
q=Queue()
searched={}
q.put(startPos)
searched[startPos]=True
while q.qsize()>0:
lx,ly,rx,ry=q.get()
for dlx,dly,drx,dry in vec:
if not isValid(W,H,lx+dlx,ly+dly): dlx,dly=(0,0)
if not isValid(W,H,rx+drx,ry+dry): drx,dry=(0,0)
if L[lx+dlx][ly+dly]=="#": dlx,dly=(0,0)
if R[rx+drx][ry+dry]=="#": drx,dry=(0,0)
newPos = (lx+dlx, ly+dly, rx+drx, ry+dry)
if newPos in searched: continue
if L[newPos[0]][newPos[1]]=="%" and R[newPos[2]][newPos[3]]=="%":
print "Yes"
return
elif not L[newPos[0]][newPos[1]]=="%" and not R[newPos[2]][newPos[3]]=="%":
q.put(newPos)
searched[newPos]=True
print "No"
while True:
W,H=map(int,raw_input().split())
if W==0: break
L=[]
R=[]
lx=-1
ly=-1
rx=-1
ry=-1
for _ in xrange(H):
l,r=raw_input().split()
L.append(l)
R.append(r)
for i in xrange(H):
for j in xrange(W):
if L[i][j] == "L":
lx=i
ly=j
if R[i][j] == "R":
rx=i
ry=j
startPos=(lx,ly,rx,ry)
walking(L,R,startPos) |
s484559449 | p01271 | u260980560 | 1482833675 | Python | Python | py | Runtime Error | 0 | 0 | 1439 | from collections import deque
dd = [(-1, 0), (0, -1), (1, 0), (0, 1)]
while 1:
w, h = map(int, raw_input().split())
if w==0:
break
M = [raw_input() for i in xrange(h)]
ML = [e[:w] for e in M]
MR = [e[w+1:] for e in M]
for i in xrange(h):
for j in xrange(w):
if MR[i][j] == 'R':
rx = j; ry = i
elif ML[i][j] == 'L':
lx = j; ly = i
dist = {(rx, ry, lx, ly)}
deq = deque()
deq.append((rx, ry, lx, ly))
ok = 0
while deq and not ok:
rx, ry, lx, ly = deq.popleft()
for dx, dy in dd:
n_rx = rx + dx
if not 0 <= n_rx < w: n_rx = rx
n_ry = ry + dy
if not 0 <= n_ry < h: n_ry = ry
rm = MR[n_ry][n_rx]
if rm == '#':
n_rx = rx; n_ry = ry
rm = '.'
n_lx = lx - dx
if not 0 <= n_lx < w: n_lx = lx
n_ly = ly + dy
if not 0 <= n_ly < h: n_ly = ly
lm = ML[n_ly][n_lx]
if lm == '#':
n_lx = lx; n_ly = ly
lm = '.'
if rm == '%' or lm == '%':
if rm == '%' and lm == '%':
ok = 1
continue
n_key = (n_rx, n_ry, n_lx, n_ly)
if n_key not in dist:
dist.add(n_key)
deq.append(n_key)
print "Yes"*ok or "No" |
s634796984 | p01271 | u260980560 | 1482833995 | Python | Python | py | Runtime Error | 40000 | 257904 | 1466 | from collections import deque
dd = [(-1, 0), (0, -1), (1, 0), (0, 1)]
while 1:
w, h = map(int, raw_input().split())
if w==0:
break
M = [raw_input() for i in xrange(h)]
ML = [e[:w] for e in M]
MR = [e[w+1:] for e in M]
rx = ry = lx = ly = None
for i in xrange(h):
for j in xrange(w):
if MR[i][j] == 'R':
rx = j; ry = i
if ML[i][j] == 'L':
lx = j; ly = i
dist = {(rx, ry, lx, ly)}
deq = deque()
deq.append((rx, ry, lx, ly))
ok = 0
while deq and not ok:
rx, ry, lx, ly = deq.popleft()
for dx, dy in dd:
n_rx = rx + dx
if not 0 <= n_rx < w: n_rx = rx
n_ry = ry + dy
if not 0 <= n_ry < h: n_ry = ry
rm = MR[n_ry][n_rx]
if rm == '#':
n_rx = rx; n_ry = ry
rm = '.'
n_lx = lx - dx
if not 0 <= n_lx < w: n_lx = lx
n_ly = ly + dy
if not 0 <= n_ly < h: n_ly = ly
lm = ML[n_ly][n_lx]
if lm == '#':
n_lx = lx; n_ly = ly
lm = '.'
if rm == '%' or lm == '%':
if rm == '%' and lm == '%':
ok = 1
continue
n_key = (n_rx, n_ry, n_lx, n_ly)
if n_key not in dist:
dist.add(n_key)
deq.append(n_key)
print "Yes"*ok or "No" |
s834415286 | p01271 | u260980560 | 1482835043 | Python | Python | py | Runtime Error | 40000 | 258072 | 1465 | from collections import deque
dd = [(-1, 0), (0, -1), (1, 0), (0, 1)]
deq = deque()
push = deq.append
pop = deq.popleft
clear = deq.clear
while 1:
w, h = map(int, raw_input().split())
if w==0:
break
M = [raw_input() for i in xrange(h)]
rx = ry = lx = ly = None
for i in xrange(h):
e = M[i]
for j in xrange(w):
if e[j+w+1] == 'R':
rx = j; ry = i
if e[j] == 'L':
lx = j; ly = i
dist = {(rx, ry, lx, ly)}
push((rx, ry, lx, ly))
ok = 0
while deq and not ok:
rx, ry, lx, ly = pop()
for dx, dy in dd:
n_rx = rx + dx
if not 0 <= n_rx < w: n_rx = rx
n_ry = ry + dy
if not 0 <= n_ry < h: n_ry = ry
rm = M[n_ry][n_rx+w+1]
if rm == '#':
n_rx = rx; n_ry = ry
rm = '.'
n_lx = lx - dx
if not 0 <= n_lx < w: n_lx = lx
n_ly = ly + dy
if not 0 <= n_ly < h: n_ly = ly
lm = M[n_ly][n_lx]
if lm == '#':
n_lx = lx; n_ly = ly
lm = '.'
if rm == '%' or lm == '%':
if rm == '%' and lm == '%':
ok = 1
continue
n_key = (n_rx, n_ry, n_lx, n_ly)
if n_key not in dist:
dist.add(n_key)
push(n_key)
clear()
print "Yes"*ok or "No" |
s139628687 | p01271 | u177389471 | 1502244722 | Python | Python3 | py | Runtime Error | 40000 | 147728 | 1269 | from collections import deque
while True:
w,h=map(int,input().split(" "))
def isrange(p):
return 0<=p[0] and p[0]<h and 0<=p[1] and p[1]<w
if w==0: break
rl=[[str()] for i in range(h)]
rr=[[str()] for i in range(h)]
for i in range(h):
rl[i],rr[i]=input().split(" ")
q = deque()
dp=[[[[False for i in range(w)] for ii in range(h)] for iii in range(w)] for iiii in range(h)]
for i in range(h):
for j in range(w):
if rl[i][j]=="L": ls=(i,j)
if rr[i][j]=="R": rs=(i,j)
if rl[i][j]=="%": gl=(i,j)
if rr[i][j]=="%": gr=(i,j)
q.append((ls,rs))
dp[ls[0]][ls[1]][rs[0]][rs[1]]=True
dw=(-1,0,1,0)
dh=(0,1,0,-1)
while q:
val=q.pop()
lp=val[0]
rp=val[1]
for i in range(4):
lnp=(lp[0]+dh[i],lp[1]+dw[i])
rnp=(rp[0]+dh[i],rp[1]-dw[i])
if (not isrange(lnp)) or rl[lnp[0]][lnp[1]]=="#" : lnp=lp
if (not isrange(rnp)) or rr[rnp[0]][rnp[1]]=="#" : rnp=rp
if dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]: continue
dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]=True
q.append((lnp,rnp))
if dp[gl[0]][gl[1]][gr[0]][gr[1]] : print("Yes")
else : print("No") |
s356978382 | p01271 | u177389471 | 1502244831 | Python | Python3 | py | Runtime Error | 40000 | 95276 | 1328 | from collections import deque
while True:
w,h=map(int,input().split(" "))
def isrange(p):
return 0<=p[0] and p[0]<h and 0<=p[1] and p[1]<w
if w==0: break
rl=[[str()] for i in range(h)]
rr=[[str()] for i in range(h)]
for i in range(h):
rl[i],rr[i]=input().split(" ")
q = deque()
dp=[[[[False for i in range(w)] for ii in range(h)] for iii in range(w)] for iiii in range(h)]
for i in range(h):
for j in range(w):
if rl[i][j]=="L": ls=(i,j)
if rr[i][j]=="R": rs=(i,j)
if rl[i][j]=="%": gl=(i,j)
if rr[i][j]=="%": gr=(i,j)
q.append((ls,rs))
dp[ls[0]][ls[1]][rs[0]][rs[1]]=True
dw=(-1,0,1,0)
dh=(0,1,0,-1)
while q:
val=q.pop()
lp=val[0]
rp=val[1]
for i in range(4):
lnp=(lp[0]+dh[i],lp[1]+dw[i])
rnp=(rp[0]+dh[i],rp[1]-dw[i])
if (not isrange(lnp)) or rl[lnp[0]][lnp[1]]=="#" : lnp=lp
if (not isrange(rnp)) or rr[rnp[0]][rnp[1]]=="#" : rnp=rp
if dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]: continue
dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]=True
q.append((lnp,rnp))
if dp[gl[0]][gl[1]][gr[0]][gr[1]] : print("Yes")
else : print("No")
dp.clear()
q.clear()
rl.clear()
rr.clear() |
s266158602 | p01271 | u177389471 | 1502245084 | Python | Python3 | py | Runtime Error | 40000 | 92184 | 1384 | from collections import deque
while True:
w,h=map(int,input().split(" "))
def isrange(p):
return 0<=p[0] and p[0]<h and 0<=p[1] and p[1]<w
if w==0: break
rl=[[str()] for i in range(h)]
rr=[[str()] for i in range(h)]
for i in range(h):
rl[i],rr[i]=input().split(" ")
q = deque()
dp=[[[[False for i in range(w)] for ii in range(h)] for iii in range(w)] for iiii in range(h)]
for i in range(h):
for j in range(w):
if rl[i][j]=="L": ls=(i,j)
if rr[i][j]=="R": rs=(i,j)
if rl[i][j]=="%": gl=(i,j)
if rr[i][j]=="%": gr=(i,j)
q.append((ls,rs))
dp[ls[0]][ls[1]][rs[0]][rs[1]]=True
dw=(-1,0,1,0)
dh=(0,1,0,-1)
cnt=0
while q:
if cnt>int(1e7): break
cnt+=1
val=q.pop()
lp=val[0]
rp=val[1]
for i in range(4):
lnp=(lp[0]+dh[i],lp[1]+dw[i])
rnp=(rp[0]+dh[i],rp[1]-dw[i])
if (not isrange(lnp)) or rl[lnp[0]][lnp[1]]=="#" : lnp=lp
if (not isrange(rnp)) or rr[rnp[0]][rnp[1]]=="#" : rnp=rp
if dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]: continue
dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]=True
q.append((lnp,rnp))
if dp[gl[0]][gl[1]][gr[0]][gr[1]] : print("Yes")
else : print("No")
dp.clear()
q.clear()
rl.clear()
rr.clear() |
s051706410 | p01271 | u177389471 | 1502245350 | Python | Python3 | py | Runtime Error | 40000 | 92048 | 1384 | from collections import deque
while True:
w,h=map(int,input().split(" "))
def isrange(p):
return 0<=p[0] and p[0]<h and 0<=p[1] and p[1]<w
if w==0: break
rl=[[str()] for i in range(h)]
rr=[[str()] for i in range(h)]
for i in range(h):
rl[i],rr[i]=input().split(" ")
q = deque()
dp=[[[[False for i in range(w)] for ii in range(h)] for iii in range(w)] for iiii in range(h)]
for i in range(h):
for j in range(w):
if rl[i][j]=="L": ls=(i,j)
if rr[i][j]=="R": rs=(i,j)
if rl[i][j]=="%": gl=(i,j)
if rr[i][j]=="%": gr=(i,j)
q.append((ls,rs))
dp[ls[0]][ls[1]][rs[0]][rs[1]]=True
dw=(-1,0,1,0)
dh=(0,1,0,-1)
cnt=0
while q:
if cnt>int(1e7): break
cnt+=1
val=q.pop()
lp=val[0]
rp=val[1]
for i in range(4):
lnp=(lp[0]+dh[i],lp[1]+dw[i])
rnp=(rp[0]+dh[i],rp[1]-dw[i])
if (not isrange(lnp)) or rl[lnp[0]][lnp[1]]=="#" : lnp=lp
if (not isrange(rnp)) or rr[rnp[0]][rnp[1]]=="#" : rnp=rp
if dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]: continue
dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]=True
q.append((lnp,rnp))
if dp[gl[0]][gl[1]][gr[0]][gr[1]] : print("Yes")
else : print("No")
dp.clear()
q.clear()
rl.clear()
rr.clear() |
s491683458 | p01271 | u177389471 | 1502245361 | Python | Python | py | Runtime Error | 0 | 0 | 1384 | from collections import deque
while True:
w,h=map(int,input().split(" "))
def isrange(p):
return 0<=p[0] and p[0]<h and 0<=p[1] and p[1]<w
if w==0: break
rl=[[str()] for i in range(h)]
rr=[[str()] for i in range(h)]
for i in range(h):
rl[i],rr[i]=input().split(" ")
q = deque()
dp=[[[[False for i in range(w)] for ii in range(h)] for iii in range(w)] for iiii in range(h)]
for i in range(h):
for j in range(w):
if rl[i][j]=="L": ls=(i,j)
if rr[i][j]=="R": rs=(i,j)
if rl[i][j]=="%": gl=(i,j)
if rr[i][j]=="%": gr=(i,j)
q.append((ls,rs))
dp[ls[0]][ls[1]][rs[0]][rs[1]]=True
dw=(-1,0,1,0)
dh=(0,1,0,-1)
cnt=0
while q:
if cnt>int(1e7): break
cnt+=1
val=q.pop()
lp=val[0]
rp=val[1]
for i in range(4):
lnp=(lp[0]+dh[i],lp[1]+dw[i])
rnp=(rp[0]+dh[i],rp[1]-dw[i])
if (not isrange(lnp)) or rl[lnp[0]][lnp[1]]=="#" : lnp=lp
if (not isrange(rnp)) or rr[rnp[0]][rnp[1]]=="#" : rnp=rp
if dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]: continue
dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]=True
q.append((lnp,rnp))
if dp[gl[0]][gl[1]][gr[0]][gr[1]] : print("Yes")
else : print("No")
dp.clear()
q.clear()
rl.clear()
rr.clear() |
s930745655 | p01271 | u177389471 | 1502246297 | Python | Python3 | py | Runtime Error | 0 | 0 | 1331 | import numpy as np
from collections import deque
while True:
w,h=map(int,input().split(" "))
def isrange(p):
return 0<=p[0] and p[0]<h and 0<=p[1] and p[1]<w
if w==0: break
rl=[[str()] for i in range(h)]
rr=[[str()] for i in range(h)]
for i in range(h):
rl[i],rr[i]=input().split(" ")
q = deque()
dp=np.array((h,w,h,w))
for i in range(h):
for j in range(w):
if rl[i][j]=="L": ls=(i,j)
if rr[i][j]=="R": rs=(i,j)
if rl[i][j]=="%": gl=(i,j)
if rr[i][j]=="%": gr=(i,j)
q.append((ls,rs))
dp[ls[0]][ls[1]][rs[0]][rs[1]]=True
dw=(-1,0,1,0)
dh=(0,1,0,-1)
cnt=0
while q:
if cnt>int(1e7): break
cnt+=1
val=q.pop()
lp=val[0]
rp=val[1]
for i in range(4):
lnp=(lp[0]+dh[i],lp[1]+dw[i])
rnp=(rp[0]+dh[i],rp[1]-dw[i])
if (not isrange(lnp)) or rl[lnp[0]][lnp[1]]=="#" : lnp=lp
if (not isrange(rnp)) or rr[rnp[0]][rnp[1]]=="#" : rnp=rp
if dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]: continue
dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]=True
q.append((lnp,rnp))
if dp[gl[0]][gl[1]][gr[0]][gr[1]] : print("Yes")
else : print("No")
dp.clear()
q.clear()
rl.clear()
rr.clear() |
s718003659 | p01271 | u177389471 | 1502247429 | Python | Python3 | py | Runtime Error | 0 | 0 | 12 | import numpy |
s059212926 | p01271 | u177389471 | 1502247471 | Python | Python3 | py | Runtime Error | 0 | 0 | 29 | import numpy as np
print(" ") |
s613404466 | p01271 | u177389471 | 1502248238 | Python | Python3 | py | Runtime Error | 0 | 0 | 1434 | import numpy as np
from collections import deque
while True:
w,h=map(int,input().split(" "))
def isrange(p):
return 0<=p[0] and p[0]<h and 0<=p[1] and p[1]<w
if w==0: break
rl=[[str()] for i in range(h)]
rr=[[str()] for i in range(h)]
for i in range(h):
rl[i],rr[i]=input().split(" ")
q = deque()
dp=np.ndarray((h,w,h,w))
for i in range(h):
for j in range(w):
for ii in range(h):
for jj in range(w):
dp[i][j][ii][jj]=True
for i in range(h):
for j in range(w):
if rl[i][j]=="L": ls=(i,j)
if rr[i][j]=="R": rs=(i,j)
if rl[i][j]=="%": gl=(i,j)
if rr[i][j]=="%": gr=(i,j)
q.append((ls,rs))
dp[ls[0]][ls[1]][rs[0]][rs[1]]=True
dw=(-1,0,1,0)
dh=(0,1,0,-1)
cnt=0
while q:
if cnt>int(1e7): break
cnt+=1
val=q.pop()
lp=val[0]
rp=val[1]
for i in range(4):
lnp=(lp[0]+dh[i],lp[1]+dw[i])
rnp=(rp[0]+dh[i],rp[1]-dw[i])
if (not isrange(lnp)) or rl[lnp[0]][lnp[1]]=="#" : lnp=lp
if (not isrange(rnp)) or rr[rnp[0]][rnp[1]]=="#" : rnp=rp
if dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]: continue
dp[lnp[0]][lnp[1]][rnp[0]][rnp[1]]=True
q.append((lnp,rnp))
if dp[gl[0]][gl[1]][gr[0]][gr[1]] : print("Yes")
else : print("No") |
s523371001 | p01271 | u509278866 | 1529657487 | Python | Python3 | py | Runtime Error | 0 | 0 | 2694 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
w,h = LI()
if w == 0:
break
la = ["#" * (w+2)]
ra = ["#" * (w+2)]
for _ in range(h):
l,r = LS()
la.append("#{}#".format(l))
ra.append("#{}#".format(r))
la.append("#" * (w+2))
ra.append("#" * (w+2))
ls = None
rs = None
for i in range(1,h+2):
for j in range(1,w+2):
if la[i][j] == 'L':
ls = (i,j)
if ra[i][j] == 'R':
rs = (i,j)
def search(s):
d = collections.defaultdict(lambda: inf)
d[s] = 0
q = []
heapq.heappush(q, (0, s))
v = collections.defaultdict(bool)
while len(q):
k, u = heapq.heappop(q)
if v[u]:
continue
v[u] = True
for di, dj in dd:
li = u[0][0] + di
lj = u[0][1] + dj
if la[li][lj] == "#":
li -= di
lj -= dj
ri = u[1][0] + di
rj = u[1][1] - dj
if ra[ri][rj] == "#":
ri -= di
rj += dj
if la[li][lj] == '%' and ra[ri][rj] == '%':
return True
if la[li][lj] == '%':
continue
if ra[ri][rj] == '%':
continue
uv = ((li,lj), (ri,rj))
if v[uv]:
continue
vd = k + 1
if d[uv] > vd:
d[uv] = vd
heapq.heappush(q, (vd, uv))
return False
if search((ls,rs)):
rr.append('Yes')
else:
rr.append('No')
return '\n'.join(map(str,rr))
print(main())
|
s423742065 | p01271 | u509278866 | 1529666379 | Python | Python3 | py | Runtime Error | 0 | 0 | 3186 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
w,h = LI()
if w == 0:
break
print(w,h)
la = ["#" * (w+2)]
ra = ["#" * (w+2)]
for _ in range(h):
l,r = LS()
la.append("#{}#".format(l))
ra.append("#{}#".format(r))
la.append("#" * (w+2))
ra.append("#" * (w+2))
ls = None
rs = None
lp = None
rp = None
for i in range(1,h+2):
for j in range(1,w+2):
if la[i][j] == 'L':
ls = (i,j)
elif la[i][j] == '%':
lp = (i,j)
if ra[i][j] == 'R':
rs = (i,j)
elif ra[i][j] == '%':
rp = (i,j)
lla = []
rra = []
for i in range(h+2):
tl = []
tr = []
for j in range(w+2):
if la[i][j] == '#':
tl.append(None)
else:
tl.append(1)
if ra[i][j] == '#':
tr.append(None)
else:
tr.append(1)
lla.append(tl)
rra.append(tr)
def search(s):
q = []
q.append(s)
v = set()
v.add(s)
qi = 0
while len(q) > qi:
u = q[qi]
qi += 1
for di, dj in dd:
li = u[0][0]
lj = u[0][1]
if not lla[li+di][lj+dj] is None:
li += di
lj += dj
ri = u[1][0]
rj = u[1][1]
if not rra[ri+di][rj-dj] is None:
ri += di
rj -= dj
uv = ((li,lj), (ri,rj))
if uv in v:
continue
v.add(uv)
if (li,lj) == lp and (ri,rj) == rp:
# print(len(q))
return True
if (li,lj) == lp:
continue
if (ri,rj) == rp:
continue
q.append(uv)
# print(len(q))
return False
if search((ls,rs)):
rr.append('Yes')
else:
rr.append('No')
# print(rr[-1])
return '\n'.join(map(str,rr))
print(main())
|
s477416075 | p01271 | u509278866 | 1529714672 | Python | Python3 | py | Runtime Error | 0 | 0 | 2984 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
w,h = LI()
if w == 0:
break
# print(w,h)
W = w+2
dd = [(0,-1),(W,0),(0,1),(-W,0)]
la = ["#" * W]
ra = ["#" * W]
for _ in range(h):
l,r = LS()
la.append("#{}#".format(l))
ra.append("#{}#".format(r))
la.append("#" * W)
ra.append("#" * W)
ls = None
rs = None
lp = None
rp = None
for i in range(1,h+2):
for j in range(1,w+2):
if la[i][j] == 'L':
ls = i*W+j
elif la[i][j] == '%':
lp = i*W+j
if ra[i][j] == 'R':
rs = i*W+j
elif ra[i][j] == '%':
rp = i*W+j
lla = []
rra = []
for i in range(h+2):
for j in range(w+2):
if la[i][j] == '#':
lla.append(None)
else:
lla.append(1)
if ra[i][j] == '#':
rra.append(None)
else:
rra.append(1)
def search(s):
q = []
q.append(s)
v = set()
v.add(s)
qi = 0
while len(q) > qi:
u = q[qi]
qi += 1
for di, dj in dd:
lij = u[0]
if not lla[lij+di+dj] is None:
lij += di + dj
rij = u[1]
if not rra[rij+di-dj] is None:
rij += di - dj
uv = (lij,rij)
if uv in v:
continue
v.add(uv)
if lij == lp and rij == rp:
# print(len(q))
return True
if lij == lp:
continue
if rij == rp:
continue
q.append(uv)
# print(len(q))
return False
if search((ls,rs)):
rr.append('Yes')
else:
rr.append('No')
# print(rr[-1])
return '\n'.join(map(str,rr))
print(main())
|
s879807290 | p01271 | u352394527 | 1529775370 | Python | Python3 | py | Runtime Error | 0 | 0 | 1465 | from collections import deque
direct_l = ((-1, 0), (1, 0), (0, 1), (0, -1))
direct_r = ((1, 0), (-1, 0), (0, 1), (0, -1))
directs = tuple(zip(direct_l, direct_r))
def search(start_l, start_r, mp_l, mp_r):
que = deque()
que.append((start_l, start_r))
dic = {}
dic[(start_l, start_r)] = True
while que:
pl, pr = que.popleft()
lx, ly = pl
rx, ry = pr
for ld, rd in directs:
ldx, ldy = ld
rdx, rdy = rd
lnx, lny = (lx + ldx, ly + ldy) if mp_l[ly + ldy][lx + ldx] != "#" else (lx, ly)
rnx, rny = (rx + rdx, ry + rdy) if mp_r[ry + rdy][rx + rdx] != "#" else (rx, ry)
if not ((lnx, lny), (rnx, rny)) in dic:
dic[((lnx, lny), (rnx, rny))] = True
if mp_l[lny][lnx] == "%" and mp_r[rny][rnx] == "%":
print("Yes")
return
if mp_l[lny][lnx] != "%" and mp_r[rny][rnx] != "%":
que.append(((lnx, lny), (rnx, rny)))
else:
print("No")
return
while True:
w, h = map(int, input().split())
if w == 0:
break
mp_l = ["#" * (w + 2)]
mp_r = ["#" * (w + 2)]
for _ in range(h):
l, r = input().split()
l = "#" + l + "#"
r = "#" + r + "#"
mp_l.append(l)
mp_r.append(r)
mp_l.append("#" * (w + 2))
mp_r.append("#" * (w + 2))
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp_l[y][x] == "L":
start_l = (x, y)
if mp_r[y][x] == "R":
start_r = (x, y)
search(start_l, start_r, mp_l, mp_r)
|
s750824480 | p01271 | u352394527 | 1529776016 | Python | Python3 | py | Runtime Error | 0 | 0 | 1598 | from collections import deque
direct_l = ((-1, 0), (1, 0), (0, 1), (0, -1))
direct_r = ((1, 0), (-1, 0), (0, 1), (0, -1))
directs = tuple(zip(direct_l, direct_r))
def search(start_l, start_r, mp_l, mp_r, dic):
que = deque()
que.append((start_l, start_r))
dic[start_l[0]][start_l[1]][start_r[0]][start_r[1]] = True
while que:
pl, pr = que.popleft()
lx, ly = pl
rx, ry = pr
for ld, rd in directs:
ldx, ldy = ld
rdx, rdy = rd
lnx, lny = (lx + ldx, ly + ldy) if mp_l[ly + ldy][lx + ldx] != "#" else (lx, ly)
rnx, rny = (rx + rdx, ry + rdy) if mp_r[ry + rdy][rx + rdx] != "#" else (rx, ry)
if not dic[lnx][lny][rnx][rny]:
dic[lnx][lny][rnx][rny] = True
if mp_l[lny][lnx] == "%" and mp_r[rny][rnx] == "%":
print("Yes")
return
if mp_l[lny][lnx] != "%" and mp_r[rny][rnx] != "%":
que.append(((lnx, lny), (rnx, rny)))
else:
print("No")
return
while True:
w, h = map(int, input().split())
if w == 0:
break
mp_l = ["#" * (w + 2)]
mp_r = ["#" * (w + 2)]
for _ in range(h):
l, r = input().split()
l = "#" + l + "#"
r = "#" + r + "#"
mp_l.append(l)
mp_r.append(r)
mp_l.append("#" * (w + 2))
mp_r.append("#" * (w + 2))
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp_l[y][x] == "L":
start_l = (x, y)
if mp_r[y][x] == "R":
start_r = (x, y)
#dic[lx][ly][rx][ry]
dic = [[[[False] * (h + 2) for _ in range(w + 2)] for _ in range(h + 2)] for _ in range(w + 2)]
search(start_l, start_r, mp_l, mp_r, dic)
|
s197609775 | p01271 | u352394527 | 1529776569 | Python | Python3 | py | Runtime Error | 0 | 0 | 1569 | from collections import deque
directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1))
def search(start_l, start_r, mp_l, mp_r, dic):
que = deque()
que.append((start_l[0], start_l[1], start_r[0], start_r[1]))
dic[start_l[0]][start_l[1]][start_r[0]][start_r[1]] = True
while que:
lx, ly, rx, ry = que.popleft()
for ldx, ldy, rdx, rdy in directs:
lnx, lny = (lx + ldx, ly + ldy) if mp_l[ly + ldy][lx + ldx] != "#" else (lx, ly)
rnx, rny = (rx + rdx, ry + rdy) if mp_r[ry + rdy][rx + rdx] != "#" else (rx, ry)
if not dic[lnx][lny][rnx][rny]:
dic[lnx][lny][rnx][rny] = True
lsym, rsym = mp_l[lny][lnx], mp_r[rny][rnx]
if lsym == "%" and rsym == "%":
print("Yes")
return
if lsym != "%" and rsym != "%":
que.append(((lnx, lny, rnx, rny)))
else:
print("No")
return
def main():
while True:
w, h = map(int, input().split())
if w == 0:
break
mp_l = ["#" * (w + 2)]
mp_r = ["#" * (w + 2)]
for _ in range(h):
l, r = input().split()
l = "#" + l + "#"
r = "#" + r + "#"
mp_l.append(l)
mp_r.append(r)
mp_l.append("#" * (w + 2))
mp_r.append("#" * (w + 2))
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp_l[y][x] == "L":
start_l = (x, y)
if mp_r[y][x] == "R":
start_r = (x, y)
dic = [[[[False] * (h + 2) for _ in range(w + 2)] for _ in range(h + 2)] for _ in range(w + 2)]
search(start_l, start_r, mp_l, mp_r, dic)
main()
|
s926631948 | p01271 | u352394527 | 1529777691 | Python | Python3 | py | Runtime Error | 0 | 0 | 1625 | from collections import deque, defaultdict
def main():
directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1))
while True:
w, h = map(int, input().split())
if w == 0:
break
mp_l = ["#" * (w + 2)]
mp_r = ["#" * (w + 2)]
for _ in range(h):
l, r = input().split()
l = "#" + l + "#"
r = "#" + r + "#"
mp_l.append(l)
mp_r.append(r)
mp_l.append("#" * (w + 2))
mp_r.append("#" * (w + 2))
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp_l[y][x] == "L":
start_l = (x, y)
if mp_r[y][x] == "R":
start_r = (x, y)
dic = [[[[False] * (h + 2) for _ in range(w + 2)] for _ in range(h + 2)] for _ in range(w + 2)]
def search():
que = deque()
app = que.append
pop = que.popleft
app((start_l[0], start_l[1], start_r[0], start_r[1]))
dic[start_l[0]][start_l[1]][start_r[0]][start_r[1]] = True
while que:
lx, ly, rx, ry = pop()
for ldx, ldy, rdx, rdy in directs:
lnx, lny = (lx + ldx, ly + ldy) if mp_l[ly + ldy][lx + ldx] != "#" else (lx, ly)
rnx, rny = (rx + rdx, ry + rdy) if mp_r[ry + rdy][rx + rdx] != "#" else (rx, ry)
if not dic[lnx][lny][rnx][rny]:
dic[lnx][lny][rnx][rny] = True
lsym, rsym = mp_l[lny][lnx], mp_r[rny][rnx]
if lsym == "%" and rsym == "%":
print("Yes")
return
if lsym != "%" and rsym != "%":
app(((lnx, lny, rnx, rny)))
else:
print("No")
return
search()
main()
|
s128593013 | p01271 | u352394527 | 1529778274 | Python | Python3 | py | Runtime Error | 0 | 0 | 1895 | from collections import deque, defaultdict
def main():
directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1))
while True:
w, h = map(int, input().split())
if w == 0:
break
mp_l = ["#" * (w + 2)]
mp_r = ["#" * (w + 2)]
for _ in range(h):
l, r = input().split()
l = "#" + l + "#"
r = "#" + r + "#"
mp_l.append(l)
mp_r.append(r)
mp_l.append("#" * (w + 2))
mp_r.append("#" * (w + 2))
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp_l[y][x] == "L":
start_l = (x, y)
if mp_r[y][x] == "R":
start_r = (x, y)
dic = [[[[False] * (h + 2) for _ in range(w + 2)] for _ in range(h + 2)] for _ in range(w + 2)]
def search():
que = deque()
app = que.append
pop = que.popleft
app((start_l[0], start_l[1], start_r[0], start_r[1]))
dic[start_l[0]][start_l[1]][start_r[0]][start_r[1]] = True
while que:
lx, ly, rx, ry = pop()
for ldx, ldy, rdx, rdy in directs:
if mp_l[ly + ldy][lx + ldx] != "#":
lnx, lny = lx + ldx, ly + ldy
else:
lnx, lny = lx, ly
if mp_r[ry + rdy][rx + rdx] != "#":
rnx, rny = rx + rdx, ry + rdy
else:
rnx, rny = rx, ry
#lnx, lny = (lx + ldx, ly + ldy) if mp_l[ly + ldy][lx + ldx] != "#" else (lx, ly)
#rnx, rny = (rx + rdx, ry + rdy) if mp_r[ry + rdy][rx + rdx] != "#" else (rx, ry)
if not dic[lnx][lny][rnx][rny]:
dic[lnx][lny][rnx][rny] = True
lsym, rsym = mp_l[lny][lnx], mp_r[rny][rnx]
if lsym == "%" and rsym == "%":
print("Yes")
return
if lsym != "%" and rsym != "%":
app(((lnx, lny, rnx, rny)))
else:
print("No")
return
search()
main()
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.