Problem:


Dropping Ink

As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (x, y) coordinate system.

We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as shown in the figure depending on its size. In the figure, a star denotes the point of fall and a circle denotes the surrounding cells.

Originally, the paper is white that means for each cell the value of density is 0. The value of density is increased by 1 when the ink sinks into the corresponding cells.

For example, if we put a drop of Small ink at (1, 2) and a drop of Medium ink at (3, 2), the ink will sink as shown in the following figure (left side):

In the figure, density values of empty cells are 0. The ink sinking into out of the paper should be ignored as shown in the figure (top side). We can put several drops of ink at the same point.

Your task is to write a program which reads a sequence of points of fall (x, y) with its size (Small = 1, Medium = 2, Large = 3), and prints the number of cells whose density value is 0. The program must also print the maximum value of density.

You may assume that the paper always consists of 10 &times; 10, and 0 ≤ x < 10, 0 ≤ y < 10.

Input

x1,y1,s1
x2,y2,s2
  :
  :

(xi, yi) represents the position of the i-th drop and si denotes its size. The number of drops is less than or equal to 50.

Output

Print the number of cells whose density value is 0 in first line.

Print the maximum value of density in the second line.

Sample Input

2,5,3
3,6,1
3,4,2
4,5,2
3,6,3
2,4,1

Output for the Sample Input

77
5



Sample input:
2,5,3
3,6,1
3,4,2
4,5,2
3,6,3
2,4,1


Sample output:
77
5

Submission status: Accepted

Solution code:
drops = {
    1: ((0,0,0,0,0), (0,0,1,0,0), (0,1,1,1,0), (0,0,1,0,0), (0,0,0,0,0)),
    2: ((0,0,0,0,0), (0,1,1,1,0), (0,1,1,1,0), (0,1,1,1,0), (0,0,0,0,0)),
    3: ((0,0,1,0,0), (0,1,1,1,0), (1,1,1,1,1), (0,1,1,1,0), (0,0,1,0,0))}

paper = [[0 for i in xrange(14)] for j in xrange(14)]

def solve(x, y, size):
    for i in xrange(5):
        for j in xrange(5):
            if drops[size][i][j] == 1:
                paper[y+i][x+j] += 1

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    x, y, size = map(int, line.split(','))
    solve(x, y, size)

s = c = 0
for i in range(2, 12):
    for j in range(2, 12):
        if paper[i][j] == 0:
            c += 1
        if s < paper[i][j]:
            s = paper[i][j]

print c
print s

Submission status: Accepted

Solution code:
drops = {
    1: ((0,0,0,0,0), (0,0,1,0,0), (0,1,1,1,0), (0,0,1,0,0), (0,0,0,0,0)),
    2: ((0,0,0,0,0), (0,1,1,1,0), (0,1,1,1,0), (0,1,1,1,0), (0,0,0,0,0)),
    3: ((0,0,1,0,0), (0,1,1,1,0), (1,1,1,1,1), (0,1,1,1,0), (0,0,1,0,0))}

paper = [[0] * 14 for j in xrange(14)]

def solve(x, y, size):
    for i in xrange(5):
        for j in xrange(5):
            if drops[size][i][j] == 1:
                paper[y+i][x+j] += 1

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    solve(*map(int, line.split(',')))

result = [f for i in [l[2:12] for l in paper[2:12]] for f in i]

print result.count(0)
print max(result)

Submission status: Accepted

Solution code:
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

print sum([1 if i==0 else 0 for j in board for i in j])
print max([i for j in board for i in j])

Submission status: Accepted

Solution code:
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

print len([j for i in board for j in i if j==0])
print max([i for j in board for i in j])

Submission status: Accepted

Solution code:
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

print len([j for i in board for j in i if j==0])
print max([j for i in board for j in i])

Submission status: Accepted

Solution code:
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

a=[j for i in board for j in i]
print a.count(0)
print max(a)

Submission status: Accepted

Solution code:
cell = [[0] * 10 for i in xrange(10)]

large = [[0,0,1,0,0],
         [0,1,1,1,0],
         [1,1,1,1,1],
         [0,1,1,1,0],
         [0,0,1,0,0]]

medium= [[0,0,0,0,0],
         [0,1,1,1,0],
         [0,1,1,1,0],
         [0,1,1,1,0],
         [0,0,0,0,0]]

