QOJ.ac

QOJ

Límite de tiempo: 4 s Límite de memoria: 1024 MB Puntuación total: 100

#23946. 庭院 2

Estadísticas

题目描述

JOI 庭院呈正方形,被划分为纵向 $N$ 行、横向 $N$ 列的方格状。从上往下第 $i$ 行($1 \le i \le N$)、从左往右第 $j$ 列($1 \le j \le N$)的格子称为区域 $(i, j)$。

由于 JOI 庭院的土壤不够肥沃,每个区域只能种植特定 $1$ 种颜色的花,且最多只能种 $1$ 朵。具体而言,在区域 $(i, j)$ 中,当 $A_{i, j} =$ R 时只能种红花,当 $A_{i, j} =$ Y 时只能种黄花,当 $A_{i, j} =$ B 时只能种蓝花,且最多只能种 $1$ 朵。

现在,该庭院的管理者 K 理事长为了在航拍时更加美观,打算按以下步骤种花:

  1. 确定表示大小的整数 $r$。其中必须满足 $0 \le r \le (N-1) \div 2$。
  2. 确定表示中心的区域 $(x, y)$。其中必须满足 $r+1 \le x \le N-r$ 且 $r+1 \le y \le N-r$。
  3. 分别从红、黄、蓝中选定颜色 $c_0, c_1, c_2, \dots, c_r$。
  4. 对于每个区域 $(x', y')$,根据 $d = |x'-x| + |y'-y|$ 按如下规则种花,其中 $|t|$ 表示 $t$ 的绝对值:
    • 若 $d \le r$,则在区域 $(x', y')$ 中种植颜色为 $c_d$ 的花。
    • 若 $d > r$,则在区域 $(x', y')$ 中不种花。

给定庭院的大小以及每个区域可以种植的花的颜色信息,请编写程序求出 K 理事长最多可以种植多少朵花。

数据范围

  • $3 \le N \le 3\,500$。
  • $A_{i, j}$ 为 R、Y、B 之一($1 \le i \le N, 1 \le j \le N$)。
  • $N$ 是整数。

子任务

  1. ($4$ 分)$N = 3$。
  2. ($13$ 分)$N \le 50$。
  3. ($17$ 分)$N \le 800$。
  4. ($14$ 分)满足 $A_{i, j} \neq$ R 的 $(i, j)$($1 \le i \le N, 1 \le j \le N$)不超过 $5$ 个。
  5. ($16$ 分)对于任意 $(i, j)$($1 \le i \le N-1, 1 \le j \le N-1$),在 $A_{i, j}$、$A_{i, j+1}$、$A_{i+1, j}$、$A_{i+1, j+1}$ 中至少有 $3$ 个 R。
  6. ($36$ 分)无额外约束。

输入格式

输入按以下格式给出:

N
A_{1,1}   A_{1,2}   …   A_{1,N}
A_{2,1}   A_{2,2}   …   A_{2,N}
︙
A_{N,1}   A_{N,2}   …   A_{N,N}

输出格式

输出 $1$ 行,表示 K 理事长最多可以种植的花的数量。

样例 1

输入

3
RYR
YBY
BYY

输出

5

若取 $r = 1$,$(x, y) = (2, 2)$,并选定 $c_0$ 为蓝色、$c_1$ 为黄色,则可以如下图所示种植 $5$ 朵花。其中,背景颜色表示各个区域可以种植的花的颜色。

由于不存在能够种植 $6$ 朵或更多花的方法,因此输出 $5$。

该样例满足子任务 $1, 2, 3, 6$ 的限制。

样例 2

输入

9
YYRYBBBYR
BYYRRBYBB
RBRRBRBBY
RYRBRYRBR
YYBRYYYRB
RRYBRYRBR
RBYRBRBRB
BRYYRBBBR
RBBBYBRRY

输出

25

若取 $r = 3$,$(x, y) = (5, 6)$,并选定 $c_0$ 为黄色、$c_1$ 为黄色、$c_2$ 为红色、$c_3$ 为蓝色,则可以如下图所示种植 $25$ 朵花。其中,背景颜色表示各个区域可以种植的花的颜色。

由于不存在能够种植 $26$ 朵或更多花的方法,因此输出 $25$。

该样例满足子任务 $2, 3, 6$ 的限制。

样例 3

输入

6
RBYRBY
BYRBYR
YRBYRB
RBYRBY
BYRBYR
YRBYRB

输出

1

该样例满足子任务 $2, 3, 6$ 的限制。

样例 4

输入

20
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRBRRRRRRRRRRRRYRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRYRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRYRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRBR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRR

输出

85

该样例满足子任务 $2, 3, 4, 5, 6$ 的限制。

样例 5

输入

10
RRRRRRRRRR
RYRRRRRRRR
RRRRYRRRRR
RBRRRRRRRR
RRRRRRRRYR
RBRRRRRRRR
RRRRBRRRRR
RBRRRRRRRR
RRRRRRRRYR
RRRRRRRRRR

输出

25

该样例满足子任务 $2, 3, 5, 6$ 的限制。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.