Problem:


Score : 400 points

Problem Statement

We have a grid with H rows and W columns. At first, all cells were painted white.

Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.

Compute the following:

For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

Constraints

3 \leq H \leq 10^9

3 \leq W \leq 10^9

0 \leq N \leq min(10^5,H×W)

1 \leq a_i \leq H (1 \leq i \leq N)

1 \leq b_i \leq W (1 \leq i \leq N)

(a_i, b_i) \neq (a_j, b_j) (i \neq j)

Input

The input is given from Standard Input in the following format:

H W N
a_1 b_1
:
a_N b_N

Output

Print 10 lines.
The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.

Sample Input 1

4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4

Sample Output 1

0
0
0
2
4
0
0
0
0
0

There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.

Sample Input 2

10 10 20
1 1
1 4
1 9
2 5
3 10
4 2
4 7
5 9
6 4
6 6
6 7
7 1
7 3
7 7
8 1
8 5
8 10
9 2
10 4
10 9

Sample Output 2

4
26
22
10
2
0
0
0
0
0

Sample Input 3

1000000000 1000000000 0

Sample Output 3

999999996000000004
0
0
0
0
0
0
0
0
0



Sample input:
4 5 8
1 1
1 4
1 5
2 3
3 1
3 2
3 4
4 4


Sample output:
0
0
0
2
4
0
0
0
0
0

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def sum_matrix(array):
	return sum([sum(x) for x in array])
count = {}
H, W, N = MAP()
ab = [LIST() for _ in range(N)]
for a, b in ab:				
	for i in range(a-3, a):
		for j in range(b-3, b):
			if i < 0 or j < 0:
				continue
			if i+2 >= H or j+2 >= W:
				continue
			else:
				if not str(i)+","+str(j) in count:
					count[str(i)+","+str(j)] = 1
				else:
					count[str(i)+","+str(j)] += 1
ans = [0] * 10
for key in count:
	ans[count[key]] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
for i in ans:
	print(i)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	H, W, N = map(int, input().split(" "))
	AB = []
	for _ in range(N):
		a, b = map(int, input().split(" "))
		AB.append((a, b))

	ans = {}
	for i, val in enumerate(AB):
		a, b = val
		a, b = a-1, b-1
		for ba in range(max(0, a-2), min(H-2, a+1)):
			for bb in range(max(0, b-2), min(W-2, b+1)):
				if (ba, bb) in ans.keys():
					ans[(ba, bb)] += 1
				else:
					ans[(ba, bb)] = 1

	ans2 = [0] * 10
	total = (H-2) * (W-2)
	t = 0
	for i in ans.values():
		ans2[i] += 1
		t += 1
	ans2[0] = total - t
	for i in range(10):
		print(ans2[i])

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    H, W, N = map(int, input().split())
    cnt = defaultdict(lambda: defaultdict(lambda: 0))
    ans = [0] * 10
    ans[0] = (H-2)*(W-2)
    for _ in range(N):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        for i in range(a-1, a+2):
            for j in range(b-1, b+2):
                if i < 1 or H-1 <= i or j < 1 or W-1 <= j:
                    continue
                c = cnt[i][j]
                ans[c] -= 1
                ans[c+1] += 1
                cnt[i][j] = c+1
    for a in ans:
        print(a)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w,n = [int(_) for _ in input().split(" ")]
d = {}
for _ in range(n):
  a, b = [int(_) for _ in input().split(" ")]
  for i in [-1, 0, 1]:
    for j in [-1, 0, 1]:
      k = (a+i,b+j)
      if k in d:
        d[k] += 1
      else:
        d[k] = 1

ans = {i:0 for i in range(1,10)}
s = 0
for k, v in d.items():
  if 1 < k[0] < h and 1 < k[1] < w:
    ans[v] += 1
    s += 1
ans[0] = (w-2) * (h-2) - s

for _ in range(10):
  print(ans[_])