small = [[0,0,0,0,0],
         [0,0,1,0,0],
         [0,1,1,1,0],
         [0,0,1,0,0],
         [0,0,0,0,0]]

size = [0,small,medium,large]

while True:
    try:
        x, y, s = [int(i) for i in raw_input().split(',')]
    except EOFError:
        break
    except ValueError:
        break
    p = size[s]
    for i in xrange(5):
        for j in xrange(5):
            px = i+x-2
            py = j+y-2
            if(px in xrange(10) and py in xrange(10)):
                cell[py][px] += p[i][j]
print reduce(lambda x,y:x+y,map(lambda x:x.count(0),cell))
print max(map(max,cell))

Submission status: Accepted

Solution code:
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

NUM = [[0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
paper = Counter()
for line in stdin:
    if not line.strip():
        break
    x, y, size = (int(s) for s in line.split(','))

    xidx = [x, x-1, x, x+1, x-2, x-1, x, x+1, x+2, x-1, x, x+1, x]
    yidx = [y-2, y-1, y-1, y-1, y, y, y, y, y, y+1, y+1, y+1, y+2]
    val = NUM[size-1]

    for a, b, i in zip(xidx, yidx, xrange(len(xidx))):
        if a < 0 or 9 < a or b < 0 or 9 < b:
            continue
        paper[a + b * 10] += val[i]

print(sum(1 for i in xrange(100) if not paper[i]))
print(max(paper[i] for i in xrange(100)))

Submission status: Accepted

Solution code:
mass = [[0 for p in xrange(14)] for q in xrange(14)]
while True:
	try:
		x,y,size = map(int,raw_input().split(','))
		x += 2 ; y += 2
		if   size == 1:
			mass[x-2][y-2]+=0;mass[x-1][y-2]+=0;mass[x][y-2]+=0;mass[x+1][y-2]+=0;mass[x+2][y-2]+=0
			mass[x-2][y-1]+=0;mass[x-1][y-1]+=0;mass[x][y-1]+=1;mass[x+1][y-1]+=0;mass[x+2][y-1]+=0
			mass[x-2][y]  +=0;mass[x-1][y]  +=1;mass[x][y]  +=1;mass[x+1][y]  +=1;mass[x+2][y]  +=0
			mass[x-2][y+1]+=0;mass[x-1][y+1]+=0;mass[x][y+1]+=1;mass[x+1][y+1]+=0;mass[x+2][y+1]+=0
			mass[x-2][y+2]+=0;mass[x-1][y+2]+=0;mass[x][y+2]+=0;mass[x+1][y+2]+=0;mass[x+2][y+2]+=0
		elif size == 2:
			mass[x-2][y-2]+=0;mass[x-1][y-2]+=0;mass[x][y-2]+=0;mass[x+1][y-2]+=0;mass[x+2][y-2]+=0
			mass[x-2][y-1]+=0;mass[x-1][y-1]+=1;mass[x][y-1]+=1;mass[x+1][y-1]+=1;mass[x+2][y-1]+=0
			mass[x-2][y]  +=0;mass[x-1][y]  +=1;mass[x][y]  +=1;mass[x+1][y]  +=1;mass[x+2][y]  +=0
			mass[x-2][y+1]+=0;mass[x-1][y+1]+=1;mass[x][y+1]+=1;mass[x+1][y+1]+=1;mass[x+2][y+1]+=0
			mass[x-2][y+2]+=0;mass[x-1][y+2]+=0;mass[x][y+2]+=0;mass[x+1][y+2]+=0;mass[x+2][y+2]+=0
		elif size == 3:
			mass[x-2][y-2]+=0;mass[x-1][y-2]+=0;mass[x][y-2]+=1;mass[x+1][y-2]+=0;mass[x+2][y-2]+=0
			mass[x-2][y-1]+=0;mass[x-1][y-1]+=1;mass[x][y-1]+=1;mass[x+1][y-1]+=1;mass[x+2][y-1]+=0
			mass[x-2][y]  +=1;mass[x-1][y]  +=1;mass[x][y]  +=1;mass[x+1][y]  +=1;mass[x+2][y]  +=1
			mass[x-2][y+1]+=0;mass[x-1][y+1]+=1;mass[x][y+1]+=1;mass[x+1][y+1]+=1;mass[x+2][y+1]+=0
			mass[x-2][y+2]+=0;mass[x-1][y+2]+=0;mass[x][y+2]+=1;mass[x+1][y+2]+=0;mass[x+2][y+2]+=0
	except: break
white = 0
max = 0
for p in xrange(2,12):
	for q in xrange(2,12):
		if mass[p][q] == 0: white += 1
		if mass[p][q] > max: max = mass[p][q]
print white
print max

Submission status: Accepted

Solution code:

import sys


class Paper:
    def __init__(self):
        self.paper = [[0 for x in range(10)] for y in range(10)]

    def white_space(self):
        s = 0
        for x in range(10):
            for y in range(10):
                if self.paper[x][y] == 0:
                    s += 1
        return s

    def most_dark(self):
        s = 0
        for x in range(10):
            for y in range(10):
                if self.paper[x][y] > s:
                    s = self.paper[x][y]
        return s

    def drop(self, x, y, size):
        r = []
        if size == 1:
            r.append((x,y))
            r.append((x-1,y))
            r.append((x+1,y))
            r.append((x,y-1))
            r.append((x,y+1))
        elif size == 2:
            r = [(i,j) for i in range(x-1, x+2) for j in range(y-1, y+2)]
        elif size == 3:
            r = [(i,j) for i in range(x-1, x+2) for j in range(y-1, y+2)]
            r.append((x-2, y))
            r.append((x+2, y))
            r.append((x, y-2))
            r.append((x, y+2))
        else:
            pass
#        print r
        r = filter(self.out_of_paper, r)
#        print r
        try:
            for p in r:
                self.paper[p[0]][p[1]] += 1
        except:
            pass
        return self

    def out_of_paper(self, p):
        if 0 <= p[0] < 10 and 0 <= p[1] < 10:
            return True
        else:
            return False



paper = Paper()
for line in sys.stdin:
    (x, y, size) = tuple(map(int, line.split(',')))
    paper.drop(x, y, size)
print paper.white_space()
print paper.most_dark()

Submission status: Accepted

Solution code:
def drop(x,y):
    global paper
    if 0<=x<10 and 0<=y<10: paper[y][x]+=1
    return

def ink(x,y,size):
    drop(x,y)
    drop(x-1,y)
    drop(x+1,y)
    drop(x,y-1)
    drop(x,y+1)
    if size==1: return
    drop(x-1,y-1)
    drop(x-1,y+1)
    drop(x+1,y-1)
    drop(x+1,y+1)
    if size==2: return
    drop(x-2,y)
    drop(x+2,y)
    drop(x,y-2)
    drop(x,y+2)
    return

paper = [[0 for i in range(10)] for j in range(10)]
while True:
    try:
        x,y,size = map(int, raw_input().split(","))
        ink(x,y,size)
    except:
        break

print sum([e.count(0) for e in paper])
print max([max(e) for e in paper])

Submission status: Accepted

Solution code:
px = ((0,0,-1,1), (-1,-1,1,1), (0,0,-2,2))
py = ((-1,1,0,0), (-1,1,-1,1), (-2,2,0,0))

p = [[0]*14 for i in range(14)]

while True:
    try:
        x,y,s = map(int,raw_input().split(','))
        x += 2
        y += 2
        p[x][y] += 1
        for i in range(s):
            for j in range(4):
                p[x+px[i][j]][y+py[i][j]] += 1
    except EOFError:
        break
p = [a[2:-2] for a in p[2:-2]]
print sum([a.count(0) for a in p])
print max([max(a) for a in p])

Submission status: Accepted

Solution code:
import sys

SIZE = 10
paper = []


def main():
    init()

    for line in sys.stdin:
        data = line.strip().split(',')
        i = int(data[0])
        j = int(data[1])
        size = int(data[2])

        if   size == 1:
            drop_small(i, j)
        elif size == 2:
            drop_medium(i, j)
        elif size == 3:
            drop_large(i, j)

    print count_white()
    print find_max()

def find_max():
    mx = 0
    for i in xrange(SIZE):
        for j in xrange(SIZE):
            mx = max(mx, paper[i][j])

    return mx

def count_white():
    c = 0
    for i in xrange(SIZE):
        for j in xrange(SIZE):
            if paper[i][j] == 0:
                c += 1

    return c

def init():
    global paper
    for i in xrange(SIZE):
        paper.append([0]*SIZE)


def check(i, j):
    if i < 0 or SIZE <= i:
        return False
    if j < 0 or SIZE <= j:
        return False

    return True


def drop(i, j):
    global paper
    if not check(i, j):
        return False

    paper[i][j] += 1
    return True


def drop_small(i, j):
    drop(i, j)
    drop(i - 1, j)
    drop(i + 1, j)
    drop(i, j - 1)
    drop(i, j + 1)


def drop_medium(i, j):
    drop_small(i, j)
    drop(i - 1, j - 1)
    drop(i - 1, j + 1)
    drop(i + 1, j - 1)
    drop(i + 1, j + 1)


def drop_large(i, j):
    drop_medium(i, j)
    drop(i - 2, j)
    drop(i, j - 2)
    drop(i, j + 2)
    drop(i + 2, j)

main()

Submission status: Accepted

Solution code:
paper = [[0 for i in range(10)] for j in range(10)]

def drop(x,y):
    global paper
    if 0 <= x < 10 and 0<= y < 10:
        paper[y][x] += 1
    return

def ink(x,y,s):
    drop(x,y)
    drop(x+1,y); drop(x,y+1)
    drop(x-1,y); drop(x,y-1)
    if s == 1: return
    drop(x+1,y+1); drop(x+1,y-1)
    drop(x-1,y+1); drop(x-1,y-1)
    if s == 2: return
    drop(x+2,y); drop(x,y+2)
    drop(x-2,y); drop(x,y-2)
    return

while True:
    try:
        x, y, s = map(int, raw_input().split(","))
        ink(x,y,s)
    except:
        break

print sum([i.count(0) for i in paper])
print max([max(i) for i in paper])

Submission status: Accepted

Solution code:
import sys
def ink(x,y,size):
    global paper
    paper[y][x]+=1
    for d in [-1,1]:
        paper[y+d][x]+=1
        paper[y][x+d]+=1
    if size==1: return
    for d in [-1,1]:
        paper[y+d][x+d]+=1
        paper[y+d][x-d]+=1
    if size==2: return
    for d in [-2,2]:
        paper[y+d][x]+=1
        paper[y][x+d]+=1
    return

R=range(14)
paper=[[0 for i in R] for j in R]
for s in sys.stdin:
    x,y,size = map(int, s.split(","))
    ink(x+2,y+2,size)
c=0
m=0
for e in paper[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Submission status: Accepted

Solution code:
import sys
def ink(x,y,size):
    global P
    P[y][x]+=1
    for d in [-1,1]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    if size==1: return
    for d in [-1,1]:
        P[y+d][x+d]+=1
        P[y+d][x-d]+=1
    if size==2: return
    for d in [-2,2]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    return

R=range(14)
P=[[0 for i in R] for j in R]
for s in sys.stdin:
    x,y,size = map(int, s.split(","))
    ink(x+2,y+2,size)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Submission status: Accepted

Solution code:
import sys
def ink(x,y,s):
    global P
    P[y][x]+=1
    P[y+1][x]+=1
    P[y-1][x]+=1
    P[y][x+1]+=1
    P[y][x-1]+=1
    if s==1: return
    P[y+1][x+1]+=1
    P[y+1][x-1]+=1
    P[y-1][x+1]+=1
    P[y-1][x-1]+=1
    if s==2: return
    P[y+2][x]+=1
    P[y-2][x]+=1
    P[y][x+2]+=1
    P[y][x-2]+=1
    return

P=[[0]*14 for j in range(14)]
for s in sys.stdin:
    x,y,s = map(int, s.split(","))
    ink(x+2,y+2,s)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Submission status: Accepted

Solution code:
small_x = [-1, 0, 0, 1]
small_y = [0, -1, 1, 0]
middle_x = [-1, -1, -1, 0, 0, 1, 1, 1]
middle_y = [-1, 0, 1, -1, 1, -1, 0, 1]
big_x = [-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2]
big_y = [0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0]
dx = [[], small_x, middle_x, big_x]
dy = [[], small_y, middle_y, big_y]

field = [[0] * 10 for _ in range(10)]
while 1:
    try:
        x1, y1, size = map(int, raw_input().split(','))
        field[y1][x1] += 1
        for k in range(len(dx[size])):
            ny = y1 + dy[size][k]
            nx = x1 + dx[size][k]
            if nx < 0 or ny < 0 or nx >= 10 or ny >= 10:
                continue
            field[ny][nx] += 1
    except:
        break
ret, mx = 0, 0
for i in range(10):
    for j in range(10):
        if field[i][j] == 0:
            ret += 1
        mx = max(mx, field[i][j])
print ret
print mx

Submission status: Accepted

Solution code:
dx = [[0, 1, 0, -1, 0], [1, 1, -1, -1], [2, 0, -2, 0]]
dy = [[0, 0, 1, 0, -1], [-1, 1, 1, -1], [0, 2, 0, -2]]
a = [[0 for i in range(14)] for j in range(14)]
try:
    while True:
        x, y, s = map(int, raw_input().split(','))
        x += 2
        y += 2
        for i in range(s):
            for j in range(len(dx[i])):
                a[x + dx[i][j]][y + dy[i][j]] += 1
except:
    pass
ct = mx = 0
for b in a[2:-2]:
    for p in b[2:-2]:
        mx = max(mx, p)
        if p == 0:
            ct += 1
print ct
print mx

Submission status: Accepted

Solution code:
import sys

def plot(x, y):
    global ban
    if 0 <= x < 10 and 0 <= y < 10: ban[y][x] += 1

def drop(x, y, s):
    for dx, dy in [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)]:
        plot(x + dx, y + dy)
    if s == 1: return
    for dx, dy in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
        plot(x + dx, y + dy)
    if s == 2: return
    for dx, dy in [(-2, 0), (2, 0), (0, -2), (0, 2)]:
        plot(x + dx, y + dy)

ban = [[0 for x in range(10)] for y in range(10)]
for line in sys.stdin:
    x, y, size = map(int, line.split(','))
    drop(x, y, size)

print(sum(ban[y][x] == 0 for y in range(10) for x in range(10)))
print(max(ban[y][x] for y in range(10) for x in range(10)))

Submission status: Accepted

Solution code:
mat = []
for i in range(10):
    mat.append([0]*10)

while True:
    try:
        lst = list(map(int, input().split(',')))
        x, y, s = lst[0], lst[1], lst[2]
        
        if s == 1:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1]]

        elif s == 2:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1], [x-1, y-1], [x+1, y-1], [x-1, y+1], [x+1, y+1]]

        else:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1], [x-1, y-1], [x+1, y-1], [x-1, y+1], [x+1, y+1], [x, y-2], [x-2, y], [x+2, y], [x, y+2]]

        for i in tmplst:
            if i[0] < 0 or i[0] > 9 or i[1] < 0 or i[1] > 9:
                pass
            else:
                mat[i[1]][i[0]] +=1
        
    except EOFError:
        break

