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:
h,w,n=map(int,input().split())
d=dict()
def change(a,b):
    global h,w,d
    if 1<=a<h-1 and 1<=b<w-1:
        if (a,b) in d:
            d[(a,b)]+=1
        else:
            d[(a,b)]=1
for i in range(n):
    a,b=map(int,input().split())
    a-=1
    b-=1
    change(a,b)
    change(a-1,b-1)
    change(a-1,b+1)
    change(a+1,b-1)
    change(a+1,b+1)
    change(a-1,b)
    change(a+1,b)
    change(a,b-1)
    change(a,b+1)
ans=[0]*10
ans[0]=(h-2)*(w-2)
#print(d)
for i in d:
    ans[d[i]]+=1
    ans[0]-=1
for i in range(10):
    print(ans[i])

Submission status: Accepted

Solution code:
import sys
sys.stdin.readline

def main():
    H, W, N = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    X = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
    Y = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
    XY = list(zip(X, Y))
    S = {}
    for a, b in AB:
        for x, y in XY:
            k = (a+x, b+y)
            S.setdefault(k, 0)
            S[k] += 1
    ans = [0] * 10
    for (x, y), v in S.items():
        if 1 < x < H and 1 < y < W:
            ans[v] += 1
    ans[0] = (H-2)*(W-2)-sum(ans[1:])
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

from collections import defaultdict

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

counter = defaultdict(int)
for a, b in AB:
  for aa in range(a - 1, a + 2):
    for bb in range(b - 1, b + 2):
      if 2 <= aa <= H - 1 and 2 <= bb <= W - 1:
        counter[(aa, bb)] += 1

answer = [0] * (10)
for (x, y), n in list(counter.items()):
  if n:
    answer[n] += 1
answer[0] = (H - 2) * (W - 2)
for i in range(1, 10):
  answer[0] -= answer[i]
  
for a in answer:
  print(a)

Submission status: Accepted

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

from collections import defaultdict

H, W, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
SIZE = 10 ** 9 + 1

counter = defaultdict(int)
for a, b in AB:
  for aa in range(a - 1, a + 2):
    for bb in range(b - 1, b + 2):
      if 2 <= aa <= H - 1 and 2 <= bb <= W - 1:
        counter[aa * SIZE + bb] += 1

answer = [0] * (10)
for x, n in list(counter.items()):
  if n:
    answer[n] += 1
answer[0] = (H - 2) * (W - 2)
for i in range(1, 10):
  answer[0] -= answer[i]
  
for a in answer:
  print(a)

Submission status: Accepted

Solution code:
dx = [-1,-1,-1,0,0,1,1,1,0]
dy = [-1,0,1,-1,1,-1,0,1,0]
H,W,N = map(int,input().split())
from collections import defaultdict, Counter
d = defaultdict(int)
for i in range(N):
    a,b = map(int,input().split())
    for j in range(9):
        A = a + dy[j]
        B = b + dx[j]
        f = 0
        if 2 <= A <= H-1:
            if 2 <= B <= W-1:
                f = 1
        if f == 1:
            d[(A,B)] += 1
s = 0
c = Counter(d.values())
for i in range(1,10):
    s += c[i]
c[0] = (H-2)*(W-2) - s
for i in range(10):
    print(c[i])

Submission status: Accepted

Solution code:
from itertools import product
from collections import defaultdict, Counter
import sys
input = sys.stdin.readline
h,w,n = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
pls = defaultdict(int)
for x,y in a:
  for arx,ary in product(list(range(x-1,x+2)),list(range(y-1,y+2))):
    if 2<=arx<=h-1 and 2<=ary<=w-1:
      pls[(arx,ary)] += 1
c = Counter(pls.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
input = sys.stdin.readline
from collections import Counter
h,w,n=map(int,input().split())
c=Counter()
for _ in range(n):
    b,a=map(int,input().split())
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 2<=a+i<w and 2<=b+j<h:
                c[a+i,b+j]+=1
#print(c.items())
c2=Counter(c.values())
print((h-2)*(w-2)-sum(c2.values()))
for i in range(1,10):
    print(c2[i])

Submission status: Accepted

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


#
import collections
H, W, N = map(int, input().split(' '))

point_frq_dict = collections.defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split(' '))
    for i in range(3):
        for j in range(3):
            if 0 < a-i < H-1 and 0 < b-j < W-1:
                point_frq_dict[(a-i, b-j)] += 1

