Facebook
From Ample Mockingbird, 11 Months ago, written in Python.
Embed
Download Paste or View Raw
Hits: 111
  1. import re
  2.  
  3. def list_of_points_in_space(d: {}) -> []:
  4.     li = []
  5.     for w in range(int(d["w"])):
  6.         for h in range(int(d["h"])):
  7.             t = (int(d["ls"]) + w, int(d["ts"]) + h)
  8.             li.append(t)
  9.     return li
  10.  
  11. def list_of_points_in_space_dict(d: {}) -> {}:
  12.     # Zwraca list─Ö punkt├│w w przestrzeni zajmowan─ů przez okre┼Ťlny claim
  13.     # lista tupli, tzn. [(0,0), (0,1)] itd.
  14.     result_dict = {}
  15.     for d2 in d.values():
  16.         for t in list_of_points_in_space(d2):
  17.             result_dict[t] = result_dict.get(t, 0) + 1
  18.     return result_dict
  19.  
  20. if __name__ == "__main__":
  21.     # Pobieranie danych i zaczytywanie do dict
  22.     d = {}
  23.     ids = []
  24.     inpt = input()
  25.     while inpt:
  26.         #id @ left_shift,top_shift: WidthxHeight
  27.         dupa_re = re.compile(r"\#(\d{1,4}) \@ (\d{1,3})\,(\d{1,3})\: (\d{1,2})x(\d{1,2})")
  28.         m = dupa_re.search(inpt)
  29.         d_temp = {"ls": m.group(2), "ts": m.group(3), "w": m.group(4), "h": m.group(5)}
  30.         # d[m.group(1)] = d_temp # stary spos├│b
  31.         li = list_of_points_in_space(d_temp)
  32.         for t in li:
  33.             if t in d:
  34.                 d[t].append(int(m.group(1)))
  35.             else:
  36.                 d[t] = [int(m.group(1))]
  37.         ids.append(int(m.group(1)))
  38.         inpt = input()
  39.  
  40.     # Szukanie takiego ID, kt├│ry nie wyst─Öpuje w parze z innym ID
  41.     # w ┼╝adnym kluczu (tupli)
  42.     bad_ids, good_ids = [], []
  43.     for v in d.values():
  44.         if len(v) > 1:
  45.             bad_ids += v
  46.         else:
  47.             good_ids += v
  48.  
  49.     for x in set(good_ids):
  50.         if x not in bad_ids:
  51.             print(x)
  52.             break