summat = 0
maxmat = 0
for j in mat:
    summat += j.count(0)
    if maxmat < max(j):
        maxmat = max(j)

print(summat)
print(maxmat)

Submission status: Accepted

Solution code:
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    P = []
    for line in readlines():
        x, y, s = map(int, line.split(","))
        P.append((x, y, s))
    L = 10
    MP = [[0]*L for i in range(L)]
    def update(k, ps):
        for x, y, s in P:
            if k <= s:
                for dx, dy in ps:
                    nx = x + dx; ny = y + dy
                    if not 0 <= nx < L or not 0 <= ny < L:
                        continue
                    MP[ny][nx] += 1
    update(0, [(0, 0)])
    update(1, [(-1, 0), (0, -1), (1, 0), (0, 1)])
    update(2, [(-1, -1), (1, -1), (-1, 1), (1, 1)])
    update(3, [(-2, 0), (0, -2), (2, 0), (0, 2)])
    z = m = 0
    for i in range(L):
        for j in range(L):
            if MP[i][j] == 0:
                z += 1
            m = max(m, MP[i][j])
    write("%d\n%d\n" % (z, m))
solve()

Submission status: Accepted

Solution code:
paper = [[0 for i in range(10)] for j in range(10)]
while True :
    try :
        x, y, s = map(int, input().split(","))
        
        paper[x][y] += 1
        if x > 0 :
            paper[x-1][y] += 1
        if y > 0 :
            paper[x][y-1] += 1
        if x < 9 :
            paper[x+1][y] += 1
        if y < 9 :
            paper[x][y+1] += 1

        if s > 1 :
            if x > 0 :
                if y > 0 :
                    paper[x-1][y-1] += 1
                if y < 9 :
                    paper[x-1][y+1] += 1
            if x < 9 :
                if y > 0 :
                    paper[x+1][y-1] += 1
                if y < 9 :
                    paper[x+1][y+1] += 1
        if s > 2 :
            if x > 1 :
                paper[x-2][y] += 1
            if y > 1 :
                paper[x][y-2] += 1
            if x < 8 :
                paper[x+2][y] += 1
            if y < 8 :
                paper[x][y+2] += 1
                
    except EOFError :
        break


