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:
from itertools import product
from collections import Counter

H, W, N = map(int, input().split())
V = set([tuple(map(int, input().split())) for _ in range(N)])
D = tuple(product((-1, 0, 1), repeat=2))

A = set()
cnt = Counter()
for a, b in V:
    for h, w in D:
        if 2 <= a + h <= H - 1 and 2 <= b + w <= W - 1:
            cnt[(a + h, b + w)] += 1

ans = [0] * 10
for c in cnt.values():
    ans[c] += 1

ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

from collections import defaultdict

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

dic = defaultdict(int)
lst = [0] * (10)
lst[0] = (H - 2) * (W - 2)

for _ in range(N):
    a, b = map(int, input().split())
    for i in range(-1, 2):
        for j in range(-1, 2):
            if 2 <= (a + i) <= (H - 1):
                if 2 <= (b + j) <= (W - 1):
                    tmp = dic[(a + i, b + j)]
                    lst[tmp] -= 1
                    lst[tmp + 1] += 1
                    dic[((a + i, b + j))] += 1

print (*lst, sep = '\n')

Submission status: Accepted

Solution code:
h,w,n=map(int,input().split())
ls=[]
while True:
    try:
        ls.append(tuple(map(int,input().split())))
    except EOFError:break
check={}
count={0:(h-2)*(w-2)}
for i in range(1,10):
    count[i]=0
for tup in ls:
    for i in range(-2,1):
        for j in range(-2,1):
            if(tup[0]+i>0 and tup[0]+i<h-1 and tup[1]+j>0 and tup[1]+j<w-1):
              try:
                check[(tup[0]+i,tup[1]+j)]+=1
              except KeyError:
                check[(tup[0]+i,tup[1]+j)]=1
              index=check[(tup[0]+i,tup[1]+j)]
              count[index]+=1
              count[index-1]-=1
for i in range(10):
    print("{}".format(count[i]))

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
H,W,N=map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
tpl = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
edge_WtoB = dd(int)
edge_BtoB = dd(int)
node_B = set(ab)
# node_W = set()
res = dd(int)
# 今見てるマスが黒
for a,b in ab:
    for s,t in tpl:
        tgt = (a+s,b+t)
        # 隣接マスも黒
        if tgt in node_B:
            if not (1 < a < H and 1 < b < W):
                continue
            edge_BtoB[(a,b)] += 1
        # 隣接マスは白
        else:
            if not (1 < a + s < H and 1 < b + t < W):
                continue
            edge_WtoB[tgt] += 1
            # node_W.add(tgt)
for val in edge_WtoB.values():
    res[val] += 1
for val in edge_BtoB.values():
    res[val] += 1
zero = (H-2)*(W-2)
for j in range(1,10):
    zero -= res[j]
res[0] = zero
for j in range(10):
    print(res[j])

Submission status: Accepted

Solution code:
h, w, n = map(int, input().split())
square = dict()
for i in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for x in range(b-2,b+1,1):
        for y in range(a-2,a+1,1):
            if 0 <= y <= (h - 3) and 0 <= x <= (w - 3) :
                if (x,y) in square:
                    square[(x,y)] += 1
                else:
                    square[(x,y)] = 1
ans = [0 for i in range(10)]
for i in square.values():
    ans[i] += 1
ans[0] = (h - 2) * (w - 2) - sum(ans)
for i in range(10):
    print(ans[i])

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter

H, W, N = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]

d = defaultdict(int)
for a, b in ab:
  for da in range(3):
    aa = a - da
    if aa < 1 or H < aa + 2:
      continue
    for db in range(3):
      bb = b - db
      if bb < 1 or W < bb + 2:
        continue
      
      d[(aa, bb)] += 1

num = [0] * 10
num[0] = (H - 2) * (W - 2)
count_n = Counter(list(d.values()))
for i in range(1, 10):
  n = count_n[i]
  num[i] += n
  num[0] -= n

print(*num, sep='\n')

Submission status: Accepted

Solution code:
H, W, N = map(int, input().split())
ab = set(tuple(map(int, input().split())) for i in range(N))

dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]}
num_all = (H - 2) * (W - 2)
num = [0] * 10
for a, b in ab:
  for i in range(3):
    Da = dxy[i]
    for j in range(3):
      n = 0
      flag = False
      Db = dxy[j]
      for da in Da:
        aa = a + da
        for db in Db:
          bb = b + db
          if aa < 1 or H < aa or bb < 1 or W < bb:
            flag = True
            break
          if (aa, bb) in ab:
            n += 1
        if flag:
          break
      if flag:
        continue
      num[n] += 1

for i in range(2, 10):
  num[i] //= i

num[0] = num_all - sum(num[1:])
print(*num, sep='\n')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    H,W,N=map(int,input().split())
    s=set()
    for i in range(N):
        s.add(tuple(map(int1,input().split())))
    ans=[0]*10
    used=set()
    for y,x in s:
        for dy in range(-1,2):
            for dx in range(-1,2):
                if 0>y+dy-1 or y+dy+1>=H or 0>x+dx-1 or x+dx+1>=W or (y+dy,x+dx) in used:
                    continue
                tmp=0
                used.add((y+dy,x+dx))
                for ddy in range(-1,2):
                    for ddx in range(-1,2):
                        if (y+dy+ddy,x+dx+ddx) in s:
                            tmp+=1
                ans[tmp]+=1
    ans[0]=(H-2)*(W-2)-sum(ans[1:])
    for row in ans:
        print(row)
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict

H, W, N = map(int, input().split())
dic = defaultdict(int)
dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
dy = [1, 1, 1, 0, 0, 0, -1, -1, -1]
for i in range(N):
    y, x = map(int, input().split())
    for j in range(9):
        ny, nx = y+dy[j], x+dx[j]
        if not 1 < ny < H: continue
        if not 1 < nx < W: continue
        dic[str(ny)+":"+str(nx)] += 1
count = [0]*10
tot = (H-3+1)*(W-3+1)
count[0] = tot-len(dic.keys())
for k,v in dic.items():
    count[v] += 1
for c in count:
    print(c)

Submission status: Accepted

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    matrix.append([x-1,y-1])
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + ' '  +str(nowy)
            if name in cand : cand[name] += 1
            else: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
  ans[x] +=1
ans[0] =tmp - len(cand)
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + ' '  +str(nowy)
            if name in cand : cand[name] += 1
            else: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + ' '  +str(nowy)
            if name in cand : cand[name] += 1
            else: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + ' '  +str(nowy)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + 'sakoda'  +str(nowy)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) +"hoge" +str(nowy)
            try: cand[name] += 1
            except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
from collections import Counter

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

black_count = {}

for _ in range(n):
    a,b = map(int,input().split())
    for dx in (-1,0,1):
        for dy in (-1,0,1):
            y = a+dy
            x = b+dx
            if 2<=y<=h-1 and 2<=x<=w-1:
                black_count[(y,x)] = black_count.get((y,x),0) + 1

ans = Counter(black_count.values())
ans[0] = (h-2) * (w-2) - sum(ans.values())
for i in range(10):
    print(ans.get(i,0))

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter

H, W, N = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

ctr = defaultdict(int)
for a, b in X:
    for k in range(3):
        for l in range(3):
            if 1 <= a - k <= H - 2 and 1 <= b - l <= W - 2:
                ctr[(a - k, b - l)] += 1

d = Counter(ctr.values())
for i in range(10):
    if i == 0:
        print((H - 2) * (W - 2) - sum(d.values()))
    else:
        print(d[i])

Submission status: Accepted

Solution code:
h, w, n = [int(i) for i in input().split()]
A = [0 for _ in range(n)]
B = [0 for _ in range(n)]
cnt = {}


