| 12345678910111213141516 |
- '''
- > https://www.codingame.com/ide/puzzle/organic-compounds
- @author: olivier.massot, 2019
- '''
- import re
- compounds = [re.findall("\(\d\)|CH\d|0", input().replace(" ", "0")) for i in range(int(input()))]
- values = [[int(re.search(r"\d", c)[0]) for c in row] for row in compounds]
- def getval(x, y):
- return values[y][x] if 0 <= y < len(values) and 0 <= x < len(values[y]) else 0
-
- valid = all((sum([getval(x, y), getval(x - 1, y), getval(x + 1, y), getval(x, y - 1), getval(x, y + 1)]) == 4 \
- for y, row in enumerate(compounds) for x, v in enumerate(row) if v[0] == 'C'))
-
- print("VALID" if valid else "INVALID")
|