Submission status: Accepted

Solution code:
h,w,n = map(int,input().split())
coord = [list(map(int,input().split())) for i in range(n)]

num = {}

for i in range(n):
  for j,k in [[0,0],[0,1],[0,-1],[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1]]:
    if not(2<=coord[i][0]+j<=h-1) or not(2<=coord[i][1]+k<=w-1):
      continue
    if not coord[i][0]+j in num:
      num[coord[i][0]+j] = {}
    if not coord[i][1]+k in num[coord[i][0]+j]:
      num[coord[i][0]+j][coord[i][1]+k] = 1
    else:
      num[coord[i][0]+j][coord[i][1]+k] += 1

ans = [0]*10
for i in num:
  for value in num[i].values():
    ans[value] +=1

print((h-2)*(w-2)-sum(ans))
for i in range(1,10):
  print(ans[i])

Submission status: Accepted

Solution code:
h, w, n = map(int, input().split())

if n == 0:
    print((h-2) * (w-2))
    for i in range(9):
        print(0)
    exit()

ab = [tuple(int(x) - 1 for x in input().split()) for _ in range(n)]

p = []

for a, b in ab:
    for x in range(max(0, a-2), min(h-3, a) + 1):
        for y in range(max(0, b-2), min(w-3, b) + 1):
            p.append([x, y])

p.sort()

#print(p)

ans = [0] * 10

c = 1
for i in range(len(p) - 1):
    if p[i] == p[i + 1]:
        c += 1
    else:
        ans[c] += 1
        c = 1
ans[c] += 1

ans[0] = (h - 2) * (w - 2) - sum(ans[1:])

for i in range(10):
    print(ans[i])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C

#D
h,w,n = LI()
dp = [0 for i in range(10)]
dp[0] = (h-2)*(w-2)
q = defaultdict(int)
for i in range(n):
    a,b = LI()
    a -= 1
    b -= 1
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 0 < a+i < h-1 and 0 < b+j < w-1:
                q[(a+i)*w+b+j] += 1
                dp[q[(a+i)*w+b+j]] += 1
                dp[q[(a+i)*w+b+j]-1] -= 1
for i in dp:
    print(i)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
#ABC045D
from collections import defaultdict
h,w,n=map(int,input().split())
ans=defaultdict(int)
for i in range(n):
    a,b=map(int,input().split())
    for j in range(0,-3,-1):
        for k in range(0,-3,-1):
            if a+j>0 and a+j<=h-2 and b+k>0 and b+k<=w-2:
                ans[(a+j,b+k)]+=1
res=[0 for i in range(10)]
for x in ans.values():
    res[x]+=1
res[0]=((h-2)*(w-2))-sum(res[1:])
for i in range(10):
    print(res[i])

Submission status: Accepted

Solution code:
from collections import Counter
from collections import defaultdict as dd

h, w, n = map(int, input().split())
d = dd(int)

for _ in range(n):
  a, b = map(int, input().split())
  for i in range(3):
    for j in range(3):
      if a-i>0 and b-j>0 and a-i<=h-2 and b-j<=w-2:
        d[(a-i, b-j)] += 1
d = dict(d)
con = Counter(d.values())
con[0] = (h-2)*(w-2) - sum(con.values())
for i in range(10):
  print(con[i])

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W, N] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    b_list = []
    b_set = set([])
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [int(input_raw[0]) - 1, int(input_raw[1]) - 1]
        #b_list.append((a, b))
        b_set.add((a, b))

    black_count = {}
    for i in range(10):
        black_count[i] = 0



    already_set = set([])
    for m in b_set:
        for x in range(0, -3, -1):
            for y in range(0, -3, -1):
                square_upper_left_x = m[1] + x
                square_upper_left_y = m[0] + y
                if ((square_upper_left_y, square_upper_left_x) not in already_set and
                    square_upper_left_x + 2 < W and
                    square_upper_left_y + 2 < H and
                    square_upper_left_x >= 0 and
                    square_upper_left_y >= 0):
                        already_set.add((square_upper_left_y, square_upper_left_x))
                        count = 0
                        for i in range(3):
                            for j in range(3):
                                if (square_upper_left_y + j, square_upper_left_x + i) in b_set:
                                    count += 1
                        black_count[count] += 1
    s = 0L
    for i in range(1, 10):
        s += black_count[i]
    print (H -2) * (W - 2) - s
    for i in range(1, 10):
        print black_count[i]




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