for i in range(n):
	a, b = [int(j) for j in input().split()]
	if a > 1 and b > 1 and a < h and b < w:
		if "{} {}".format(a, b) not in cnt.keys():
			cnt["{} {}".format(a, b)] = 0
		cnt["{} {}".format(a, b)] += 1
	if a > 2 and b > 2 and a <= h and b <= w:	
		if "{} {}".format(a-1, b-1) not in cnt.keys():
			cnt["{} {}".format(a-1, b-1)] = 0
		cnt["{} {}".format(a-1, b-1)] += 1
	if a > 2 and b > 1 and a <= h and b < w:	
		if "{} {}".format(a-1, b) not in cnt.keys():
			cnt["{} {}".format(a-1, b)] = 0
		cnt["{} {}".format(a-1, b)] += 1
	if a > 2 and b > 0 and a <= h and b < w-1:
		if "{} {}".format(a-1, b+1) not in cnt.keys():
			cnt["{} {}".format(a-1, b+1)] = 0
		cnt["{} {}".format(a-1, b+1)] += 1
	if a > 1 and b > 2 and a < h and b <= w:
		if "{} {}".format(a, b-1) not in cnt.keys():
			cnt["{} {}".format(a, b-1)] = 0
		cnt["{} {}".format(a, b-1)] += 1
	if a > 0 and b > 0 and a < h-1 and b < w-1:
		if "{} {}".format(a+1, b+1) not in cnt.keys():
			cnt["{} {}".format(a+1, b+1)] = 0
		cnt["{} {}".format(a+1, b+1)] += 1
	if a > 0 and b > 1 and a < h-1 and b < w:
		if "{} {}".format(a+1, b) not in cnt.keys():
			cnt["{} {}".format(a+1, b)] = 0
		cnt["{} {}".format(a+1, b)] += 1
	if a > 1 and b > 0 and a < h and b < w-1:
		if "{} {}".format(a, b+1) not in cnt.keys():
			cnt["{} {}".format(a, b+1)] = 0
		cnt["{} {}".format(a, b+1)] += 1
	if a > 0 and b > 2 and a < h-1 and b <= w:
		if "{} {}".format(a+1, b-1) not in cnt.keys():
			cnt["{} {}".format(a+1, b-1)] = 0
		cnt["{} {}".format(a+1, b-1)] += 1

count = [0 for i in range(10)]
for i in cnt.values():
	count[i] += 1
count[0] =  (h-2)*(w-2) - len(cnt)

for i in count:
	print(i)

Submission status: Accepted

Solution code:
import math
import fractions
import sys
input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################


h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
    t = list(map(int, input().split()))
    for j in range(3):
        for k in range(3):
            painted.append([t[0]-2+j, t[1]-2+k])
    
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])

p2 = []

for i in painted:
    if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
        p2.append(i)

#print(p2)
ans = [0 for i in range(10)]
chain=0
if(len(p2)>0):
    before = p2[0]
    chain = 1
for ii in range(len(p2)-1):
    i = ii+1
    if(p2[i][0] == before[0] and p2[i][1] == before[1]):
        chain += 1
    else:
        ans[chain]+=1
        chain=1
        before[0],before[1] = p2[i]
if(len(p2)>0): ans[chain]+=1

ans[0] = (h-2)*(w-2) - sum(ans[1:])
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

H, W, N = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
    x, y = map(int, input().split())
    for i in range(-2, 1):
        if 1 <= x + i <= H - 2:
            for j in range(-2, 1):
                if 1 <= y + j <= W - 2:
                    d[(x + i, y + j)] += 1

c = Counter(d.values())
zero = (H - 2) * (W - 2) - len(d)
print(zero)
for i in range(1, 10):
    print(c[i])

Submission status: Accepted