ans = [0 for _ in range(10)]
n = 0
for frq in point_frq_dict.values():
    ans[frq] += 1

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

Submission status: Accepted

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

# 黒マス black[y座標] = [x1,x2,...]
black = dict()

# 周囲に黒マスがあるマス
search = set()

for i in range(n):
    a,b = map(int, input().split())
    a-=1
    b-=1
    for x in [-1,0,1]:
        for y in [-1,0,1]:
            if 1<=a+y<h-1 and 1<=b+x<w-1:
                search.add((a+y,b+x))  # タプル。set()内にリストは格納できない。
    try:
        black[a][b]=1
    except:
        black[a]=dict()
        black[a][b]=1


ans = [0]*10
# 探索すべき全マスに対して、周囲の黒マスの数を数える。
for a,b in search:
    p = 0
    for y in [-1,0,1]:
        for x in [-1,0,1]:
            try:
                if black[a+y][b+x]==1:
                    p+=1
            except:
                continue
    ans[p]+=1
ans[0]=(h-2)*(w-2)-sum(ans[1:])

for a in ans:
    print(a)

Submission status: Accepted

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

H,W,N = map(int,input().split())
D = defaultdict(bool)
B = []

for _ in range(N):
    a,b = map(lambda x: int(x)-1,input().split())
    D[(a,b)] = True
    B.append((a,b))

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

for a,b in B:
    for i in range(9):
        ix,iy = divmod(i,3)
        if a-ix<0 or b-iy<0:
            continue
        black_count = 0
        for j in range(9):
            jx,jy = divmod(j,3)
            if H<=a-ix+jx or W<=b-iy+jy:
                break
            if (a-ix+jx,b-iy+jy) in D:
                if -iy+jy<0 or (-iy+jy==0 and -ix+jx<0):
                    break
                black_count += 1
        else:
            ans[black_count] += 1

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

Submission status: Accepted

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

import sys
from collections import defaultdict, Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, N = MAP()
D = defaultdict(int)

# あるマスが黒いことで黒マスが増える1〜9個の3*3正方形に+1する
for _ in range(N):
    a, b = MAP()
    for i in range(max(a-2, 1), min(a+1, H-1)):
        for j in range(max(b-2, 1), min(b+1, W-1)):
            D[(i, j)] += 1

C = Counter(D.values())
total = (H-2) * (W-2)
# 0は 全体 - 合計 で出す
print(total - sum(C.values()))
for i in range(1, 10):
    print(C[i])

Submission status: Accepted

Solution code:
H, W, N = list(map(int, input().split()))
D = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    for dy in (-1, 0, +1):
        y = a + dy
        if y<=1 or y>=H: continue
        for dx in (-1, 0, +1):
            x = b + dx
            if x<=1 or x>=W: continue
            D.append((x,y))

D = sorted(D)

i = 0
M = len(D)
ans = [0]*10
while i<M:
    n = 1
    d = D[i]
    while i+n<M and D[i+n]==d: n+=1
    ans[n] += 1
    i+=n

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

Submission status: Accepted

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

dic = {}

for i in range(n):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(-1, 2):
        for j in range(-1, 2):
            if a + i <= 0 or a + i >= h - 1 or b + j <= 0 or b + j >= w - 1:
                continue
            if (a+i, b+j) in dic:
                dic[(a+i, b+j)] += 1
            else:
                dic[(a+i, b+j)] = 1

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

Submission status: Accepted

Solution code:
import numpy as np
# import math
import collections
import sys
input = sys.stdin.readline

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

ab = []

eff = collections.defaultdict(int)