H, W, N = [int(v) for v in input().split()]

square_list = []
for i in range(N):
    a, b = [int(v) for v in input().split()]
    for p in range(3):
        for q in range(3):
            if 1 <= a-p <= H-2 and 1 <= b - q <= W-2:
                square_list.append((a - p, b - q))

square_cnt = Counter(square_list)
ans = {i: 0 for i in range(10)}
ans[0] = (H-2) * (W-2) - len(square_cnt)
for cnt in square_cnt.values():
    ans[cnt] += 1

for k in sorted(ans.keys()):
    print(ans[k])

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

h,w,n=map(int,input().split())
d=dd(int)
c={i:0 for i in range(10)}

for _ in range(n):
    a,b=map(int,input().split())
    for i in range(3):
        for j in range(3):
            if a-i>0 and b-j>0 and a-i<=h-2 and b-j<=w-2:
                d[(a-i,b-j)]+=1

d=dict(d)
v=0
for i in d.values():
    c[i]+=1
    v+=1
c[0]=(h-2)*(w-2)-v

for i in range(10):
    print(c[i])

Submission status: Accepted

Solution code:
from collections import defaultdict as dd

h,w,n=map(int,input().split())
d=dd(int)
c={i:0 for i in range(10)}

for _ in range(n):
    a,b=map(int,input().split())
    for i in range(3):
        for j in range(3):
            if a-i>0 and b-j>0 and a-i<=h-2 and b-j<=w-2:
                d[(a-i,b-j)]+=1

d=dict(d)
v=0
for i in d.values():
    c[i]+=1
    v+=1
c[0]=(h-2)*(w-2)-v

for i in range(10):
    print(c[i])

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict

h, w, n = map(int, input().split())
dic = defaultdict(int)
for _ in range(n):
    a, b = map(int, input().split())
    for y in range(a - 2, a + 1):
        for x in range(b - 2, b + 1):
            if 1 <= y <= h - 2 and 1 <= x <= w - 2:
                dic[(x, y)] += 1
counter = Counter(dic.values())
cntSum = (w - 2) * (h - 2)
counter[0] = cntSum - sum(counter.values())
for k in range(10):
    print(counter[k])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