S = 0
M = 0
for i in range(10) :
    for j in range(10) :
        if paper[i][j] == 0 :
            S += 1
        if paper[i][j] > M :
            M = paper[i][j]
        
print(S)
print(M)

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    input_lines = stdin
    
    paper = [0] * 196
    
    size = [[0, -1, 1, -14, 14], [0, -1, 1, -15, -14, -13, 13, 14, 15],
            [0, -1, 1, -15, -14, -13, 13, 14, 15, -28, -2, 2, 28]]
    
    for line in input_lines:
        x, y, s = map(int, line.split(','))
        
        pos = 30 + x + 14 * y
        s -= 1
        
        for move in size[s]:
            paper[pos+move] += 1
    
    zero_cnt = 0
    max_density = 0
    for i in range(30, 157, 14):
        line = paper[i:i+10]
        zero_cnt += line.count(0)
        max_density = max(max_density, max(line))
    
    print(zero_cnt)
    print(max_density)

solve()

Submission status: Accepted

Solution code:
sheet = [[0 for _ in range(10)] for _ in range(10)]

#小、中、大のインクの範囲
small_range = ((0, 0), (1, 0), (0, 1), (-1, 0), (0, -1))
middle_range = ((0, 0), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))
large_range = ((0, 0), (1, 0), (2, 0), (1, 1), (0, 1), (0, 2), (-1, 1), (-1, 0), (-2, 0), (-1, -1), (0, -1), (0, -2), (1, -1))