for i in range(N):
    temp = list(map(int,input().split()))
    ab.append(temp)
    for j in range(3):
        for k in range(3):
            if (temp[0]-j >= 1) & (temp[0]-j <= H-2):
                if (temp[1]-k >= 1) & (temp[1]-k <= W-2):
                    eff[(temp[0]-j,temp[1]-k)] += 1

count = collections.Counter(eff.values())

count0 = (H-2) * (W-2) - sum(count.values())

print(count0)
for i in range(1,10):
    if i in count:
        print(count[i])
    else:
        print(0)

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    input = stdin.readline
    h, w, n = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*n]

    ans = [0]*10
    d = {}

    for a, b in ab:
        for j in range(-1, 2):
            for k in range(-1, 2):
                d[(a+j, b+k)] = d.get((a+j, b+k), 0)+1

    for (i, j), k in d.items():
        if 2 <= i < h and 2 <= j < w:
            ans[k] += 1

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


main()

Submission status: Accepted

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

from collections import defaultdict
dic = defaultdict(int)
for _ in range(n):
   a,b = map(int,input().split())
   a -= 1
   b -= 1
   for aa in range(a-1, a+2):
      for bb in range(b-1, b+2):
         if 1 <= aa <= h-2 and 1 <= bb <= w-2:
            dic[(aa,bb)] += 1
ans = [0 for i in range(10)]
for i in dic.values():
   ans[i] += 1

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

for anss in ans:
   print(anss)

Submission status: Accepted

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

from collections import Counter
d = []

for _ in range(n):
    a,b = map(int,input().split())
    for k in range(3):
        for l in range(3):
            if 0 < a-k < h-1 and 0 < b-l < w-1:
                d.append((a-k,b-l))

dd = Counter(d)
ddd = list(dd.values())

ans = [0]*10

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

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

for x in ans:
    print(x)

Submission status: Accepted

Solution code:
H, W, N = list(map(int, input().split()))
ans = {}
for i in range(N):
  a, b = list(map(int, input().split()))
  for j in range(-1, 2):
    for k in range(-1, 2):
      if (a+j)>=2 and (b+k)>=2 and (a+j)<=(H-1) and (b+k)<=(W-1):
        key = str(a+j) + "_" + str(b+k)
        ans[key] = ans.get(key, 0) + 1
ans_value = list(ans.values())
ans_n0 = 0
for i in range(1, 10):
  ans_n0 = ans_n0 + ans_value.count(i)
print((H-2)*(W-2)-ans_n0)
for i in range(1, 10):
  print(ans_value.count(i))

Submission status: Accepted

Solution code:
from collections import defaultdict

H, W, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
h = defaultdict(int)
for a, b in ab:
    for y in range(max([a - 2, 1]), min([a, H - 2]) + 1):
        for x in range(max([b - 2, 1]), min([b, W - 2]) + 1):
            h[(y, x)] += 1

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

for a in ans:
    print(a)

Submission status: Accepted

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

d = dict()
for i in range(len(ab)):
    a = ab[i][0] - 1
    b = ab[i][0] - 1
    d[a] = set()

dp = [0] * 10
dp[0] = (h - 2) * (w - 2)
for i in range(n):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    for dx in [-1, 0, 1]:
        for dy in [-1, 0, 1]:
            nx, ny = a + dx, b + dy # center
            if nx >= 1 and nx <= h - 2 and ny >= 1 and ny <= w - 2:
                # print(nx, ny)
                tmp = 0
                for dx2 in [-1, 0, 1]:
                    for dy2 in [-1, 0, 1]:
                        if nx + dx2 in d and ny + dy2 in d[nx + dx2]:
                            tmp += 1

                dp[tmp] -= 1
                dp[tmp + 1] += 1

    d[a].add(b)

for x in dp:
    print(x)

Submission status: Accepted

Solution code:
def solve():
    diff = [(i-1,j-1) for i in range(3) for j in range(3)]
    H,W,N = map(int, input().split())
    count_dict = {}
    ret = [0]*10
    ret[0] = (W-2)*(H-2)
    for i in range(N):
        a, b = map(int,input().split())
        # da = min(a, W-a, 2)+1
        # db = min(b, H-b, 2)+1
        # rect_num = da*db
        for da,db in diff:
            ra, rb = a+da, b+db
            if ra <= 1 or ra >= H or rb <= 1 or rb >= W : continue
            # if (ra,rb) == (4,2): print(i+1, a, b, ra, rb)
            if (ra,rb) in count_dict:
                dom = count_dict[(ra,rb)]
                ret[dom] -= 1
                ret[dom+1] += 1
                count_dict[(ra,rb)] += 1
            else:
                ret[0] -= 1
                ret[1] += 1
                count_dict[(ra,rb)] = 1
                
    # print(count_dict)
    print('\n'.join(map(str,ret)))
    
solve()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter

h, w, n = map(int, sys.stdin.readline().split())
ab = map(int, sys.stdin.read().split())
ab = zip(ab, ab)

def main():
    c = defaultdict(int)
    for a, b in ab:
        for da in range(-2, 1):
            for db in range(-2, 1):
                # 今見ているマスを含むrectangularの左上
                i = a + da
                j = b + db
                if 1 <= i <= h - 2 and 1 <= j <= w - 2:
                    c[(i, j)] += 1
    
    res = Counter(c.values())
    cnt_0 = (h - 2) * (w - 2) - sum(res.values())
    yield cnt_0
    for i in range(1, 10):
        if i in res:
            yield res[i]
        else:
            yield 0

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import product
from collections import defaultdict
def resolve():
    h,w,n=map(int,input().split())
    D=defaultdict(int)
    for _ in range(n):
        a,b=map(int,input().split())
        for i,j in product(range(a-1,a+2),range(b-1,b+2)):
            if(2<=i<=h-1 and 2<=j<=w-1):
                D[(i,j)]+=1

    ans=[0]*10
    for v in D.values():
        ans[v]+=1
    ans[0]=(h-2)*(w-2)-sum(ans)
    print(*ans,sep='\n')
resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import product
from collections import defaultdict
def resolve():
    h,w,n=map(int,input().split())
    D=defaultdict(int)
    for _ in range(n):
        a,b=map(int,input().split())
        for i,j in product(range(a-1,a+2),range(b-1,b+2)):
            if(1<=i<=h and 1<=j<=w):
                D[(i,j)]+=1

    ans=[0]*10
    for k,v in D.items():
        i,j=k
        if(i==1 or i==h or j==1 or j==w): continue
        ans[v]+=1
    ans[0]=(h-2)*(w-2)-sum(ans)
    print(*ans,sep='\n')
resolve()

Submission status: Accepted

Solution code:
from collections import Counter
h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
d=(-1,0,1)
c=Counter()
for a,b in ab:
    for da in d:
        for db in d:
            aa=a+da
            bb=b+db
            if 2<=aa<=h-1 and 2<=bb<=w-1:
                c[(aa,bb)]+=1
ans=Counter(c.values())
count_0=(h-2)*(w-2)-sum(ans.values())
print(count_0)
for i in range(1,10):
    print(ans[i])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

h, w, n = [int(item) for item in input().split()]
blk_cnt = defaultdict(int) 

for i in range(n):
    a, b = [int(item) - 1 for item in input().split()]
    for j in range(-1, 2):
        for k in range(-1, 2):
            blk_cnt[(a + j, b + k)] += 1
ans = [0] * 10 
for key in blk_cnt.keys():
    if key[0] < 1 or key[1] < 1 or key[0] >= h-1 or key[1] >= w-1:
        continue
    ans[blk_cnt[key]] += 1
total = (w - 2) * (h - 2)
ans[0] = total - sum(ans)
for item in ans:
    print(item)

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from collections import defaultdict
from collections import Counter
H,W,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

dic = defaultdict(int)
for a,b in AB:
    for dh in range(3):
        for dw in range(3):
            if 0 < a-dh <= H-2 and 0 < b-dw <= W-2:
                dic[(a-dh,b-dw)] += 1

Ans = Counter(dic.values())
Ans[0] = (H-2)*(W-2) - sum(Ans.values())

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

