No.3410 Happiest Art
タグ : / 解いたユーザー数 19
作問者 :
kazuppa
/ テスター :
Cafe1942
AwashAmityOak
Story
Kazuppa, Awash, Yu~, and Ruku are preparing for a Christmas party. Kazuppa is in charge of drawing a picture.
Kazuppa: "I'm quite confident in how bad I am at drawing, so I think Yu~ would be better suited than me for the job of drawing (mutter mutter)"
Even so, he draws a picture for everyone. "I'll draw a picture that makes everyone happy!" is his declaration and his public stance, but since he dislikes some of the people, his goal is to please only certain people and become happy himself. Given these complicated wishes, please tell him a picture that makes him as happy as possible.
Problem Statement
You are given $N$ grids $S_1,S_2,...,S_N$. The $x\ (1\leq x\leq N)$-th grid has $H$ rows and $W$ columns, and each $S_{x,i,j}$ is . or #. Each grid $x$ also has a number $F_x$ assigned to it.
Kazuppa chooses one grid with $H$ rows and $W$ columns consisting of . and #. Hereafter, the chosen grid is called $g$.
For the grid $g$, define an integer sequence $a_1,a_2,...,a_N$ as follows.
- For $1\leq x\leq N$, $a_x=1$ if and only if the number of pairs $(i,j)$ satisfying $S_{x,i,j}\neq g_{i,j}$ is at most $F_x$. Otherwise, $a_x=0$.
Kazuppa's happiness for the grid $g$ is defined as $\sum_{i=1}^U a_i-\sum_{i=U+1}^N a_i$.
Tell him the maximum happiness he can achieve by choosing an optimal grid, along with one grid that achieves it.
Constraints
- $1\leq N\leq 100$
- $0\leq U\leq N$
- $1\leq H,W\leq 100$
- $F_i\in\{0,1\}$
- $S_{x,i,j}$ is
.or# - $N,U,H,W,F_i$ are all integers
Input
$N\ U$
$H\ W$
$F_1$
$S_{1,1,1},S_{1,1,2},\cdots,S_{1,1,W}$
$S_{1,2,1},S_{1,2,2},\cdots,S_{1,2,W}$
$\vdots$
$S_{1,H,1},S_{1,H,2},\cdots,S_{1,H,W}$
$F_2$
$S_{2,1,1},S_{2,1,2},\cdots,S_{2,1,W}$
$S_{2,2,1},S_{2,2,2},\cdots,S_{2,2,W}$
$\vdots$
$S_{2,H,1},S_{2,H,2},\cdots,S_{2,H,W}$
$\vdots$
$F_N$
$S_{N,1,1},S_{N,1,2},\cdots,S_{N,1,W}$
$S_{N,2,1},S_{N,2,2},\cdots,S_{N,2,W}$
$\vdots$
$S_{N,H,1},S_{N,H,2},\cdots,S_{N,H,W}$
Output
On line $1$, output the maximum achievable value of Kazuppa's happiness. On the $H$ lines starting from line $2$, output one grid that actually achieves it. Print a newline at the end.
If there are multiple solutions, you may output any of them.
Sample
Sample 1
Input
4 3 3 3 0 #.# .#. #.# 1 #.# ... #.# 0 #.# ... #.# 0 #.# ... #.#
Output
2 #.# .#. #.#
For example, if $g=($#.#$,$...$,$#.#$)$, then $a=(0,1,1,1)$, so Kazuppa's happiness is $1$.
Alternatively, if $g=($#.#$,$.#.$,$#.#$)$, then $a=(1,1,0,0)$, so Kazuppa's happiness is $2$.
Happiness $3$ cannot be achieved for this input, so this is the correct output (for this input, this is the only solution).
Sample 2
Input
1 1 1 1 1 #
Output
1 #
Both $($.$)$ and $($#$)$ give happiness $1$, so you may output either of them.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。