#範囲内か判定してインクを足す
def drop(x, y, drop_range):
  for dx, dy in drop_range:
    newx, newy = x + dx, y + dy
    if 0 <= newx <= 9 and 0 <= newy <= 9:
      sheet[newx][newy] += 1

while True:
  try:
    x, y, s = map(int, input().split(","))

    if s == 1:
      drop(x, y, small_range)
    elif s == 2:
      drop(x, y, middle_range)
    else:
      drop(x, y, large_range)

  except EOFError:
    break

#0の個数
zero_cnt = 0

#インクの最大値
max_ink = 0

for x in range(10):
  for y in range(10):
    ink = sheet[x][y]

    if ink == 0:
      zero_cnt += 1

    if max_ink < ink:
      max_ink = ink

print(zero_cnt)
print(max_ink)

Submission status: Accepted

Solution code:
def paint(masu,data):
    masu[data[1]][data[0]]+=1                   #インクを垂らした場所
    #print(masu)
    if data[2]==1:                              #インク小の時
        if data[0]!=0:
            masu[data[1]][data[0]-1]+=1
        if data[0]!=9:
            masu[data[1]][data[0]+1]+=1
        if data[1]!=0:
            masu[data[1]-1][data[0]]+=1
        if data[1]!=9:
            masu[data[1]+1][data[0]]+=1
        #print("小の時",masu)
    elif data[2]==2:                            #インク中の時
        if data[0]!=0:
            masu[data[1]][data[0]-1]+=1
        if data[0]!=9:
            masu[data[1]][data[0]+1]+=1
        if data[1]!=0:
            masu[data[1]-1][data[0]]+=1
        if data[1]!=9:
            masu[data[1]+1][data[0]]+=1
        if data[1]!=9 and data[0]!=9:
            masu[data[1]+1][data[0]+1]+=1
        if data[1]!=9 and data[0]!=0:
            masu[data[1]+1][data[0]-1]+=1
        if data[1]!=0 and data[0]!=9:
            masu[data[1]-1][data[0]+1]+=1
        if data[1]!=0 and data[0]!=0:
            masu[data[1]-1][data[0]-1]+=1
        #print("中の時",masu)
    elif data[2]==3:                            #インク大の時
        if data[0]!=0:
            masu[data[1]][data[0]-1]+=1
        if data[0]!=9:
            masu[data[1]][data[0]+1]+=1
        if data[1]!=0:
            masu[data[1]-1][data[0]]+=1
        if data[1]!=9:
            masu[data[1]+1][data[0]]+=1
        if data[1]!=9 and data[0]!=9:
            masu[data[1]+1][data[0]+1]+=1
        if data[1]!=9 and data[0]!=0:
            masu[data[1]+1][data[0]-1]+=1
        if data[1]!=0 and data[0]!=9:
            masu[data[1]-1][data[0]+1]+=1
        if data[1]!=0 and data[0]!=0:
            masu[data[1]-1][data[0]-1]+=1
        if data[1]>=2:
            masu[data[1]-2][data[0]]+=1
        if data[1]<=7:
            masu[data[1]+2][data[0]]+=1
        if data[0]>=2:
            masu[data[1]][data[0]-2]+=1
        if data[0]<=7:
            masu[data[1]][data[0]+2]+=1
        #print("大の時",masu)
    return masu

