hiho week 255 register

Ended

Participants:127

Verdict:Accepted
Score:100 / 100
Submitted:2019-05-24 15:48:54

Lang:Python2

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from collections import Counter
def comb2(n):
    return int(n*(n-1)/2)
n = int(raw_input())
queen_loc = []
for i in range(n):
    queen_loc.append([int(s) for s in raw_input().split(' ')])
RCLDRD = [][][][]
# in same row, column, right diagonal and left diagonal
for loc in queen_loc:
    r_i , c_i = loc
    R.append(r_i)
    C.append(c_i)
    LD.append(r_i+c_i)
    RD.append(r_i-c_i)
sum_queen = 0
for cat in [Counter(R),Counter(C),Counter(LD),Counter(RD)]:
    for item in cat.values():
        if item > 1:
            sum_queen += comb2(item)
print(int(sum_queen))
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX