# 【AtCoder Beginner Contest 099】Solution / Editorial / 题解

Posted on

## 比赛地址

### C – Strange Bank

#### Statement

To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:

1 yen (the currency of Japan)

6 yen, 62(=36) yen, 63(=216) yen, …

9 yen, 92(=81) yen, 93(=729) yen, …

At least how many operations are required to withdraw exactly N yen in total?

It is not allowed to re-deposit the money you withdrew.

### D – Good Grid

#### Statement

There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.

These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color ci,j.

We say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1≤i,j,x,y≤N:

If (i+j)%3=(x+y)%3, the color of (i,j) and the color of (x,y) are the same.
If (i+j)%3≠(x+y)%3, the color of (i,j) and the color of (x,y) are different.
Here, X%Y represents X modulo Y.

We will repaint zero or more squares so that the grid will be a good grid.

For a square, the wrongness when the color of the square is X before repainting and Y after repainting, is DX,Y.

Find the minimum possible sum of the wrongness of all the squares.