Submission status: Accepted

Solution code:
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from collections import defaultdict
H,W,N = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

dic = defaultdict(int)
for a,b in AB:
    for dh in range(3):
        for dw in range(3):
            if 0 < a-dh <= H-2 and 0 < b-dw <= W-2:
                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 sys
import collections


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w, n = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for _ in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        for i in range(-1, 2):
            for j in range(-1, 2):
                if 1 <= a-1+i < h-1 and 1 <= b-1+j < w-1:
                    d[a-1+i, b-1+j] += 1
    nd = []
    for k, v in d.items():
        nd.append(v)
    nd = collections.Counter(nd)
    print((h - 2) * (w - 2) - sum(nd.values()))
    for i in range(1, 10):
        print(nd[i])


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
H, W, N = map(int, input().split())
A = []
L = 0
ans = [0] * 10

for i in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(max(0, a - 2), min(a + 1,H-2)):
        for j in range(max(0, b - 2), min(b + 1,W-2)):
            A.append((i, j))
            L += 1

A.sort()
count = 1
for i in range(L - 1):
    if A[i] == A[i + 1]:
        count += 1
    else:
        ans[count] += 1
        count = 1
if L >= 1:
    ans[count] += 1

ans[0] = (H - 2) * (W - 2) - sum(ans)

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

Submission status: Accepted

Solution code:
H,W,N = map(int,input().split())
count = []
L = 0
for i in range(N):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    for i in range(max(0,a-2),min(a+1,H-2)):
        for j in range(max(0,b-2),min(b+1,W-2)):
            count.append((i,j))
            L += 1
count.sort()
ans = [0]*10
tmp = 1
for i in range(L-1):
    if count[i] == count[i+1]:
        tmp += 1
    else:
        ans[tmp] += 1
        tmp = 1
if L>=1:
  ans[tmp] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
for i in range(10):
    print(ans[i])

Submission status: Accepted

Solution code:
import sys
import bisect
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w, n = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    dt = collections.defaultdict(int)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        a -= 1
        b -= 1
        for j in range(max(1, a - 1), min(h-1, a + 2)):
            for k in range(max(1, b - 1), min(w-1, b + 2)):
                d[j, k] += 1
                dt[d[j, k]] += 1
                dt[d[j, k]-1] -= 1
    dt[0] += (h - 3 + 1) * (w - 3 + 1)
    for i in range(10):
        print(dt[i])


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import sys
import bisect
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache


def slove():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    h, w, n = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(int)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        a -= 1
        b -= 1
        for j in range(max(1, a - 1), min(h-1, a + 2)):
            for k in range(max(1, b - 1), min(w-1, b + 2)):
                d[j, k] += 1
    ls = [0] * 10
    for k, v in sorted(d.items(), key=lambda x: x[1]):
        ls[v] += 1
    ls[0] = (h - 3 + 1) * (w - 3 + 1) - sum(ls)
    for i in range(10):
        print(ls[i])


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

def main():
    H, W, N = map(int, input().split())
    j = [0] * 10
    ans = [0] * 10
    ans[0] = (H - 2) * (W - 2)
    d = defaultdict(int)
    dt = [-1,0,1]
    for i in range(N):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        for i in dt:
            if 0 <= a + i <= H - 1:
                for j in dt:
                    if 0 <= b + j <= W - 1:
                        tmp = d[(a + i, b + j)]
                        d[(a + i, b + j)] += 1
                        if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                            ans[tmp] -= 1
                            ans[tmp + 1] += 1
    
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import product
from collections import Counter
input = sys.stdin.readline

H, W, N = map(int, input().split())
udlr = [-1, 0, 1]
center = []

for _ in range(N):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    for i, j in product(udlr, repeat=2):
        if 0 < a + i < H - 1 and 0 < b + j < W - 1:
            center.append((a + i, b + j))

black = Counter(list(Counter(center).values()))
black[0] = (H - 2) * (W - 2) - sum(list(black.values()))

for i in range(10):
    if black.get(i):
        print(black[i])
    else:
        print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

