diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-08-03 03:06:23 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-08-03 03:06:23 +0700 |
commit | 5cfeec0f11dbcff922fe5b1a1a17bccf4812852e (patch) | |
tree | c866745d54978d860f93acbff14e7ca1d1d2db59 /others/mHoang/colorec.py | |
parent | 44f9d4b8e63d4f7f1b447744124e95f22c8ce296 (diff) | |
download | cp-5cfeec0f11dbcff922fe5b1a1a17bccf4812852e.tar.gz |
[others] Move other/colorec.* to mHoang and add other/{defrac,lang}.py
Diffstat (limited to 'others/mHoang/colorec.py')
-rwxr-xr-x | others/mHoang/colorec.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/others/mHoang/colorec.py b/others/mHoang/colorec.py new file mode 100755 index 0000000..d55ac7f --- /dev/null +++ b/others/mHoang/colorec.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +from itertools import combinations + +COLORS = {1, 2, 3, 4} + +with open('COLOREC.INP') as f: + f.readline() + color, exes, eyes, count = {}, {}, {}, 0 + for line in f: + x, y, c = map(int, line.split()) + color[x, y] = c + exes.setdefault(y, []) + exes[y].append(x) + eyes.setdefault(x, []) + eyes[x].append(y) + +for v in eyes.values(): v.sort() +for y0, l in exes.items(): + for x0, x1 in combinations(l, 2): + s = COLORS - {color[x0, y0], color[x1, y0]} + if len(s) > 2: continue + for y1 in eyes[x0][y0:]: + try: + count += not s - {color[x0, y1], color[x1, y1]} + except: + continue + +with open('COLOREC.OUT', 'w') as f: print(count, file=f) |