Solution code:
def main():
    h, w, n = map(int, input().split())
    dic = {}
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(max(2, a-1), min(h, a+2)):
            for j in range(max(2, b-1), min(w, b+2)):
                if (i, j) in dic:
                    dic[(i, j)] += 1
                else:
                    dic[(i, j)] = 1
    ans = [0]*10
    cnt = 0
    for v in dic.values():
        ans[v] += 1
        cnt += 1
    ans[0] = (h-2)*(w-2) - cnt
    for i in range(10):
        print(ans[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
h,w,n = map(int, input().split())
ab = [tuple(map(int, input().split())) for i in range(n)]
J = [0] * 10
black = dict()
for i in ab:
  black[i] = 1
for a,b in ab:
  for x in range(max(0,3-a),min(3,h+1-a)):
    for y in range(max(0,3-b),min(3,w+1-b)):
      j = 0
      for X in range(a+x-2,a+x+1):
        for Y in range(b+y-2,b+y+1):
          if (X,Y) in black:
            j += 1
      J[j] += 1
for i in range(2,10):
  J[i] //= i
ALL = (h-2) * (w-2)
J[0] = ALL - sum(J[1:])
for i in J:
  print(i)

Submission status: Accepted

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

h,w,n = map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(n)]

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

black = set(ab)
checked = set()

for tmp in ab:
    a,b = tmp
    y0 = max(1,a-2)
    y1 = min(h,a+2)-1
    x0 = max(1,b-2)
    x1 = min(w,b+2)-1
    for i in range(x0,x1):
        for j in range(y0,y1):
            if ((j,i) in checked):
                continue
            tmp = 0
            for x in range(3):
                for y in range(3):
                    tmp += ((j+y,i+x) in black)
            ans[0] -= 1
            ans[tmp] += 1
            checked.add((j,i))

print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
def main():
    import sys
    from collections import Counter
    # readline = sys.stdin.readline
    readlines = sys.stdin.readlines
    H, W, N = map(int, input().split())
    P = set()
    for s in readlines():
        a, b = map(int, s.split())
        a -= 1; b -= 1
        P.add((a, b))

    cnt = Counter()
    for a, b in P:
        for oa in range(a - 2, a + 1):
            for ob in range(b - 2, b + 1):
                if 0 <= oa <= H - 3 and 0 <= ob <= W - 3:
                    cnt[(oa, ob)] += 1
    ans = Counter(cnt.values())
    ans[0] = (H - 2) * (W - 2) - sum(ans.values())

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    # readline = sys.stdin.readline
    readlines = sys.stdin.readlines
    H, W, N = map(int, input().split())
    grid = {}
    P = set()
    for s in readlines():
        a, b = map(int, s.split())
        a -= 1; b -= 1
        if a in grid:
            grid[a].add(b)
        else:
            grid[a] = set([b])
        P.add((a, b))

    ans = [0] * 10
    done = set()
    for a, b in P:
        for oa in range(a - 2, a + 1):
            for ob in range(b - 2, b + 1):
                if 0 <= oa <= H - 3 and 0 <= ob <= W - 3 and (oa, ob) not in done:
                    tmp = 0
                    for i in range(3):
                        for j in range(3):
                            na = oa + i
                            nb = ob + j
                            if (na, nb) in P:
                                tmp += 1
                    ans[tmp] += 1
                    done.add((oa, ob))
    
    ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

    print(*ans, sep='\n')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

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

L = []
for _ in range(N):
    a,b = map(int, input().split())
    for i in range(3):
        if a+i-1 <= 1 or a+i-1 >= H: continue
        for j in range(3):
            if b+j-1 <= 1 or b+j-1 >= W: continue
            L.append((a+i-1, b+j-1))
L.sort()
C = Counter(L)

ans = [0]*10
for value in C.values():
    ans[value] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])

print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
# solution
import io
from collections import Counter

nim, mike, kite, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    C.update(
        (a - i, b - j)
        for i, j in move
        if 2 <= a - i <= nim - 1 and 2 <= b - j <= mike - 1
    )

D = Counter(v for _, v in C.items())

print((nim - 2) * (mike - 2) - sum(D.values()))
for i in range(1, 10):
    print(D[i])

Submission status: Accepted

Solution code:
H, W, N = input().split(" ")
H, W, N = int(H), int(W), int(N)
A = []
for i in range(N):
    A.append([int(j) for j in input().split(" ")])


import itertools
from collections import defaultdict, Counter

c = defaultdict(int)
for a, b in A:
    # そのセルを含む正方形の中心を記録
    for dx,dy in itertools.product([-1,0,1],repeat = 2):
        aa = a + dx
        bb = b + dy
        if 2 <= aa <= H-1 and 2 <= bb <= W-1:
            c[(aa,bb)] += 1
            