Cells = defaultdict(int)
Count = [(H-2)*(W-2)] + [0 for _ in range(9)]

for a,b in AB:
  a -= 1
  b -= 1
  for i in range(-1,2):
    for j in range(-1,2):
      if 1 <= a+i <= H-2 and 1 <= b+j <= W-2:
        Count[Cells[(a+i,b+j)]] -= 1
        Count[Cells[(a+i,b+j)]+1] += 1
      Cells[(a+i,b+j)] += 1
for c in Count:
  print(c)

Submission status: Accepted

Solution code:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
# from copy import deepcopy, copy

import queue
from collections import deque




def main():
    high, width, num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]

    ans_list = defaultdict(int)
    move_dic = [-2, -1, 0]
    for i in range(num):
        a, b = data[i]
        a -= 1
        b -= 1
        for move_a in move_dic:
            for move_b in move_dic:
                now_a = a + move_a
                now_b = b + move_b
                if 0 <= now_a < high - 2 and 0 <= now_b < width - 2:
                    ans_list[(now_a, now_b)] += 1
        # print(ans_list)

    ans = Counter(list(ans_list.values()))
    print((high - 2) * (width - 2) - sum(list(ans.values())))
    for i in range(1, 10):
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline

    H, W, N = map(int, input().split())
    ans = [0] * 10
    ans[0] = (H - 2) * (W - 2)
    # print (ans)
    tmplst = [-1, 0, 1]
    dic = defaultdict(int)
    for _ in range(N):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        for i in tmplst:
            if 0 <= a + i <= H - 1:
                for j in tmplst:
                    if 0 <= b + j <= W - 1: #範囲に入っている
                        tmp = dic[(a + i, b + j)]
                        dic[(a + i, b + j)] += 1
                        if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                            ans[tmp] -= 1
                            ans[tmp + 1] += 1

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

H, W, N = map(int, input().split())
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
# print (ans)
tmplst = [-1, 0, 1]
dic = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        if 0 <= a + i <= H - 1:
            for j in tmplst:
                if 0 <= b + j <= W - 1: #範囲に入っている
                    tmp = dic[(a + i, b + j)]
                    dic[(a + i, b + j)] += 1
                    if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                        ans[tmp] -= 1
                        ans[tmp + 1] += 1

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

Submission status: Accepted

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

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

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Submission status: Accepted

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

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

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Submission status: Accepted

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

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

lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)

tmp = None
count = 0
for i in lst:
    if i == tmp:
        count += 1
    else:
        ans[0] -= 1
        ans[count] += 1
        count = 1
        tmp = i

ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')

Submission status: Accepted

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

H, W, N = map(int, input().split())
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
# print (ans)
tmplst = [-1, 0, 1]
dic = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    for i in tmplst:
        for j in tmplst:
            if 0 <= a + i <= H - 1 and 0 <= b + j <= W - 1: #範囲に入っている
                tmp = dic[(a + i, b + j)]
                dic[(a + i, b + j)] += 1
                if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
                    ans[tmp] -= 1
                    ans[tmp + 1] += 1


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

Submission status: Accepted

Solution code:
def main():
    h,w,n=map(int,input().split(' '))
    if n==0:
        print((h-2)*(w-2))
        for i in range(9):
            print(0)
        exit()
    draw_list=[]
    for i in range(n):
        draw=tuple(map(int,input().split(' ')))
        for j in range(3):
            for k in range(3):
                if 0<draw[0]-j<=h-2 and 0<draw[1]-k<=w-2:
                    draw_list.append((draw[0]-j,draw[1]-k))
    ans = [0]*9
    sorted_draw = sorted(draw_list)
    for n,i in enumerate(sorted_draw):
        if not n:
            ans_num=0
            tmp = i
            continue
        if tmp == i:
            ans_num+=1
        else:
            ans[ans_num] += 1
            tmp = i
            ans_num = 0
    ans[ans_num] += 1
    print((h-2)*(w-2)-sum(ans))
    for i in ans:
        print(i)



if __name__ == '__main__':
    main()