masu=[
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0]
    ]



def keisan(masu):
    max=0
    num1=0
    for na in range(10):
        for ma in range(10):
            if masu[na][ma]==0:
                num1+=1
            if masu[na][ma]>max:
                max=masu[na][ma]
    print(num1)
    print(max)

while True:
    try:
        x,y,s=list(map(int, input().split(',')))
        data=[x,y,s]   
        masu2=paint(masu,data)
    except:
        break

    
    #print("masu",masu2)
#print("masu2",masu2)
keisan(masu2)

Submission status: Accepted

Solution code:
def small(x, y, a):
    a[x][y] += 1
    a[x + 1][y] += 1
    a[x - 1][y] += 1
    a[x][y + 1] += 1
    a[x][y - 1] += 1


def medium(x, y, a):
    small(x, y, a)
    a[x + 1][y + 1] += 1
    a[x - 1][y + 1] += 1
    a[x - 1][y - 1] += 1
    a[x + 1][y - 1] += 1


def large(x, y, a):
    medium(x, y, a)
    a[x + 2][y] += 1
    a[x - 2][y] += 1
    a[x][y + 2] += 1
    a[x][y - 2] += 1


p = [[0] * 13 for i in range(13)]
while 1:
    try:
        x, y, s = map(int, input().split(','))
        if s == 1:
            small(x, y, p)
        elif s == 2:
            medium(x, y, p)
        elif s == 3:
            large(x, y, p)
    except:
        break

