sortings *1700

Please click on ads to support us..

Python Code:

import sys
from itertools import groupby
from collections import defaultdict, Counter

n, m = sys.stdin.readline().split(maxsplit=1)
n = int(n)
m = int(m)
queens = []

for line in sys.stdin:
    if line == '':
        break
    line = line.strip()

    x, y = line.split(maxsplit=1)
    queens.append((int(x), int(y)))


def f1(x):
    return x[1], x[0]


def f2(x):
    return x[0], x[1]


def f3(x):
    return x[1] + x[0], x[1]


def f4(x):
    return x[1] - x[0], x[1]


def f5(x):
    return x[1]


def f6(x):
    return x[0]


def f7(x):
    return x[1] + x[0]


def f8(x):
    return x[1] - x[0]


lambdas = [f1, f2, f3, f4]
g_lambdas = [f5, f6, f7, f8]
if len(queens) != m:
    raise ValueError("wrong queen numbe8r!")
attacks = defaultdict(lambda: 0)
for sl, gl in zip(lambdas, g_lambdas):
    s_queens = sorted(queens, key=sl)
    a = (list(g) for k, g in groupby(s_queens, key=gl))

    for g in a:
        if len(g) == 1:
            attacks[g[0]] += 0
        else:
                        attacks[g[0]] += 1
            attacks[g[-1]] += 1
            for k in g[1:-1]:
                attacks[k] += 2

output = [0] * 9
for k, v in Counter(attacks.values()).items():
    output[k] = v
print(*output)


Comments

Submit
0 Comments
More Questions

507B - Amr and Pins
379A - New Year Candles
1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns
1374C - Move Brackets
1476A - K-divisible Sum
1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort
1370C - Number Game
1206B - Make Product Equal One
131A - cAPS lOCK
1635A - Min Or Sum
474A - Keyboard
1343A - Candies
1343C - Alternating Subsequence
1325A - EhAb AnD gCd
746A - Compote
318A - Even Odds
550B - Preparing Olympiad
939B - Hamster Farm