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
s617167660
p01144
u947762778
1508049434
Python
Python3
py
Runtime Error
40000
9364
437
while True: n, m = map(int, input().split()) dpList = [] if n + m < 1: break for i in range(n): row = list(map(int,input().split())) dpList.append(row) dpList = sorted(dpList, key = lambda x:x[1], reverse = True) num = 0 for i in range(n): if m >= dpList[i][0]: m -= dpList[i][0] else: num += (dpList[i][0] - m) * dpList[i][1] print(num)
s352754660
p01144
u947762778
1508049535
Python
Python3
py
Runtime Error
40000
9276
442
while True: n, m = map(int, input().split()) dpList = [] if (n,m) == (0,0): break for i in range(n): row = list(map(int,input().split())) dpList.append(row) dpList = sorted(dpList, key = lambda x:x[1], reverse = True) num = 0 for i in range(n): if m >= dpList[i][0]: m -= dpList[i][0] else: num += (dpList[i][0] - m) * dpList[i][1] print(num)
s134565221
p01144
u797673668
1510312588
Python
Python3
py
Runtime Error
0
0
347
while True: n, m = map(int, input().split()) if n == 0: break risks = [(p, d) for d, p in (map(int, input().split()) for _ in range(n))] risks.sort() while m: p, d = risks.pop() if d >= m: remain = p * (d - m) break m -= d print(remain + sum(p * d for p, d in risks))
s638291744
p01144
u797673668
1510312634
Python
Python3
py
Runtime Error
0
0
362
while True: n, m = map(int, input().split()) if n == 0: break risks = [(p, d) for d, p in (map(int, input().split()) for _ in range(n))] risks.sort() remain = 0 while m: p, d = risks.pop() if d >= m: remain = p * (d - m) break m -= d print(remain + sum(p * d for p, d in risks))
s216161886
p01144
u624914682
1524481364
Python
Python3
py
Runtime Error
0
0
755
# coding: utf-8 n,m=map(int,input().split()) while n!=0: d=[] p=[] for i in range(n): d_i,p_i=map(int,input().split()) d.append(d_i) p.append((p_i,i)) #タプルでインデックス情報を付加 #単位長さあたりの期待値で降順ソート p.sort(key=lambda x:-x[0]) #警備がいない場合の期待値を求める hazard=0 for i in range(n): hazard+=d[i]*p[i][0] for i in range(n): rest=d[p[i][1]] while rest!=0: if m==0: break m-=1 rest-=1 hazard-=p[i][0] else: continue break print(hazard) n,m=map(int,input().split())
s272907338
p01144
u624914682
1524481395
Python
Python3
py
Runtime Error
0
0
755
# coding: utf-8 n,m=map(int,input().split()) while n!=0: d=[] p=[] for i in range(n): d_i,p_i=map(int,input().split()) d.append(d_i) p.append((p_i,i)) #タプルでインデックス情報を付加 #単位長さあたりの期待値で降順ソート p.sort(key=lambda x:-x[0]) #警備がいない場合の期待値を求める hazard=0 for i in range(n): hazard+=d[i]*p[i][0] for i in range(n): rest=d[p[i][1]] while rest!=0: if m==0: break m-=1 rest-=1 hazard-=p[i][0] else: continue break print(hazard) n,m=map(int,input().split())
s405606143
p01144
u089116225
1524489354
Python
Python3
py
Runtime Error
0
0
464
while True: n, m = map(int, input().split()) if n == 0: break else: s = 0 l = [] for _ in range(n): d, p = map(int, input().split()) s += d * p l.append((p,d)) l.sort() while m > 0: a, b = l.pop() if m >= b: s -= a * b m -= b else: s -= a * m m = 0 print(s)
s299687517
p01144
u089116225
1524489417
Python
Python3
py
Runtime Error
0
0
464
while True: n, m = map(int, input().split()) if n == 0: break else: s = 0 l = [] for _ in range(n): d, p = map(int, input().split()) s += d * p l.append((p,d)) l.sort() while m > 0: a, b = l.pop() if m >= b: s -= a * b m -= b else: s -= a * m m = 0 print(s)
s116674861
p01144
u209989098
1528953466
Python
Python3
py
Runtime Error
0
0
460
da = list(map(int,input().split())) k = [[0]*2]*10000 i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = map(int,input().split()) su += k[i][0] * k[i][1] sorted(k) while da[1] != 0: if da[1] > k[j][0]: su -= k[j][0]* k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 j += 1 print(su) da = list(map(int,input().split())) k = [[0]*2]*10000
s227430186
p01144
u209989098
1528954990
Python
Python3
py
Runtime Error
0
0
545
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,reverse = True) while da[1] != 0: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 j += 1 print(su) da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)]
s206993225
p01144
u209989098
1528955190
Python
Python3
py
Runtime Error
0
0
545
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,reverse = True) while da[1] != 0: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 j += 1 print(su) da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)]
s735878234
p01144
u209989098
1528957213
Python
Python3
py
Runtime Error
0
0
605
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 j += 1 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10000)]
s419092644
p01144
u209989098
1528957908
Python
Python3
py
Runtime Error
0
0
545
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,reverse = True) while da[1] != 0: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 j += 1 print(su) da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)]
s554609111
p01144
u209989098
1528958884
Python
Python3
py
Runtime Error
0
0
595
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s960722853
p01144
u209989098
1528959368
Python
Python3
py
Runtime Error
0
0
624
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 if j == i: break else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s988370999
p01144
u209989098
1528959798
Python
Python3
py
Runtime Error
0
0
631
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0 or j != i + 1: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif da[1] < k[j][0]: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s434598010
p01144
u209989098
1528959862
Python
Python3
py
Runtime Error
0
0
626
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0 or j != i: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif da[1] < k[j][0]: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s018804062
p01144
u209989098
1528960019
Python
Python3
py
Runtime Error
0
0
630
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0 or j != i + 1: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif da[1] < k[j][0]: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s897996990
p01144
u209989098
1528960374
Python
Python3
py
Runtime Error
0
0
627
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0 or j != i: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif da[1] < k[j][0]: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s797355250
p01144
u209989098
1528968331
Python
Python3
py
Runtime Error
0
0
625
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] > 0 and j != i + 1: if da[1] >= k[j][0] and j != i + 1b su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s121492726
p01144
u209989098
1528968360
Python
Python3
py
Runtime Error
0
0
624
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] > 0 and j != i + 1: if da[1] >= k[j][0] and j != i + 1 su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s196241213
p01144
u209989098
1528968429
Python
Python3
py
Runtime Error
0
0
624
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] > 0 and j != i + 1: if da[1] >= k[j][0] and j != i + 1 su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s509375479
p01144
u209989098
1528968478
Python
Python3
py
Runtime Error
0
0
622
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = map(int,input().split()) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] > 0 and j != i + 1: if da[1] >= k[j][0] and j != i + 1 su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 else: su -= da[1] * k[j - 1][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s285420991
p01144
u209989098
1528968580
Python
Python3
py
Runtime Error
0
0
650
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = map(int,input().split()) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] > 0 and j != i + 1: if da[1] >= k[j][0] and j != i + 1 su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif j == i + 1: da[1] = 0 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s687632608
p01144
u209989098
1528968614
Python
Python3
py
Runtime Error
0
0
646
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = map(int,input().split()) su += k[i][0] * k[i][1] sorted(k,key = lambda x: x[1],reverse = True) while da[1] > 0 and j != i + 1: if da[1] >= k[j][0] and j != i su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif j == i + 1: da[1] = 0 else: su -= da[1] * k[j][1] da[1] = 0 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s347957582
p01144
u209989098
1528970943
Python
Python3
py
Runtime Error
0
0
722
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = map(int,input().split()) su += k[i][0] * k[i][1] k = sorted(k,key = lambda x:x[1]reverse = True) while da[1] != 0 and j != i + 1: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif da[1] < k[j][0] and da[1] > 0: su -= da[1] * k[j][1] da[1] = 0 j += 1 print(su) da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)]
s009396951
p01144
u209989098
1528971073
Python
Python3
py
Runtime Error
0
0
714
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = map(int,input().split()) su += k[i][0] * k[i][1] k = sorted(k,key = lambda x:x[1]reverse = True) while da[1] != 0 and j != i: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif da[1] < k[j][0] and da[1] > 0: su -= da[1] * k[j][1] da[1] = 0 j += 1 print(su) da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10000)]
s755761812
p01144
u209989098
1528971324
Python
Python3
py
Runtime Error
0
0
694
da = list(map(int,input().split())) k = [[0 for i in range(2)]for j in range(10001)] i = 0 su = 0 j = 0 while da[0] != 0 and da[1] != 0: i = 0 su = 0 j = 0 for i in range(da[0]): k[i][0],k[i][1] = list(map(int,input().split())) su += k[i][0] * k[i][1] k = sorted(k,key = lambda x: x[1],reverse = True) while da[1] != 0 and j != i+1: if da[1] >= k[j][0]: su -= k[j][0] * k[j][1] da[1] -= k[j][0] j += 1 elif da[1] > 0 and da[1] < k[j][0] and j != i + 1: su -= da[1] * k[j][1] da[1] = 0 else: j += 1 print(su) da = list(map(int,input().split())) if da[0] == 0 and da[1] == 0: break k = [[0 for i in range(2)]for j in range(10001)]
s927073791
p01145
u967850487
1365513363
Python
Python
py
Runtime Error
0
0
2945
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <map> using namespace std; const string boin = "aiueo"; const string shiin = "kstnhmyrwgzdbp"; const string cho = "aiu"; const string museiinshi = "ksthp"; bool isBoin(char c) { return boin.find(c) != string::npos; } bool isShiin(char c) { return shiin.find(c) != string::npos; } bool isCho(char c) { return cho.find(c) != string::npos; } bool isMuseiinshi(char c) { return museiinshi.find(c) != string::npos; } vector<pair<string,int> > parse(const string &s) { vector<pair<string,int> > v; string t = ""; for(int i = 0; i < s.size(); ++i) { t += s[i]; if(isBoin(s[i])) { int type = 0; if(t.size() == 1) { if(i >= 1 && isBoin(s[i-1]) && isCho(s[i])) { type = 6; } else { type = 1; } } else if(t.size() == 2) { type = 2; } else if(t.size() == 3) { type = 3; } v.push_back(make_pair(t, type)); t = ""; } else if(i+1 < s.size() && isShiin(s[i]) && s[i+1] == s[i] && s[i] != 'n' && s[i] != 'y' && s[i] != 'w') { v.push_back(make_pair(t, 4)); t = ""; } else if(s[i] == 'n' && (i+1 == s.size() || (i+1 < s.size() && isShiin(s[i+1]))) ) { v.push_back(make_pair(t, 5)); t = ""; } else if(s[i] == '\'') { v.push_back(make_pair(t, 5)); t = ""; } } return v; } char getBoin(const string &s) { return *s.rbegin(); } int main() { string s; while(cin >> s && s != "#") { vector<pair<string, int> > v = parse(s); int n = v.size(); bool isMusei[n]; fill(isMusei, isMusei+n, false); // i or u for(int i = 0; i < n; ++i) { if((v[i].second == 2 || v[i].second == 3) && isMuseiinshi(v[i].first[0]) && (getBoin(v[i].first) == 'i' || getBoin(v[i].first) == 'u') && (i+1 == n || isMuseiinshi(v[i+1].first[0]))) { isMusei[i] = true; } } // a or o for(int i = 0, cnt = 0; i+1 < n; ++i) { if((getBoin(v[i].first) == 'a' || getBoin(v[i].first) == 'o') && getBoin(v[i].first) == getBoin(v[i+1].first)); else continue; bool flag = true; for(int j = 0; j < 2; ++j) { const string &t = v[i+j].first; const int &type = v[i+j].second; if((type == 2 || type == 3) && isMuseiinshi(t[0])) ; else { flag = false; break; } } if(flag) { isMusei[i] = true; } } for(int i = 0, pre = 0; i < n; ++i) { if(isBoin(getBoin(v[i].first))) { bool musei = !pre && isMusei[i]; cout << v[i].first.substr(0, v[i].first.size()-1); if(musei) cout << "("; cout << getBoin(v[i].first); if(musei) cout << ")"; pre = musei; } else { cout << v[i].first; } } cout << endl; } return 0; }
s198386882
p01146
u352394527
1530796211
Python
Python3
py
Runtime Error
0
0
1075
from heapq import heappush, heappop INF = 10 ** 20 while True: n, m, l, k, a, h = map(int, input().split()) if n == 0: break if l != 0: sisetu = list(map(int, input().split())) + [a, h] else: sisetu = [a, h] costs = [[INF] * n for _ in range(n)] for _ in range(k): x, y, t = map(int, input().split()) costs[x][y] = t costs[y][x] = t for i in range(n): costs[i][i] = 0 for k in range(n): for j in range(n): for i in range(n): costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]) edges = [[] for _ in range(n)] for i in range(n): for j in range(n): if i != j and i in sisetu and j in sisetu and costs[i][j] <= m: edges[i].append((costs[i][j], j)) que = [] heappush(que, (0, a)) cost = [INF] * n cost[0] = 0 while que: total, node = heappop(que) for dist, to in edges[node]: if total + dist < cost[to]: cost[to] = total + dist heappush(que, (total + dist, to)) if cost[h] == INF: print("Help!") else: print(cost[h] + (cost[h] - m))
s367537586
p01146
u352394527
1530797633
Python
Python3
py
Runtime Error
0
0
1387
from heapq import heappush, heappop INF = 10 ** 20 def main(): while True: n, m, l, k, a, h = map(int, input().split()) if n == 0: break if l != 0: sisetu = list(map(int, input().split())) + [a, h] else: input() sisetu = [a, h] costs = [[INF] * n for _ in range(n)] for _ in range(k): x, y, t = map(int, input().split()) costs[x][y] = t costs[y][x] = t for k in range(n): costsk = costs[k] for i in range(n): costsi = costs[i] costsik = costsi[k] for j in range(i + 1, n): costsij = costsi[j] costsikj = costsik + costsk[j] if costsij > costsikj: costsi[j] = costsikj costs[j][i] = costsikj edges = [[] for _ in range(n)] for i in range(n): for j in range(i + 1, n): if i in sisetu and j in sisetu and costs[i][j] <= m: edges[i].append((costs[i][j], j)) edges[j].append((costs[i][j], i)) que = [] heappush(que, (0, a)) cost = [INF] * n cost[a] = 0 while que: total, node = heappop(que) for dist, to in edges[node]: if total + dist < cost[to]: cost[to] = total + dist heappush(que, (total + dist, to)) if cost[h] == INF: print("Help!") else: print(cost[h] + max(0, (cost[h] - m))) main()
s874962060
p01146
u943441430
1555920594
Python
Python3
py
Runtime Error
0
0
1708
# AOJ2021 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time #if t - time > 0 else 0 if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s773948158
p01146
u943441430
1555920762
Python
Python3
py
Runtime Error
0
0
1708
# AOJ2021 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time #if t - time > 0 else 0 if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s653843468
p01146
u943441430
1555921753
Python
Python3
py
Runtime Error
0
0
1741
# AOJ2021 town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s295010015
p01146
u943441430
1555922158
Python
Python3
py
Runtime Error
0
0
1715
# AOJ2021 town = [] freezer = [] dp = [] dic = {} mint = 100000000 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s460165884
p01146
u943441430
1555922189
Python
Python3
py
Runtime Error
0
0
1717
# AOJ2021 town = [] freezer = [] dp = [] dic = {} mint = 100000000 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) # if mint == 100000000: # return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s334491344
p01146
u943441430
1555922301
Python
Python3
py
Runtime Error
0
0
1681
# AOJ2021 town = [] freezer = [] dp = [] dic = {} mint = 100000000 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s879496053
p01146
u943441430
1555922502
Python
Python3
py
Runtime Error
0
0
1654
def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time #if t - time > 0 else 0 if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s263015659
p01146
u943441430
1555922550
Python
Python3
py
Runtime Error
0
0
1654
def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time #if t - time > 0 else 0 if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s238270470
p01146
u943441430
1555922623
Python
Python3
py
Runtime Error
0
0
1739
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time #if t - time > 0 else 0 if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s253447800
p01146
u943441430
1555922712
Python
Python3
py
Runtime Error
0
0
1715
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s231440862
p01146
u943441430
1555922769
Python
Python3
py
Runtime Error
0
0
1697
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s587839064
p01146
u943441430
1555922848
Python
Python3
py
Runtime Error
0
0
1741
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break if L > 0: freezer = list(map(int, list(input().split()))) else: input() for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s222709143
p01146
u943441430
1555923245
Python
Python3
py
Runtime Error
0
0
1697
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s763283383
p01146
u943441430
1555923630
Python
Python3
py
Runtime Error
0
0
1697
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, time = nt tt = t - time if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + time: dp[tt][town] = dp[t][r] + time if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + time: dp[tt + j][town] = dp[t][r] + j + time if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s061858965
p01146
u943441430
1555923693
Python
Python3
py
Runtime Error
0
0
1685
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, ti = nt tt = t - ti if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + ti: dp[tt][town] = dp[t][r] + ti if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + ti: dp[tt + j][town] = dp[t][r] + j + ti if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s551060857
p01146
u943441430
1555923825
Python
Python3
py
Runtime Error
0
0
1685
town = [] freezer = [] dp = [] dic = {} mint = 100000000 N = M = L = K = A = H = 0 def nexttown(): for r in range(0, N): dic[r] = [t[1:3] for t in town if t[0] == r] + [ [t[0], t[2]] for t in town if t[1] == r] def solve(): solve2(A, M, 0) if mint == 100000000: return "Help!" return mint def solve2(r, t, lv): global mint ntown = dic[r] for nt in ntown: town, ti = nt tt = t - ti if tt >= 0: if not(town in freezer): if dp[tt][town] == 0 or min(dp[tt][town], mint) > dp[t][r] + ti: dp[tt][town] = dp[t][r] + ti if town != H: solve2(town, tt, lv + 1) elif mint > dp[tt][town]: mint = dp[tt][town] else: for j in range(M - tt, -1, -1): if dp[tt + j][town] == 0 or min(dp[tt + j][town], mint) > dp[t][r] + j + ti: dp[tt + j][town] = dp[t][r] + j + ti if town != H: solve2(town, tt + j, lv + 1) elif mint > dp[tt + j][town]: mint = dp[tt + j][town] while True: town = [] freezer = [] dp = [] dic = {} mint = 100000000 line = input() N, M, L, K, A, H = map(int, line.split()) if N == 0 and M == 0 and L == 0: break freezer = list(map(int, list(input().split()))) for _ in range(0, K): t = list(map(int, list(input().split()))) town.append(t) dp = [ [0] * N for _ in range(0, M + 1) ] nexttown() print(solve())
s599565420
p01146
u633068244
1424513295
Python
Python
py
Runtime Error
0
0
671
inf = 1 << 28 def dfs(s,m,path): global ans if s == H: tmp = sum(d[i][j] for i,j in zip(path,path[1:])) ans = min(ans, tmp+max(0,tmp-M)) if s in cold: m = M for t in range(N): if d[s][t] <= m: if path.count(t) > 2: continue dfs(t,m-d[s][t],path+[t]) while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = [] if L > 0: cold += map(int,raw_input().split()) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t ans = inf dfs(A,M,[A]) print ans if ans < inf else "Help!"
s176201462
p01146
u633068244
1424513731
Python
Python
py
Runtime Error
19930
4272
646
inf = 1 << 28 def dfs(s,m,path): global ans if s == H: tmp = sum(d[i][j] for i,j in zip(path,path[1:])) ans = min(ans, tmp+max(0,tmp-M)) if s in cold: m = M for t in range(N): if d[s][t] <= m: if path.count(t) > 1: continue dfs(t,m-d[s][t],path+[t]) while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = map(int,raw_input().split()) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t ans = inf dfs(A,M,[A]) print ans if ans < inf else "Help!"
s822836342
p01146
u633068244
1424514885
Python
Python
py
Runtime Error
19930
4568
968
inf = 1 << 28 while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = map(int,raw_input().split()) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t for k in xrange(N): for i in xrange(N): for j in xrange(N): d[i][j] = min(d[i][j], d[i][k]+d[k][j]) ans = d[A][H] if d[A][H] <= M else inf used = [False]*N used[A] = True que = [[i,d[A][i]] for i in xrange(N) if i in cold and d[A][i] <= M] while que: s,time = que.pop(0) used[s] = True if d[s][H] <= M: time += d[s][H] ans = min(ans, time+max(0,time-M)) continue for t in xrange(N): if t in cold and not used[t] and d[s][t] <= M: que.append([t,time+d[s][t]]) print ans if ans < inf else "Help!"
s592542899
p01146
u633068244
1424515001
Python
Python
py
Runtime Error
19920
4560
1001
inf = 1 << 28 while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = map(int,raw_input().split()) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t for k in xrange(N): for i in xrange(N): for j in xrange(N): d[i][j] = min(d[i][j], d[i][k]+d[k][j]) ans = d[A][H] if d[A][H] <= M else inf used = [False]*N used[A] = True que = [[i,d[A][i]] for i in xrange(N) if i in cold and d[A][i] <= M] while que: s,time = que.pop(0) if time >= ans: continue used[s] = True if d[s][H] <= M: time += d[s][H] ans = min(ans, time+max(0,time-M)) continue for t in xrange(N): if t in cold and not used[t] and d[s][t] <= M: que.append([t,time+d[s][t]]) print ans if ans < inf else "Help!"
s724938341
p01146
u633068244
1424515150
Python
Python
py
Runtime Error
19920
4572
1006
inf = 1 << 28 while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = map(int,raw_input().split()) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t for k in xrange(N): for i in xrange(N): for j in xrange(N): d[i][j] = min(d[i][j], d[i][k]+d[k][j]) ans = d[A][H] if d[A][H] <= M else inf used = [False]*N used[A] = True que = [[i,d[A][i]] for i in xrange(N) if i in cold and d[A][i] <= M] for i,time in que: used[i] = True while que: s,time = que.pop(0) used[s] = True if d[s][H] <= M: time += d[s][H] ans = min(ans, time+max(0,time-M)) continue for t in xrange(N): if t in cold and not used[t] and d[s][t] <= M: que.append([t,time+d[s][t]]) print ans if ans < inf else "Help!"
s897094406
p01146
u633068244
1424515390
Python
Python
py
Runtime Error
19930
4608
1105
import copy inf = 1 << 28 while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = set(map(int,raw_input().split())) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t for k in xrange(N): for i in xrange(N): for j in xrange(N): d[i][j] = min(d[i][j], d[i][k]+d[k][j]) ans = d[A][H] if d[A][H] <= M else inf used = [False]*N used[A] = True que = sorted([[d[A][i],i] for i in xrange(N) if i in cold and d[A][i] <= M]) for time,i in que: used[i] = True while que: nque = [] time,s = que.pop(0) if time >= ans: continue used[s] = True if d[s][H] <= M: time += d[s][H] ans = min(ans, time+max(0,time-M)) break for t in xrange(N): if t in cold and not used[t] and d[s][t] <= M: nque.append([time+d[s][t],t]) que = copy.deepcopy(sorted(nque)) print ans if ans < inf else "Help!"
s860130853
p01146
u633068244
1424515454
Python
Python
py
Runtime Error
19930
4608
1158
import copy inf = 1 << 28 while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = set(map(int,raw_input().split())) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t for k in xrange(N): for i in xrange(N): for j in xrange(N): d[i][j] = min(d[i][j], d[i][k]+d[k][j]) ans = d[A][H] if d[A][H] <= M else inf if ans < inf: print ans continue used = [False]*N used[A] = True que = sorted([[d[A][i],i] for i in xrange(N) if i in cold and d[A][i] <= M]) for time,i in que: used[i] = True while que: nque = [] time,s = que.pop(0) if time >= ans: continue used[s] = True if d[s][H] <= M: time += d[s][H] ans = min(ans, time+max(0,time-M)) break for t in xrange(N): if t in cold and not used[t] and d[s][t] <= M: nque.append([time+d[s][t],t]) que = copy.deepcopy(sorted(nque)) print ans if ans < inf else "Help!"
s368168009
p01146
u633068244
1424516410
Python
Python
py
Runtime Error
19920
4588
964
def warshall(A): n = len(A) for k in xrange(n): for i in xrange(n): for j in xrange(n): A[i][j] = min(A[i][j], A[i][k]+A[k][j]) return A inf = 1 << 28 while 1: N,M,L,K,A,H = map(int,raw_input().split()) if N == 0: break cold = map(int,raw_input().split()) d = [[inf]*N for i in xrange(N)] for loop in xrange(K): x,y,t = map(int,raw_input().split()) d[x][y] = d[y][x] = t d = warshall(d) dd = [[inf]*(L+2) for i in xrange(L+2)] for i in range(L): dd[ 0][i+1] = dd[i+1][ 0] = d[A][cold[i]] if d[A][cold[i]] <= M else inf dd[-1][i+1] = dd[i+1][-1] = d[H][cold[i]] if d[H][cold[i]] <= M else inf for i in range(L): for j in range(L): dd[i+1][j+1] = d[cold[i]][cold[j]] if d[cold[i]][cold[j]] <= M else inf dd = warshall(dd) time = dd[0][-1] print time+max(0,time-M) if time < inf else "Help!"
s176285013
p01146
u685815919
1474953673
Python
Python
py
Runtime Error
0
0
1842
import sys def warshall(n, matrix): for i in xrange(n): matrix[i][i] = 0 for i in xrange(n): for j in xrange(n): for k in xrange(n): matrix[j][k] = min(matrix[j][k], matrix[j][i]+matrix[i][k]) return matrix def dijkstra(nodes, start, matrix): defnode = [False] * (nodes) cost = [sys.maxint] * (nodes) cost[start] = 0 node = start counter = 0 while True: counter += 1 if counter == nodes or node == sys.maxint: return cost defnode[node] = True for i in xrange(nodes): if defnode[i]: continue if matrix[node][i] == sys.maxint: continue cost[i] = min(cost[i], cost[node]+matrix[node][i]) minnode = sys.maxint mincost = sys.maxint for i in xrange(nodes): if defnode[i]: continue if cost[i] < mincost: minnode = i mincost = cost[i] node = minnode while True: # N : number of towns # M : time limit # L : locations for freeze # K : number of roads # A : start # H : destination N,M,L,K,A,H = map(int, raw_input().split()) if N==M==L==K==A==H==0: break if L == 0: l = [] else: l = map(int, raw_input().split()) matrix = [[1000000] * N for _ in xrange(N)] for _ in xrange(K): x,y,t = map(int, raw_input().split()) matrix[x][y] = t matrix[y][x] = t costs = warshall(N, matrix) newmatrix = [[1000000] * (L+2) for _ in xrange(L+2)] nodes = [] nodes.append(A) nodes.extend(l) nodes.append(H) for i in xrange(len(nodes)): for j in xrange(len(nodes)): newmatrix[i][j] = matrix[nodes[i]][nodes[j]] if newmatrix[i][j] > M: newmatrix[i][j] = 1000000 newcosts = dijkstra(L+2, 0, newmatrix) cost = newcosts[L+1] if cost >= 1000000: print "Help!" else: if cost > M: print cost*2-M else: print cost
s791034893
p01146
u685815919
1474954068
Python
Python
py
Runtime Error
40000
6700
1808
import sys def warshall(n, matrix): for i in xrange(n): matrix[i][i] = 0 for i in xrange(n): for j in xrange(n): for k in xrange(n): matrix[j][k] = min(matrix[j][k], matrix[j][i]+matrix[i][k]) return matrix def dijkstra(nodes, start, matrix): defnode = [False] * (nodes) cost = [sys.maxint] * (nodes) cost[start] = 0 node = start counter = 0 while True: counter += 1 if counter == nodes or node == sys.maxint: return cost defnode[node] = True for i in xrange(nodes): if defnode[i]: continue if matrix[node][i] == sys.maxint: continue cost[i] = min(cost[i], cost[node]+matrix[node][i]) minnode = sys.maxint mincost = sys.maxint for i in xrange(nodes): if defnode[i]: continue if cost[i] < mincost: minnode = i mincost = cost[i] node = minnode while True: # N : number of towns # M : time limit # L : locations for freeze # K : number of roads # A : start # H : destination N,M,L,K,A,H = map(int, raw_input().split()) if N==M==L==K==A==H==0: break l = map(int, raw_input().split()) matrix = [[1000000] * N for _ in xrange(N)] for _ in xrange(K): x,y,t = map(int, raw_input().split()) matrix[x][y] = t matrix[y][x] = t costs = warshall(N, matrix) newmatrix = [[1000000] * (L+2) for _ in xrange(L+2)] nodes = [] nodes.append(A) nodes.extend(l) nodes.append(H) for i in xrange(len(nodes)): for j in xrange(len(nodes)): newmatrix[i][j] = matrix[nodes[i]][nodes[j]] if newmatrix[i][j] > M: newmatrix[i][j] = 1000000 newcosts = dijkstra(L+2, 0, newmatrix) cost = newcosts[L+1] if cost >= 1000000: print "Help!" else: if cost > M: print cost*2-M else: print cost
s287319238
p01146
u685815919
1479101731
Python
Python
py
Runtime Error
0
0
1552
import sys import heapq class Dijkstra(object): def dijkstra(self, adj, start, goal=None): num = len(adj) dist = [sys.maxint] * num prev = [sys.maxint] * num dist[start] = 0 q = [] heapq.heappush(q, (0, start)) while len(q) != 0: prov_cost, src = heapq.heappop(q) if dist[src] < prov_cost: continue for dest in range(num): cost = adj[src][dest] if cost != sys.maxint and dist[dest] > dist[src] + cost: dist[dest] = dist[src] + cost heapq.heappush(q, (dist[dest], dest)) prev[dest] = src if goal is not None: return self.get_path(goal, prev) else: return dist def get_path(self, goal, prev): path = [goal] dest = goal while prev[dest] != sys.maxint: path.append(prev[dest]) dest = prev[dest] return list(reversed(path)) while True: N,M,L,K,A,H=map(int,raw_input().split()) if N==0: break # t(n,t) : minimum cost to remain t times and reach town n if L==0: Ls=[] else: Ls=map(int,raw_input().split()) edge=[[sys.maxint]*(N*(M+1)) for _ in xrange(N*(M+1))] for l in Ls: for i in xrange(M): edge[l*(M+1)+i][l*(M+1)+i+1]=1 for _ in xrange(K): s,g,c=map(int,raw_input().split()) for i in xrange(c,M+1): edge[s*(M+1)+i][g*(M+1)+i-c]=c edge[g*(M+1)+i][s*(M+1)+i-c]=c cost=Dijkstra().dijkstra(edge, A*(M+1)+M) minCost=sys.maxint for i in xrange(M+1): minCost=min(minCost,cost[H*(M+1)+i]) if minCost==sys.maxint: print "Help!" else: print minCost
s930244563
p01146
u260980560
1482831264
Python
Python
py
Runtime Error
0
0
969
from heapq import heappush, heappop while 1: N, M, L, K, A, H = map(int, raw_input().split()) if N == 0: break F = [0]*N if L>0: for e in map(int, raw_input().split()): F[e] = 1 G = [[] for i in xrange(N)] for i in xrange(K): x, y, t = map(int, raw_input().split()) G[x].append((y, t)) G[y].append((x, t)) dist = [[10**18]*(M+1) for i in xrange(N)] dist[A][M] = 0 que = [(0, A, M)] while que: cost, v, rest = heappop(que) if dist[v][rest] < cost: continue if F[v] and rest < M and cost + 1 < dist[v][rest+1]: dist[v][rest+1] = cost+1 heappush(que, (cost+1, v, rest+1)) for t, co in G[v]: if rest>=co and cost + co < dist[t][rest-co]: dist[t][rest-co] = cost + co heappush(que, (cost+co, t, rest-co)) ans = min(dist[H]) print "Help!" if ans > 10**17 else ans
s551504139
p01146
u509278866
1529642280
Python
Python3
py
Runtime Error
0
0
2190
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: N,M,L,K,A,H = LI() if N == 0: break S = set() if L > 0: S = set(LI()) e = collections.defaultdict(list) for _ in range(K): a,b,d = LI() e[a].append((b,d)) e[b].append((a,d)) def search(s): d = collections.defaultdict(lambda: inf) d[(-M,s)] = 0 q = [] heapq.heappush(q, (0, -M, s)) v = collections.defaultdict(bool) while len(q): k, m, u = heapq.heappop(q) if v[(m,u)]: continue for mm in range(m,1): v[(mm,u)] = True for uv, ud in e[u]: if ud > -m or v[(m+ud,uv)]: continue vd = k + ud vm = m+ud if uv in S: vm = -M if d[(vm,uv)] > vd: for mm in range(vm,1): d[(mm,uv)] = vd heapq.heappush(q, (vd, vm, uv)) return d d = search(A) r = inf for k in list(d.keys()): if k[1] == H and r > d[k]: r = d[k] if r == inf: rr.append('Help!') elif r <= M: rr.append(r) else: rr.append(r*2-M) return '\n'.join(map(str,rr)) print(main())
s215547005
p01158
u266872031
1422159096
Python
Python
py
Runtime Error
0
0
2563
def checkloop(pdict,product,inroute): inroute.append(product) if pdict[product][1]==product: return (False,product) elif pdict[product][1] in inroute: return (True,pdict[product][1]) else: return checkloop(pdict,pdict[product][1],inroute) def daysopen(pdict,product,made,notsearched): if pdict[product][1] in made: made.append(product) notsearched.remove(product) return pdict[product][2] if pdict[product][1]==product: made.append(product) notsearched.remove(product) return pdict[product][0] else: made.append(product) notsearched.remove(product) return daysopen(pdict,pdict[product][1],made,notsearched)+pdict[product][2] def daysloop(pdict,product,made,notsearched,inloop): inloop.append(product) if pdict[product][1] in inroute: smallestdifference=100000 smallestdifferenceitem="" for item in inloop: if smallestdifference>pdict[item][0]-pdict[item][2]: smallestdifference=pdict[item][0]-pdict[item][2] smallestdifferenceitem=item #gotsmallestitem days=pdict[smallestdifferenceitem][0] made.append(smallestdifferenceitem) notsearched.remove(smallestdifferenceitem) inloop.remove(smallestdifferenceitem) for item in inloop: made.append(item) notsearched.remove(item) days=days+pdict[item][2] return days else: return daysloop(pdict,pdict[product][1],made,notsearched,inloop) while(1): N=int(raw_input()) if N==0: break else: pdict={} notsearched=[] notcomplete=1 made=[] days=0 for i in range(N): indat=raw_input().split() pdict[indat[0]]=(int(indat[1]),indat[2],int(indat[3])) #name=(d1,sup,d2) notsearched.append(indat[0]) while len(notsearched)!=0: #check if loop inroute=[] product=notsearched[0] #check if sup made if pdict[product][1] in made: days=days+pdict[product][2] made.append(product) notsearched.remove(product) elif checkloop(pdict,product,inroute)[0]: inloop=[] days=days+daysloop(pdict,product,made,notsearched,inloop) else: days=days+daysopen(pdict,product,made,notsearched) print days
s385955724
p01158
u266872031
1422160510
Python
Python
py
Runtime Error
0
0
2604
import sys sys.setrecursionlimit(10000) def checkloop(pdict,product,inroute): inroute.append(product) if pdict[product][1]==product: return (False,product) elif pdict[product][1] in inroute: return (True,pdict[product][1]) else: return checkloop(pdict,pdict[product][1],inroute) def daysopen(pdict,product,made,notsearched): if pdict[product][1] in made: made.append(product) notsearched.remove(product) return pdict[product][2] if pdict[product][1]==product: made.append(product) notsearched.remove(product) return pdict[product][0] else: made.append(product) notsearched.remove(product) return daysopen(pdict,pdict[product][1],made,notsearched)+pdict[product][2] def daysloop(pdict,product,made,notsearched,inloop): inloop.append(product) if pdict[product][1] in inloop: smallestdifference=100000 smallestdifferenceitem="" for item in inloop: if smallestdifference>pdict[item][0]-pdict[item][2]: smallestdifference=pdict[item][0]-pdict[item][2] smallestdifferenceitem=item #gotsmallestitem days=pdict[smallestdifferenceitem][0] made.append(smallestdifferenceitem) notsearched.remove(smallestdifferenceitem) inloop.remove(smallestdifferenceitem) for item in inloop: made.append(item) notsearched.remove(item) days=days+pdict[item][2] return days else: return daysloop(pdict,pdict[product][1],made,notsearched,inloop) while(1): N=int(raw_input()) if N==0: break else: pdict={} notsearched=[] notcomplete=1 made=[] days=0 for i in range(N): indat=raw_input().split() pdict[indat[0]]=(int(indat[1]),indat[2],int(indat[3])) #name=(d1,sup,d2) notsearched.append(indat[0]) while len(notsearched)!=0: #check if loop inroute=[] product=notsearched[0] #check if sup made if pdict[product][1] in made: days=days+pdict[product][2] made.append(product) notsearched.remove(product) elif checkloop(pdict,product,inroute)[0]: inloop=[] days=days+daysloop(pdict,product,made,notsearched,inloop) else: days=days+daysopen(pdict,product,made,notsearched) print days
s273585761
p01159
u266872031
1422166912
Python
Python
py
Runtime Error
19930
4288
691
def f(fxp,fyp,x): ret=0 for i in range(len(fxp)-1): if fxp[i]<=x and fxp[i+1]>x: ret= fyp[i]+(fyp[i+1]-fyp[i])*(x-fxp[i])/float(fxp[i+1]-fxp[i]) break return ret while(1): nrinput=raw_input().split() [n,r]=[int(nrinput[0]), float(nrinput[1])] if n==0: break else: fxp=[] fyp=[] for i in range(n): [x,y]=[int(x) for x in raw_input().split()] fxp.append(x) fyp.append(y) startp=fxp[0] endp=fxp[-1] t=startp S=0 dt=0.0001 while t<=endp: S=S+f(fxp,fyp,t)*f(fxp,fyp,t+r)*dt t=t+dt print S
s884652425
p01159
u266872031
1422167431
Python
Python
py
Runtime Error
19930
4292
690
def f(fxp,fyp,x): ret=0 for i in range(len(fxp)-1): if fxp[i]<=x and fxp[i+1]>x: ret= fyp[i]+(fyp[i+1]-fyp[i])*(x-fxp[i])/float(fxp[i+1]-fxp[i]) break return ret while(1): nrinput=raw_input().split() [n,r]=[int(nrinput[0]), float(nrinput[1])] if n==0: break else: fxp=[] fyp=[] for i in range(n): [x,y]=[int(x) for x in raw_input().split()] fxp.append(x) fyp.append(y) startp=fxp[0] endp=fxp[-1] t=startp S=0 dt=0.001 while t<=endp: S=S+f(fxp,fyp,t)*f(fxp,fyp,t+r)*dt t=t+dt print S
s033066713
p01160
u266872031
1422177425
Python
Python
py
Runtime Error
19930
4252
930
def trydecr(word): longest=0 decrtemp="" decr="" if len(word)==0: return "" else: for index in range(len(word)): i=len(word)-1 while i>index: if word[i]==word[index]: decrtemp=word[index]+trydecr(word[index+1:i])+word[index] if len(decrtemp)>longest: decr=decrtemp longest=len(decrtemp) i=i-1 if len(decr)!=0: return decr else: return word[0] while(1): try: word=raw_input() except: break decr=trydecr(word) # longest=0 # decr="" # for i in range(len(word)): #trying with head letter=word ith letter # decrtemp=trydecr(word[i:]) # print decrtemp # if len(decrtemp)>longest: # decr=decrtemp # longest=len(decrtemp) print decr
s052017607
p01160
u266872031
1422177585
Python
Python
py
Runtime Error
0
0
1017
import sys sys.setrecursionlimit(10000) # 10000回 まで再帰呼び出しを許可 def trydecr(word): longest=0 decrtemp="" decr="" if len(word)==0: return "" else: for index in range(len(word)): i=len(word)-1 while i>index: if word[i]==word[index]: decrtemp=word[index]+trydecr(word[index+1:i])+word[index] if len(decrtemp)>longest: decr=decrtemp longest=len(decrtemp) i=i-1 if len(decr)!=0: return decr else: return word[0] while(1): try: word=raw_input() except: break decr=trydecr(word) # longest=0 # decr="" # for i in range(len(word)): #trying with head letter=word ith letter # decrtemp=trydecr(word[i:]) # print decrtemp # if len(decrtemp)>longest: # decr=decrtemp # longest=len(decrtemp) print decr
s871108612
p01160
u266872031
1422177764
Python
Python
py
Runtime Error
0
0
978
import sys sys.setrecursionlimit(10000) def trydecr(word,memo): longest=0 decrtemp="" decr="" if len(word)==0: return "" else: for index in range(len(word)): i=len(word)-1 while i>index: if word[i]==word[index]: decrtemp=word[index]+trydecr(word[index+1:i])+word[index] if len(decrtemp)>longest: decr=decrtemp longest=len(decrtemp) i=i-1 if len(decr)!=0: return decr else: return word[0] while(1): try: word=raw_input() except: break decr=trydecr(word) # longest=0 # decr="" # for i in range(len(word)): #trying with head letter=word ith letter # decrtemp=trydecr(word[i:]) # print decrtemp # if len(decrtemp)>longest: # decr=decrtemp # longest=len(decrtemp) print decr
s734825901
p01160
u266872031
1422177832
Python
Python
py
Runtime Error
19930
4260
973
import sys sys.setrecursionlimit(10000) def trydecr(word): longest=0 decrtemp="" decr="" if len(word)==0: return "" else: for index in range(len(word)): i=len(word)-1 while i>index: if word[i]==word[index]: decrtemp=word[index]+trydecr(word[index+1:i])+word[index] if len(decrtemp)>longest: decr=decrtemp longest=len(decrtemp) i=i-1 if len(decr)!=0: return decr else: return word[0] while(1): try: word=raw_input() except: break decr=trydecr(word) # longest=0 # decr="" # for i in range(len(word)): #trying with head letter=word ith letter # decrtemp=trydecr(word[i:]) # print decrtemp # if len(decrtemp)>longest: # decr=decrtemp # longest=len(decrtemp) print decr
s363709337
p01171
u772196646
1401854795
Python
Python
py
Runtime Error
0
0
574
def prime(a): prime = [] for p in range(2, a): if a % p == 0: prime.append(p) while a % p == 0: a /= p return prime def keynumber(prime): sum = 0 for i in range(len(prime) - 1): sum += prime[i] key = prime[-1] - sum return key while 1: ab = raw_input().split() a = int(ab[0]) b = int(ab[1]) if a == 0 and b == 0: break pa = prime(a) pb = prime(b) ka = keynumber(pa) kb = keynumber(pb) if ka > kb: print('a') else: print('b')
s868998353
p01172
u266872031
1428333740
Python
Python
py
Runtime Error
19930
19216
702
import bisect def index(a, x): 'Locate the leftmost value exactly equal to x' i = bisect.bisect_left(a, x) if i != len(a) and a[i] == x: return i else: return -1 while(1): [x,y]=[int(x) for x in raw_input().split()] if x==0: break amarilist=[x] amarilistb=[x] amari=x while(1): amari=amari*10%y if amari==0: print len(amarilist),0 break elif index(amarilist,amari)!=-1: bef=amarilistb.index(amari) aft=len(amarilistb)-bef print bef,aft break else: bisect.insort_left(amarilist,amari) amarilistb.append(amari)
s253474122
p01172
u266872031
1428334929
Python
Python
py
Runtime Error
19930
5744
499
while(1): [x,y]=[int(x) for x in raw_input().split()] digitsy=y/10+1 if x==0: break amarilist=[x] amari=x j=1 while(1): amari=amari*10%y if amari==0: print len(amarilist),0 break elif amari in amarilist: bef=amarilist.index(amari) aft=j-bef print bef,aft break else: if j<=digitsy: amarilist.append(amari) j=j+1
s701048141
p01172
u266872031
1428335257
Python
Python
py
Runtime Error
19930
4216
496
while(1): [x,y]=[int(x) for x in raw_input().split()] digitsy=len(str(y)) if x==0: break amarilist=[x] amari=x j=1 while(1): amari=amari*10%y if amari==0: print len(amarilist),0 break elif amari in amarilist: bef=amarilist.index(amari) aft=j-bef print bef,aft break else: if j<=digitsy: amarilist.append(amari) j=j+1
s166360860
p01172
u266872031
1428335479
Python
Python
py
Runtime Error
19930
4216
498
while(1): [x,y]=[int(x) for x in raw_input().split()] digitsy=len(str(y))+1 if x==0: break amarilist=[x] amari=x j=1 while(1): amari=amari*10%y if amari==0: print len(amarilist),0 break elif amari in amarilist: bef=amarilist.index(amari) aft=j-bef print bef,aft break else: if j<=digitsy: amarilist.append(amari) j=j+1
s699079838
p01172
u266872031
1474706201
Python
Python
py
Runtime Error
40000
8452
310
#a,b while(1): [a,b]=[int(x) for x in raw_input().split()] if a==0: break Dlist=[] while(1): if a in Dlist: break Dlist.append(a) a*=10 a%=b if a!=0: print Dlist.index(a),len(Dlist)-Dlist.index(a) else: print len(Dlist)-1,0
s670252044
p01180
u072053884
1520665146
Python
Python3
py
Runtime Error
0
0
534
def solve(): import sys from itertools import combinations input_lines = sys.stdin.readlines() while True: N = int(input_lines[0]) if N == 0: break distance = [] for t1, t2 in combinations(input_lines[1:N+1], 2): r1, x1, y1 = map(float, t1.split()) r2, x2, y2 = map(float, t2.split()) d = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 -r1 - r2 distance.append(d) print(min(distance)) del input_lines[:N+1] solve()
s068397627
p01192
u266872031
1500258616
Python
Python
py
Runtime Error
40000
181420
844
def printans(Cnum,ans): print 'Case #'+str(Cnum)+': '+ans Cnum=1 while(1): inp=[int(x) for x in raw_input().split()] if inp[0]==0: break [n,C]=[inp[0],inp[1:]] if C[0]!=1: ans='Cannot pay some amount' printans(Cnum,ans) Cnum+=1 else: A=[[y for y in range(55000)] for x in range(n)] for x in range(1,n): esc=0 c=C[x] for y in range(55000): A[x][y]=y/c + A[x-1][y%c] if A[x-1][y]<A[x][y]: ans='Cannot use greedy algorithm' printans(Cnum,ans) Cnum+=1 esc=1 break if esc==1: break else: ans='OK' printans(Cnum,ans) Cnum+=1 esc=1
s682023953
p01192
u266872031
1500259853
Python
Python
py
Runtime Error
40000
165004
893
def printans(Cnum,ans): print 'Case #'+str(Cnum)+': '+ans Cnum=1 while(1): inp=[int(x) for x in raw_input().split()] if inp[0]==0: break [n,C]=[inp[0],inp[1:]] Amax=C[-1]*n if C[0]!=1: ans='Cannot pay some amount' printans(Cnum,ans) Cnum+=1 else: A=[[y for y in range(Amax)] for x in range(n)] for x in range(1,n): esc=0 c=C[x] A[x][:c]=A[x-1][:c] for y in range(c,Amax): A[x][y]=y/c + A[x-1][y%c] if A[x-1][y]<A[x][y]: ans='Cannot use greedy algorithm' printans(Cnum,ans) Cnum+=1 esc=1 break if esc==1: break else: ans='OK' printans(Cnum,ans) Cnum+=1 esc=1
s611061881
p01193
u078042885
1484929288
Python
Python3
py
Runtime Error
0
0
96
while 1: try:f=input()[:-1] except:break print(eval(f) if 0<=eval(f)<10000 else 'E')
s655991472
p01193
u078042885
1484929982
Python
Python3
py
Runtime Error
0
0
99
import sys for l in sys.stdin: f,_=l.split('=') print(eval(f) if 0<=eval(f)<10000 else 'E')
s800224021
p01213
u072053884
1529378109
Python
Python3
py
Runtime Error
0
0
1211
def lcs(x, y): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return lcs[::-1] pos -= 1 def solve(): import sys file_input = sys.stdin for s in file_input: s = s.rstrip() if s == '#END': break sep = len(s) // 2 ans = lcs(s[:sep], s[sep:]) ans_len = len(ans) while sep > len(ans): sep -= 1 a1 = lcs(s[:sep], s[sep:]) a2 = lcs(s[:-sep], s[-sep:]) if ans_len < len(a1): ans = a1 ans_len = len(ans) if ans_len < len(a2): ans = a2 ans_len = len(ans) print(ans) solve()
s061680675
p01213
u072053884
1529381770
Python
Python3
py
Runtime Error
0
0
1347
def lcs(x, y): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) if idx: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return lcs[::-1] pos -= 1 else: return '' def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s == '#END': break sep = len(s) // 2 ans = lcs(s[:sep], s[sep:]) ans_len = len(ans) while sep > len(ans): a1 = lcs(s[:-sep], s[-sep:]) sep -= 1 a2 = lcs(s[:sep], s[sep:]) if ans_len < len(a1): ans = a1 ans_len = len(ans) if ans_len < len(a2): ans = a2 ans_len = len(ans) ans_out.append(ans) print(*ans_out, sep='\n') solve()
s392030623
p01213
u072053884
1529381841
Python
Python3
py
Runtime Error
0
0
1308
def lcs(x, y): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) if idx: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return lcs[::-1] pos -= 1 else: return '' def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s == '#END': break sep = len(s) // 2 ans = lcs(s[:sep], s[sep:]) ans_len = len(ans) while sep > len(ans): a1 = lcs(s[:-sep], s[-sep:]) sep -= 1 a2 = lcs(s[:sep], s[sep:]) if ans_len < len(a1): ans = a1 ans_len = len(ans) if ans_len < len(a2): ans = a2 ans_len = len(ans) print(ans) solve()
s234587652
p01213
u072053884
1529398287
Python
Python3
py
Runtime Error
0
0
1280
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s == '#END': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) sep = s_len - ans_len - 1 while sep > ans_len: ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) sep -= 1 ans_out.append(ans) print(*ans_out, sep='\n') solve()
s893977302
p01213
u072053884
1529399136
Python
Python3
py
Runtime Error
0
0
1312
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys #file_input = sys.stdin file_input = open('2090_in', 'r')# ans_out = [] for s in file_input: s = s.rstrip() if s == '#END': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) print(ans) solve()
s732291044
p01213
u072053884
1529399153
Python
Python3
py
Runtime Error
0
0
1272
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s == '#END': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) print(ans) solve()
s429873139
p01213
u072053884
1529399223
Python
Python3
py
Runtime Error
0
0
1311
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s == '#END': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) ans_out.append(ans) print(*ans_out, sep='\n') solve()
s221971991
p01213
u072053884
1529546690
Python
Python3
py
Runtime Error
0
0
1195
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def lrs(s): s = s.rstrip() s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) return ans import sys input_lines = sys.stdin.readlines() print('\n'.join(map(lrs, input_lines[:-1])))
s165992796
p01213
u072053884
1529546814
Python
Python3
py
Runtime Error
0
0
1201
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def lrs(s): s = s.rstrip() s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) return ans import sys input_lines = sys.stdin.readlines() for line in input_lines[:-1]: print(lrs(line))
s543595610
p01213
u072053884
1529977515
Python
Python3
py
Runtime Error
0
0
1311
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s[0] == '#': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) ans_out.append(ans) print(*ans_out, sep='\n') solve()
s081159110
p01213
u072053884
1530108799
Python
Python3
py
Runtime Error
0
0
1311
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s[0] == '#': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) ans_out.append(ans) print(*ans_out, sep='\n') solve()
s289832196
p01213
u072053884
1530108879
Python
Python3
py
Runtime Error
0
0
1255
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin for s in file_input: s = s.rstrip() if s[0] == '#': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) print(ans) solve()
s259334342
p01213
u072053884
1530321902
Python
Python3
py
Runtime Error
0
0
1311
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s[0] == '#': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) ans_out.append(ans) print(*ans_out, sep='\n') solve()
s817863484
p01213
u072053884
1530456875
Python
Python3
py
Runtime Error
0
0
1311
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s[0] == '#': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) ans_out.append(ans) print(*ans_out, sep='\n') solve()
s529949886
p01213
u072053884
1530552604
Python
Python3
py
Runtime Error
0
0
1311
def lcs(x, y, pre_lcs, pre_lcs_len): rec = [] idx = [] for c in y: s = 0 for i, k in enumerate(idx): t = x.find(c, s) + 1 if t < 1: break if t < k: idx[i] = t s = k else: t = x.find(c, s) + 1 if t: idx.append(t) rec.append(idx.copy()) lcs_len = len(idx) if lcs_len > pre_lcs_len: lcs = '' pos = len(idx) - 1 for line, yc in zip(rec[::-1], y[::-1]): i = line[pos] - 1 xc = x[i] if xc == yc: lcs += xc if pos == 0: return (lcs[::-1], lcs_len) pos -= 1 else: return (pre_lcs, pre_lcs_len) def solve(): import sys file_input = sys.stdin ans_out = [] for s in file_input: s = s.rstrip() if s[0] == '#': break s_len = len(s) sep = s_len // 2 ans, ans_len = lcs(s[:sep], s[sep:], '', 0) while sep > ans_len: ans, ans_len = lcs(s[:-sep], s[-sep:], ans, ans_len) sep -= 1 ans, ans_len = lcs(s[:sep], s[sep:], ans, ans_len) ans_out.append(ans) print(*ans_out, sep='\n') solve()
s277164022
p01214
u647766105
1389880784
Python
Python
py
Runtime Error
39860
4396
1579
def toBinary(block): return [sum(1 << i for i,bb in enumerate(b) if bb == "#") for b in block] def toStr(bfield): return ["".join("." if f & (1<<i) == 0 else "#" for i in xrange(W)) for f in bfield] def rotated(block): return map(lambda x:"".join(x),zip(*[b[:] for b in block]))[::-1] def striped(block): ret = [b[:] for b in block] while ret[-1] == "." * len(ret[0]): ret.pop(-1) while ret[0] == "." * len(ret[0]): ret.pop(0) return ret def canPut(x, y): if not(0 < x + w <= W or 0 < y + h <= H): return False for f,b in zip(bfield[y:y+h], bblock): if (f & (b << x)) != 0: return False return True def puted(x, y): ret = bfield[:] for i,b in zip(xrange(y,y+h), bblock): ret[i] = ret[i] | (b << x) print "\n".join(toStr(ret)),"\n" return ret def count(bfield): return sum(1 for f in bfield if f == (1 << W) -1) for _ in xrange(input()): block = striped(rotated(striped([raw_input() for _ in xrange(map(int, raw_input().split())[0])]))) h, w = len(block), len(block[0]) H, W = map(int, raw_input().split()) field = [raw_input() for _ in xrange(H)] bfield = toBinary(field) FLAG = False ans = 0 for _ in xrange(4): block = rotated(block) h, w = w, h bblock = toBinary(block) for y in xrange(0, H - h + 1): for x in xrange(0, W - w + 1): if canPut(x, y): FLAG = True ans = max(ans, count(puted(x, y))) print ans if FLAG else -1
s569224925
p01223
u546285759
1508274689
Python
Python3
py
Runtime Error
0
0
247
t = int(input()) for _ in range(t): n = int(input()) h = list(map(int, input().split())) maxv = 0, minv = 0 for i in range(len(h)-1): maxv = max(maxv, h[i+1]-h[i]) minv = max(minv, h[i]-h[i+1]) print(maxv, minv)
s015508564
p01223
u454358619
1378099190
Python
Python
py
Runtime Error
0
0
470
import sys def solve(): c = int(raw_input()) for i in range(c): n = int(raw_input()) data = map(int, raw_input()) u,d = 0,0 for i in range(n - 1): if i % 2 == 0: if data[i + 1] - data[i] > u: u = data[i + 1] - data[i] else: if data[i + 1] - data[i] > d: d = data[i + 1] - data[i] print u,d if __name__ == "__main__": solve()
s564164744
p01225
u772196646
1413772291
Python
Python
py
Runtime Error
19930
4392
622
import itertools as it T = input() def goodset(a, b, c): return (a == b and b == c) or (a + 1 == b and b + 1 == c) def win(c): return goodset(c[0], c[1], c[2]) and goodset(c[3], c[4], c[5]) and goodset(c[6], c[7], c[8]) for i in range(T): cards = map(int, raw_input().split()) color = raw_input().split() for j in range(9): if color[j] == "G": cards[j] += 100 elif color[j] == "B": cards[j] += 200 w = 0 for p in it.permutations(range(9)): c = [cards[p[j]] for j in range(9)] if win(c): w = 1 break print w
s441192594
p01225
u798803522
1469820010
Python
Python3
py
Runtime Error
0
0
1247
import os with open("input1.txt") as f: trial = int(f.readline()) nums,words = [],[] for s in range(trial): nums = [[int(n)] for n in f.readline().split(" ")] words = [n for n in f.readline().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,1,nums[t][0],nums[t][1]) if samecnt == 3: samecnt = 0 ans += 1 if 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: if ans == 2 and (samecnt == 3 or cnt == 3): print(1) else: print(0)
s106830941
p01225
u798803522
1470063706
Python
Python3
py
Runtime Error
0
0
1116
trial = int(f.readline()) nums,words = [],[] for s in range(trial): nums = [[int(n)] for n in f.readline().split(" ")] words = [n for n in f.readline().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)