w, dens = 0, 0
for i in range(10):
    for j in range(10):
        if p[i][j] == 0:
            w += 1
        if p[i][j] >= dens:
            dens = p[i][j]

print(w)
print(dens)

Submission status: Accepted

Solution code:
p = [[0 for j in range(10)] for i in range(10)]

s1i = [-1, 0, 0, 1]
s1j = [0, -1, 1, 0]
s2i = [-1, -1, -1, 0, 0, 1, 1, 1]
s2j = [-1, 0, 1, -1, 1, -1, 0, 1]
s3i = [-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2]
s3j = [0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0]

while True:
  try:
    x, y, s = map(int, input().split(","))
  except:
    break

  p[y][x] += 1
  if s == 1:
    for k in range(len(s1i)):
      xx = x + s1j[k]
      yy = y + s1i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
  elif s == 2:
    for k in range(len(s2i)):
      xx = x + s2j[k]
      yy = y + s2i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
  else:
    for k in range(len(s3i)):
      xx = x + s3j[k]
      yy = y + s3i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
    
cnt = 0
m = 0
for i in range(10):
  #print(p[i])
  for j in range(10):
    if p[i][j] == 0:
      cnt += 1
    else:
      pass
    m = max(p[i][j], m)

#print()
print(cnt)
print(m)

Submission status: Accepted