"""
参考：http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf
・各点が影響を与える9か所の正方形をメモしておく。
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W, N = MAP()
# その黒い点が含まれる正方形の左上座標を持っておく
xy = []
for i in range(N):
    a, b = MAP()
    a -= 1
    b -= 1
    for j in range(3):
        for k in range(3):
            # 3*3の正方形を作れない座標は除く
            if 0 <= a-j < H-2 and 0 <= b-k < W-2:
                xy.append((a-j, b-k))
# 各座標の出現数を集計
c = Counter(xy)
# 0以外はこの集計結果から集められる
ans = [0] * 10
for k, v in c.items():
    ans[v] += 1
# 黒い点が0個の正方形の数 = 候補となりうる全正方形の数 - 黒い点が1個でも出現した正方形の数
ans[0] = (H-2)*(W-2) - len(c)

for num in ans:
    print(num)

Submission status: Accepted

Solution code:
from collections import Counter


def solve(H, W, N, ABs):
    total = (H - 2) * (W - 2)
    points = {}
    for a, b in ABs:
        a -= 1
        b -= 1
        for i in [-1, 0, 1]:
            for j in [-1, 0, 1]:
                if 0 < a + i < H - 1 and 0 < b + j < W - 1:
                    d = (a + i, b + j)
                    if d not in points:
                        points[d] = 0
                    points[d] += 1
    c = Counter([v for v in points.values()])
    ans = [total - len(points)] + [c[f] if f in c else 0 for f in range(1, 10)]
    return "\n".join([str(a) for a in ans])

if __name__ == "__main__":
    H, W, N = map(int, input().split(" "))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(H, W, N, ABs))

Submission status: Accepted

Solution code:
from collections import defaultdict
H,W,N=map(int,input().split())
ans=[0 for i in range(10)]

data=defaultdict(int)
def check(a,b):
    if a>0 and a<H-1 and b>0 and b<W-1:return True
    else:return False

def count(a,b):
    for i in range(a-2,a+1):
        for j in range(b-2,b+1):
            if check(i,j):
                x=(i,j)
                data[x]+=1
                
for k in range(N):
    a,b=map(int,input().split())
    count(a,b)

for v in data.values():
    ans[v]+=1

ans[0]=(H-2)*(W-2)-sum(ans[1:])
for i in range(10):
    print(ans[i])
    
#http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf
#https://atcoder.jp/contests/abc045/submissions/4024831
#https://atcoder.jp/contests/abc045/submissions/4017890

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
H, W, N = map(int, input().split())
D = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for y in range(3):
        for x in range(3):
            if 0 < a - y <= H - 2 and 0 < b - x <= W - 2:
                D[(a - y, b - x)] += 1

C = Counter(D.values())
SUM = sum(C.values())

print((H - 2) * (W - 2) - SUM)
for i in range(1, 10):
    print(C[i])

Submission status: Accepted

Solution code:
H, W, N = map(int, input().split())
ab = []
for i in range(N):
    a, b = map(int, input().split())
    ab.append((a - 1, b - 1))

comb_map = {}


for a, b in ab:
    for k in range(3):
        for m in range(3):
            if 0 <= a - k < H - 2 and 0 <= b - m < W - 2:
                if (a-k, b-m) in comb_map.keys():
                    comb_map[(a - k, b - m)] += 1
                else:
                    comb_map[(a - k, b - m)] = 1

count = [0 for _ in range(10)]

for v in comb_map.values():
    count[v] += 1

count[0] = (H - 2) * (W - 2) - sum(count[1:])

for c in count:
    print(c)

Submission status: Accepted

Solution code:
import itertools
H, W, N = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N)]

memo = {}
for a, b in AB:
    #0-indexed
    a -= 1
    b -= 1
    for na, nb in itertools.product(range(a - 2, a + 1), range(b - 2, b + 1)):
        if na in range(H - 2) and nb in range(W - 2):
            memo[na + H * nb] = memo.get(na + H * nb, 0) + 1
result = [0] * 10
for k, v in memo.items():
    result[v] += 1
result[0] = (H - 2) * (W - 2) - sum(result)
[print(_) for _ in result]

Submission status: Accepted

Solution code:
H,W,N = map(int,input().split())
dic = {}
for i in range(N):
    a,b = map(int,input().split())
    for dh in range(3):
        for dw in range(3):
            if 0<a-dh<=H-2 and 0<b-dw<=W-2:
                if (a-dh,b-dw) not in dic.keys():
                    dic[(a-dh,b-dw)] = 1
                else:
                    dic[(a-dh,b-dw)] += 1

Ans = [0]*10
total = 0
for v in dic.values():
    Ans[v] += 1
    total += 1

Ans[0] = (H-2)*(W-2) - total

for ans in Ans:
    print(ans)

Submission status: Accepted

Solution code:
import collections

h, w, n = [int(i) for i in input().split()]
s = [tuple(int(i) for i in input().split()) for j in range(n)]

def dictadd(d, si):
    dc = d
    for i in range(si[0]-2, si[0]+1):
        if 1 <= i <= h-2:
            for j in range(si[1]-2, si[1]+1):
                if 1 <= j <= w-2:
                    dc[(i, j)] += 1
    return dc


d = collections.defaultdict(lambda: 0)
dc = d

for i in s:
    dc = dictadd(dc, i)

dcv = list(dc.values())
ans = []
tot = 0

for i in range(1, 10):
    x = dcv.count(i)
    ans.append(x)
    tot += x

z = (w-2)*(h-2)-tot

print(z)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import collections

h, w, n = [int(i) for i in input().split()]
s = [tuple(int(i) for i in input().split()) for j in range(n)]

def dictadd(d, si):
    dc = d
    for i in range(si[0]-2, si[0]+1):
        if 1 <= i <= h-2:
            for j in range(si[1]-2, si[1]+1):
                if 1 <= j <= w-2:
                    dc[(i, j)] += 1
    return dc


d = collections.defaultdict(lambda: 0)
dc = d

for i in s:
    dc = dictadd(dc, i)

dcv = list(dc.values())
ans = collections.defaultdict(lambda: 0)
tot = 0

for i in range(1, 10):
    ans[i] += dcv.count(i)
    tot += dcv.count(i)

ans[0] = (w-2)*(h-2)-tot


for i in range(0, 10):
    print(ans[i])

Submission status: Accepted

Solution code:
# O(N)
import collections
H, W, N = map(int, input().split())
table = collections.defaultdict(int) # (left, top) of 3x3 block => black count
for i in range(N):
    a, b = map(int, input().split())
    for yy in range(3):
        for xx in range(3):
            y = a - 1 - yy
            x = b - 1 - xx
            if 0 <= y and y + 2 < H and 0 <= x and x + 2 < W:
                table[(y, x)] += 1
counts = [0] * 10
for v in table.values():
    counts[v] += 1
counts[0] = (H - 2) * (W - 2) - sum(counts)
for c in counts:
    print(c)

Submission status: Accepted

Solution code:
from collections import defaultdict

Dic = defaultdict(int)
H, W, N = map(int, input().split())
ans = [0]*10

for i in range(N):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    for dx in range(-1, 2):
        for dy in range(-1, 2):
            if 1 <= a + dy <= H-2 and 1 <= b + dx <= W-2:
                Dic[(a+dy, b+dx)] += 1

for i in Dic:
    ans[Dic[i]] += 1
ans[0] = (H-2)*(W-2) - sum(ans)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
H, W, N = map(int, input().split())
 
Dic = {}
for i in range(N):
    a, b = map(int, input().split())
    for j in range(3):
        for k in range(3):
            if 1 <= a-j <= H-2 and 1 <= b-k <= W-2:
                if (a-j, b-k) in Dic:
                    Dic[(a-j, b-k)] += 1
                else:
                    Dic[(a-j, b-k)] = 1
                    
Painted = [0 for _ in range(10)]
colered = 0

for i in Dic:
    Painted[Dic[i]] += 1
    colered += 1

#最後に黒が一か所も塗られていない場所を、総和-(1ヵ所以上黒)として求める
Painted[0] = (H-2) * (W-2) - colered
 
for i in Painted:
    print(i)

Submission status: Accepted

Solution code:
H,W,N=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]

from collections import defaultdict
from collections import Counter

ANS = defaultdict(int)

for a,b in AB:
    for i in [a-1,a,a+1]:
        for j in [b-1,b,b+1]:
            if 2<=i<H and 2<=j<W:
                ANS[(i,j)]+=1

counter=Counter(ANS.values())
ANSLIST=[0]*10
for c in counter:
    ANSLIST[c]=counter[c]
ANSLIST[0]=(H-2)*(W-2)-sum(counter.values())

for a in ANSLIST:
    print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict
H,W,N=map(int,input().split())
d=defaultdict(int)
for n in range(N):
  y,x=map(int,input().split())
  for i in range(3):
    for j in range(3):
      if W-3>=x+i-3>=0 and H-3>=y+j-3>=0:
        d[(x+i-3,y+j-3)]+=1
ans=[0]*10
S=0
for t,t_num in d.items():
  ans[t_num]+=1
  S+=1
ans[0]=(H-2)*(W-2)-S
for i in range(10):
  print(ans[i])

Submission status: Accepted

Solution code:
H, W, N = map(int, raw_input().split())
p = set()
for i in range(N):
  a, b = map(int, raw_input().split())
  p.add((a,b))
r = [0]*10
c = set()
for a, b in p:
  for y0 in range(a-2, a+1):
    for x0 in range(b-2, b+1):
      if x0<1 or x0+2>W or y0<1 or y0+2>H or (y0,x0) in c:
        continue
      c.add((y0,x0))
      s = 0
      for y in range(y0, y0+3):
        for x in range(x0, x0+3):
          if (y,x) in p:
            s += 1
      r[s] += 1
print (H-2)*(W-2)-sum(r[1:10])
for ri in r[1:10]:
  print ri

Submission status: Accepted

Solution code:
from collections import defaultdict
H, W, N = map(int, input().split())
P = [0] * 10
P[0] = (H - 2) * (W - 2)
G = defaultdict(lambda: defaultdict(int))
for i in range(N):
  a, b = map(int, input().split())
  for i in range(max(a - 3, 0), min(a, H - 2)):
    for j in range(max(b - 3, 0), min(b, W - 2)):
      p = G[i][j]
      P[p] -= 1
      P[p + 1] += 1
      G[i][j] += 1
for i in range(10):
  print(P[i])

Submission status: Accepted

Solution code:
H,W,N=list(map(int,input().split()))

dic={}
for _ in range(N):
    a,b=list(map(int,input().split()))
    for i in range(-1,2):
        for j in range(-1,2):
            if (a+i)<=1 or b+j<=1 or a+i>=H or b+j >=W:
                continue
            s=(a+i)*W+b+j
            if dic.get(s,0)==0:
                dic[s]=1
            else:
                dic[s]+=1
arr=[0 for i in range(10)]
for v in dic.values():
    arr[v]+=1
arr[0]=(H-2)*(W-2)-sum(arr)
for x in arr:
    print(x)

Submission status: Accepted

Solution code:
# ABC 045 D
from collections import Counter
H, W, N = map(int, input().split())
L = []
for k in range(N):
    a, b = map(int, input().split())
    for k in range(3):
        for l in range(3):
            if 1 <= a-k <= H-2  and 1 <= b-l <= W-2:
                L.append((a-k,b-l))

M = Counter(L)
A = [0 for k in range(10)]
s = 0
for e in M:
    A[M[e]] += 1
    s += 1

A[0] = (H-2)*(W-2)-s
for a in A:
    print(a)

Submission status: Accepted

Solution code:
from collections import defaultdict
Delta = [-1,0,1]
d = defaultdict(lambda:0)
def paint(d,x,y):
    for dx in Delta:
        for dy in Delta:
            d[(x+dx,y+dy)] += 1
H,W,N = map(int,input().split())
for i in range(N):
    a,b = map(int,input().split())
    paint(d,a,b)
ans = defaultdict(lambda:0)
for x,y in d.keys():
    if 2<=x<=H-1 and 2<=y<=W-1:
        ans[d[(x,y)]] += 1
ans0 = (H-2)*(W-2)
for i in range(10):
    ans0 -= ans[i]
ans[0] = ans0
for i in range(10):
    print(ans[i])

Submission status: Accepted

Solution code:
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
x=[]
di=[0,0,0,1,1,1,2,2,2]
dj=[0,1,2,0,1,2,0,1,2]
from collections import defaultdict,Counter
x=defaultdict(int)
for a,b in ab:
    for ti,tj in zip(di,dj):
        if 3<=a+ti<=h and 3<=b+tj<=w:
            x[(a+ti,b+tj)]+=1

c=Counter(x.values())
print((h-2)*(w-2)-sum(c.values()))
for i in range(1,10):
    print(c[i])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict, Counter

dic = defaultdict(int)

h,w,n = li()

dhs = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
dws = [-1, 0, 1,-1, 0, 1,-1, 0, 1]

for _ in range(n):
    r,c = li()
    for dh, dw in zip(dhs, dws):
        if 1 < r+dh < h and 1 < c+dw < w:
            dic[(r+dh, c+dw)] += 1
            
vals = Counter(dic.values())

for i in range(10):
    if i == 0:
        print((h-2)*(w-2) - sum(vals.values()))
    else:
        print(vals[i])

Submission status: Accepted

Solution code:
from collections import defaultdict
H, W, N = map(int, input().split())
dic = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    for j in range(3):
        for k in range(3):
            if 1 <= a + j - 2 <= H - 2 and 1 <= b + k - 2 <= W - 2:
                dic[(a + j - 2, b + k - 2)] += 1

rec = [0] * 10
for k in dic.values():
    rec[k] += 1

rec[0] = (H - 2) * (W - 2) - sum(rec)
for i in rec:
    print(i)

Submission status: Accepted

Solution code:
import sys
def 解():
    iH,iW,iN = [int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    iMax = (iH - 2) * (iW -2)
    #print (iMax)

    dC={}
    for i in range(10):
        dC[i]=0

    #愚直 無理 つらい
    #for i in range(1,iH -1):
    #   for j in range(1,iW-1):
    #       tmp = 0
    #       for a in aD:
    #           if j<= a[1] <=j+2 and i<= a[0] <= i+2:
    #               tmp +=1
    #       dC[tmp] +=1

    #なんというか、面倒くさくなって解法みても
    #面倒くさがらずやれとしか書いてなくてつらい
    dM = {}
    for a in aD:
        y=a[0]
        x=a[1]
        for aP in [(y-2,x-2),(y-2,x-1),(y-2,x),(y-1,x-2),(y-1,x-1),(y-1,x),(y,x-2),(y,x-1),(y,x)]:
            if 0< aP[0]<iH-1 and 0 < aP[1] < iW-1:
                iP = aP[0]*iW + aP[1]
                if iP in dM: #もう最初から足したったらええんや
                    dM[iP] += 1
                else:
                    dM[iP] = 1
    for i in dM:
        dC[dM[i]]+=1

    iAllBM=0
    for i in range(1,10):
        iAllBM+=dC[i]
    dC[0] = iMax -iAllBM #点のないマス0は引き算で出せる

    for i in range(10):
        print(dC[i])
解()

Submission status: Accepted

Solution code:
import sys
iH,iW,iN = [int(_) for _ in input().split()]
aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

iMax = (iH - 2) * (iW -2)
#print (iMax)

dC={}
for i in range(10):
    dC[i]=0

#愚直 無理 つらい
#for i in range(1,iH -1):
#   for j in range(1,iW-1):
#       tmp = 0
#       for a in aD:
#           if j<= a[1] <=j+2 and i<= a[0] <= i+2:
#               tmp +=1
#       dC[tmp] +=1
dM = {}
for a in aD:
    y=a[0]
    x=a[1]
    for aP in [(y-2,x-2),(y-2,x-1),(y-2,x),(y-1,x-2),(y-1,x-1),(y-1,x),(y,x-2),(y,x-1),(y,x)]:
        if 0< aP[0]<iH-1 and 0 < aP[1] < iW-1:
            iP = aP[0]*iW + aP[1]
            if iP in dM:
                dM[iP] += 1
            else:
                dM[iP] = 1
for i in dM:
    dC[dM[i]]+=1

iAllBM=0
for i in range(1,10):
    iAllBM+=dC[i]
dC[0] = iMax -iAllBM

for i in range(10):
    print(dC[i])

Submission status: Accepted

Solution code:
H, W, N = map(int, input().split())

Dic = {}
for i in range(N):
    a, b = map(int, input().split())
    for j in range(3):
        for k in range(3):
            if 1 <= a-j <= H-2 and 1 <= b-k <= W-2:
                if (a-j, b-k) in Dic:
                    Dic[(a-j, b-k)] += 1
                else:
                    Dic[(a-j, b-k)] = 1

Painted = [0 for _ in range(10)]
colered = 0
for i in Dic:
    Painted[Dic[i]] += 1
    colered += 1
Painted[0] = (H-2) * (W-2) - colered

for i in Painted:
    print(i)

Submission status: Accepted

Solution code:
h, w, n = map(int, input().split())

c = dict()
for _ in range(n):
    a, b = map(int, input().split())
    for da in -1, 0, 1:
        for db in -1, 0, 1:
            if (2 <= a + da <= h - 1) and (2 <= b + db <= w - 1):
                c[(a + da, b + db)] = c.get((a + da, b + db), 0) + 1

#print(c)
ans_cnt = [0 for _ in range(10)]
for cnt in c.values():
    ans_cnt[cnt] += 1

ans_cnt[0] = ((h - 1) - 2 + 1) * ((w - 1) - 2 + 1) - sum((1 for cnt in c.values() if cnt > 0))

for i in range(10):
    print(ans_cnt[i])

Submission status: Accepted

Solution code:
from collections import defaultdict,Counter
d=defaultdict(int)
h,w,n=map(int,input().split())
for _ in range(n):
  p,q=map(int,input().split())
  for x in [q-2,q-1,q]:
    for y in [p-2,p-1,p]:
      if 1<=y<=h-2 and 1<=x<=w-2:
        d[(x,y)]+=1

cnt=Counter(d.values())
print((h-2)*(w-2)-sum(cnt.values()))
for i in range(1,10):
  print(cnt[i])

Submission status: Accepted

Solution code:
from collections import defaultdict
h,w,n = map(int,input().split())
x = []
for i in range(n):
  x.append(list(map(int,input().split())))
d = defaultdict(int)
for i in x:
  a = []
  for j in range(3):
    for k in range(3):
      if (i[0]-j-1>=0 and i[1]-k-1 >= 0 and i[0]-j-1<=h-3 and i[1]-k-1 <= w-3):
        a.append((i[0]-j-1,i[1]-k-1))
  for j in a:
    d[j] += 1
a = list(d.values())
ans = [0]*10
ans[0] = (h-2)*(w-2)-len(a)
for i in a:
  ans[i] += 1
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
import sys
sdin = sys.stdin.readline

from collections import defaultdict, Counter

h, w, n = map(int, sdin().split())
ab = []
for _ in range(n):
    ab.append(tuple(map(int, sdin().split())))
    
# フィールドを作って塗る
field = defaultdict(int)
grid_num = (h-2)*(w-2)

x = [-1,-1,-1, 0, 0, 0, 1, 1, 1]
y = [-1, 0, 1,-1, 0, 1,-1, 0, 1]

for a, b in ab:
    for dx,dy in zip(x, y):
        if a+dx > 1 and a+dx < h and b+dy > 1 and b+dy < w:
            field[(a+dx, b+dy)] += 1


# 数え上げる
cnt = Counter(field.values())

for j in range(10):
    if j == 0:
        print(grid_num - sum(cnt.values()))
    else:
        print(cnt[j])

Submission status: Accepted

Solution code:
from collections import Counter
H,W,N = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

blacks = Counter()
for y,x in src:
    for i in range(-1,2):
        if not 0 <= y+i < H: continue
        for j in range(-1,2):
            if not 0 <= x+j < W: continue
            blacks[(x+j, y+i)] += 1

ans = [0] * 10
for (x,y),v in blacks.items():
    if x<2 or y<2: continue
    ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])
print(*ans,sep='\n')