mfgnik

Untitled

Jan 16th, 2021
519
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import itertools
  2. import sys
  3. n = int(input())
  4. fragments = []
  5. lengthes = []
  6. for i in range(n):
  7.     amount, length = map(int, input().split())
  8.     lengthes.append(length)
  9.     fragments.append(list(map(int, input().split())))
  10.     if len(fragments[-1]) > 2:
  11.         frag_distance = fragments[-1][1] - fragments[-1][0]
  12.         for i in range(1, len(fragments[-1])):
  13.             if fragments[-1][i] - fragments[-1][i - 1] != frag_distance:
  14.                 print("NO")
  15.                 sys.exit(0)
  16. for permutation in itertools.permutations(range(n)):
  17.     current = []
  18.     current_length = 0
  19.     for element in permutation:
  20.         current.extend(map(lambda x: x + current_length, fragments[element]))
  21.         current_length += lengthes[element]
  22.     current_distance = current[1] - current[0]
  23.     flag = True
  24.     for i in range(1, len(current)):
  25.         if current[i] - current[i - 1] != current:
  26.             flag = False
  27.             break
  28.     if flag:
  29.         print("YES")
  30.         sys.exit(0)
  31. print("NO")
  32.  
RAW Paste Data