Solution code:
if __name__ == '__main__':

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

	while True:
		try:
			x,y,s = map(int,input().split(","))
			if s == 0:
				break
			if s == 1:
				#自身
				DI[x][y] += 1
				#up
				if y >= 1 :
					DI[x][y-1] += 1
				#down
				if y <= 8:
					DI[x][y+1] += 1
				#left
				if x >= 1:
					DI[x-1][y] += 1
				#right
				if x <= 8:
					DI[x+1][y] += 1

			elif s == 2:
				#自身
				DI[x][y] += 1
				#up
				if y >= 1 :
					DI[x][y-1] += 1
				#up left
				if x >= 1 and y >= 1:
					DI[x-1][y-1] += 1
				#up right
				if x <= 8 and y >= 1 :
					DI[x+1][y-1] += 1
				#down
				if y <= 8:
					DI[x][y+1] += 1
				#down left
				if x >= 1 and y <= 8:
					DI[x-1][y+1] += 1
				#down right
				if x <= 8 and y <= 8 :
					DI[x+1][y+1] += 1
				#left
				if x >= 1:
					DI[x-1][y] += 1
				#right
				if x <= 8:
					DI[x+1][y] += 1

			else:
				#自身
				DI[x][y] += 1
				#up
				if y >= 1 :
					DI[x][y-1] += 1
				#up left
				if x >= 1 and y >= 1:
					DI[x-1][y-1] += 1
				#up right
				if x <= 8 and y >= 1 :
					DI[x+1][y-1] += 1
				#up +1
				if y >= 2 :
					DI[x][y-2] += 1
				#down
				if y <= 8:
					DI[x][y+1] += 1
				#down left
				if x >= 1 and y <= 8:
					DI[x-1][y+1] += 1
				#down right
				if x <= 8 and y <= 8 :
					DI[x+1][y+1] += 1
				#down + 1
				if y <= 7:
					DI[x][y+2] += 1
				#left
				if x >= 1:
					DI[x-1][y] += 1
				#left + 1
				if x >= 2:
					DI[x-2][y] += 1
				#right
				if x <= 8:
					DI[x+1][y] += 1
				#right + 1
				if x <= 7:
					DI[x+2][y] += 1



		except EOFError:
			break

#	for j in DI:
#		print(j)

	cnt = 0
	maxcnt = 0
	for k in DI:
		cnt += k.count(0)
		if maxcnt < max(k):
			maxcnt = max(k)
	print(cnt)
	print(maxcnt)

Submission status: Accepted

Solution code:
def small_ink(paper,x,y):
  paper[x][y] += 1
  if 0 <= x-1 and x-1 < 10:
    paper[x-1][y] += 1
  if 0 <= y-1 and y-1 < 10:
    paper[x][y-1] += 1
  if 0 <= x+1 and x+1 < 10:
    paper[x+1][y] += 1
  if 0 <= y+1 and y+1 < 10:
    paper[x][y+1] += 1
  return paper

def middle_ink(paper,x,y):
  paper = small_ink(paper,x,y)
  if (0 <= x-1 and x-1 < 10) and (0 <= y-1 and y-1 < 10):
    paper[x-1][y-1] += 1
  if (0 <= x-1 and x-1 < 10) and (0 <= y+1 and y+1 < 10):
    paper[x-1][y+1] += 1
  if (0 <= x+1 and x+1 < 10) and (0 <= y-1 and y-1 < 10):
    paper[x+1][y-1] += 1
  if (0 <= x+1 and x+1 < 10) and (0 <= y+1 and y+1 < 10):
    paper[x+1][y+1] += 1
  return paper

def large_ink(paper,x,y):
  paper = middle_ink(paper,x,y)
  if (0 <= x-2 and x-2 < 10):
    paper[x-2][y] += 1
  if (0 <= y-2 and y-2 < 10):
    paper[x][y-2] += 1
  if (0 <= y+2 and y+2 < 10):
    paper[x][y+2] += 1
  if (0 <= x+2 and x+2 < 10):
    paper[x+2][y] += 1
  return paper

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

while True:
  try:
    x,y,s = map(int, input().split(','))
  except EOFError:
    break
  if s == 1:
    paper = small_ink(paper,x,y)
  elif s == 2:
    paper = middle_ink(paper,x,y)
  elif s == 3:
    paper = large_ink(paper,x,y)

sum0 = 0
max_ink = 0
for i in range(10):
  for j in range(10):
    if paper[i][j] == 0:
      sum0 += 1
    if paper[i][j] > max_ink:
      max_ink = paper[i][j]
print(sum0)
print(max_ink)