result = Counter(c.values())
result[0] = (H-2)*(W-2) - sum(result.values())
 
for j in range(10):
    print(result[j])

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.readline

H,W,N=map(int,input().split())
point=set([])
ans=[0 for i in range(0,10)]
ans[0]=(H-2)*(W-2)

def black(x,y):
    ans=0
    if (x-1,y-1) in point:
        ans+=1
    if (x-1,y) in point:
        ans+=1
    if (x-1,y+1) in point:
        ans+=1

    if (x,y-1) in point:
        ans+=1
    if (x,y) in point:
        ans+=1
    if (x,y+1) in point:
        ans+=1

    if (x+1,y-1) in point:
        ans+=1
    if (x+1,y) in point:
        ans+=1
    if (x+1,y+1) in point:
        ans+=1
        
    return ans

for _ in range(0,N):
    a,b=map(int,input().split())
    if a>2:
        if b>2:
            ss=black(a-1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a-1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a-1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1
    if H>a>1:
        if b>2:
            ss=black(a,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    if H-1>a:
        if b>2:
            ss=black(a+1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1
        if W>b>1:
            ss=black(a+1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a+1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    point.add((a,b))

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

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.readline

H,W,N=map(int,input().split())
point=set([])
ans=[0 for i in range(0,10)]
ans[0]=(H-2)*(W-2)

def black(x,y):
    ans=0
    if x!=1:
        if y!=1:
            if (x-1,y-1) in point:
                ans+=1
        if (x-1,y) in point:
            ans+=1
        if y!=W:
            if (x-1,y+1) in point:
                ans+=1
    if y!=1:
        if (x,y-1) in point:
            ans+=1
    if (x,y) in point:
        ans+=1
    if y!=W:
        if (x,y+1) in point:
            ans+=1
    if x!=H:
        if y!=1:
            if (x+1,y-1) in point:
                ans+=1
        if (x+1,y) in point:
            ans+=1
        if y!=W:
            if (x+1,y+1) in point:
                ans+=1
    return ans

for _ in range(0,N):
    a,b=map(int,input().split())
    if a>2:
        if b>2:
            ss=black(a-1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a-1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a-1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1
    if H>a>1:
        if b>2:
            ss=black(a,b-1)
            ans[ss]-=1
            ans[ss+1]+=1

        if W>b>1:
            ss=black(a,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    if H-1>a:
        if b>2:
            ss=black(a+1,b-1)
            ans[ss]-=1
            ans[ss+1]+=1
        if W>b>1:
            ss=black(a+1,b)
            ans[ss]-=1
            ans[ss+1]+=1

        if W-1>b:
            ss=black(a+1,b+1)
            ans[ss]-=1
            ans[ss+1]+=1

    point.add((a,b))

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W, N = lr()
shift = ((0, 0), (0, 1), (1, 0), (0, -1), (-1, 0), (1, 1), (-1, -1), (-1, 1), (1, -1))

l = []

for n in range(N):
    a, b = lr()
    for s in shift:
        aa = a + s[0] - 1
        bb = b + s[1] - 1
        if aa < 1 or aa > H-2:
            continue
        if bb < 1 or bb > W-2:
            continue
        l.append((aa-1, bb-1))
if len(l) == 0:
    print((H-2) * (W-2))
    [print(0) for _ in range(9)]
    exit(0)
l.sort()
m = {i: 0 for i in range(10)}
pre = l[0]
c = 1
for ll in l[1:]:
    if pre == ll:
        c += 1
    else:
        m[c] += 1
        pre = ll
        c = 1
m[c] += 1
m[0] = (H-2) * (W-2) - sum(m.values())
for v in m.values():
    print(v)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
count = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    for da in range(3):
        for db in range(3):
            na, nb = a - da, b - db
            if 1 <= na <= H - 2 and 1 <= nb <= W - 2:
                count[(na, nb)] += 1
ans = [0] * 10
for k, v in count.items():
    ans[v] += 1
ans[0] = (H-2) * (W-2) - sum(ans)
print(*ans, sep='\n')