restructure, slow security solution
This commit is contained in:
54
longlong_fail.py
Normal file
54
longlong_fail.py
Normal file
@@ -0,0 +1,54 @@
|
||||
prog1 = [(i, int(b), *r) for i, b, *r in (tuple(line.split()) for line in iter(input, 'E'))]
|
||||
prog2 = [(i, int(b), *r) for i, b, *r in (tuple(line.split()) for line in iter(input, 'E'))]
|
||||
|
||||
|
||||
def swapped(a, b):
|
||||
if a is None:
|
||||
return b, None
|
||||
if b is None:
|
||||
return a, None
|
||||
|
||||
ai, ap, *ar = a
|
||||
bi, bp, *br = b
|
||||
|
||||
if bi == 'I':
|
||||
if ap >= bp:
|
||||
a = ai, ap + 1, *ar
|
||||
return b, a
|
||||
|
||||
if ai != bi and ap == bp:
|
||||
return None, None
|
||||
|
||||
if bi == 'D':
|
||||
if ap > bp:
|
||||
a = ai, ap - 1, *ar
|
||||
return b, a
|
||||
|
||||
return a, b
|
||||
|
||||
|
||||
def bsort(lst, swapper):
|
||||
while True:
|
||||
olist = list(lst)
|
||||
i = 0
|
||||
|
||||
while i < len(lst) - 1:
|
||||
if lst[i] is None or lst[i + 1] is None or lst[i][1] >= lst[i + 1][1]:
|
||||
lst[i], lst[i+1] = swapper(lst[i], lst[i + 1])
|
||||
i += 1
|
||||
|
||||
if olist == lst:
|
||||
break
|
||||
|
||||
|
||||
# print(prog1)
|
||||
bsort(prog1, swapped)
|
||||
prog1 = [x for x in prog1 if x is not None]
|
||||
# print(prog1)
|
||||
# print()
|
||||
# print(prog2)
|
||||
bsort(prog2, swapped)
|
||||
prog2 = [x for x in prog2 if x is not None]
|
||||
# print(prog2)
|
||||
|
||||
print('10'[prog1 == prog2])
|
||||
Reference in New Issue
Block a user