CF63D.Dividing Island
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A revolution took place on the Buka Island. New government replaced the old one. The new government includes n parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island.
The island can be conventionally represented as two rectangles a × b and c × d unit squares in size correspondingly. The rectangles are located close to each other. At that, one of the sides with the length of a and one of the sides with the length of c lie on one line. You can see this in more details on the picture.

The i-th party is entitled to a part of the island equal to x__i unit squares. Every such part should fully cover several squares of the island (it is not allowed to cover the squares partially) and be a connected figure. A "connected figure" presupposes that from any square of this party one can move to any other square of the same party moving through edge-adjacent squares also belonging to that party.
Your task is to divide the island between parties.
布卡岛发生了一场革命,新政府取代了旧政府。新政府由 n 个政党组成,每个政党根据其对革命的贡献,有权获得岛上相应面积的土地。然而,他们无法直接将岛屿划分为若干部分。
该岛可被形式化地表示为两个矩形,尺寸分别为 a×b 和 c×d 个单位正方形。这两个矩形彼此紧邻放置;其中,长度为 a 的一条边与长度为 c 的一条边共线。详情请参见下图:

第 i 个政党有权获得大小为 xi 个单位正方形的土地。每块分配给政党的土地必须完全覆盖岛上的若干完整单位正方形(不允许部分覆盖任何正方形),且必须构成一个连通图形。所谓“连通图形”,是指:对于该政党所占区域中的任意两个单位正方形,均存在一条路径,使得路径上所有单位正方形均属于该政党,且相邻正方形之间共享一条边(即边相邻)。
你的任务是将该岛在各政党之间进行划分。
输入格式
The first line contains 5 space-separated integers — a, b, c, d and n (1 ≤ a, b, c, d ≤ 50, b ≠ d, 1 ≤ n ≤ 26). The second line contains n space-separated numbers. The i-th of them is equal to number x__i (1 ≤ x__i ≤ a × b + c × d). It is guaranteed that
.
第一行包含 5 个用空格分隔的整数:a、b、c、d 和 n(其中 1≤a,b,c,d≤50,b=d,1≤n≤26)。第二行包含 n 个用空格分隔的数字,其中第 i 个数字等于 xi(1≤xi≤a×b+c×d)。保证有
。
输出格式
If dividing the island between parties in the required manner is impossible, print "NO" (without the quotes). Otherwise, print "YES" (also without the quotes) and, starting from the next line, print max(b, d) lines each containing a + c characters. To mark what square should belong to what party, use lowercase Latin letters. For the party that is first in order in the input data, use "a", for the second one use "b" and so on. Use "." for the squares that belong to the sea. The first symbol of the second line of the output data should correspond to the square that belongs to the rectangle a × b. The last symbol of the second line should correspond to the square that belongs to the rectangle c × d.
If there are several solutions output any.
如果无法按要求的方式将岛屿划分给各政党,则输出 "NO"(不带引号)。否则,输出 "YES"(同样不带引号),并在下一行起输出 max(b, d) 行,每行包含 a + c 个字符。为标识每个方格所属的政党,使用小写拉丁字母:对输入数据中顺序排第一的政党使用 "a",第二的使用 "b",依此类推;用 "." 表示属于海洋的方格。输出数据第二行的第一个字符应对应于矩形 a × b 所占的方格,第二行的最后一个字符应对应于矩形 c × d 所占的方格。
若存在多种可行方案,输出任意一种即可。
输入输出样例
输入#1
3 4 2 2 3 5 8 3
输出#1
YES aaabb aabbb cbb.. ccb..
输入#2
3 2 1 4 4 1 2 3 4
输出#2
YES abbd cccd ...d ...d
输入解题思路,AI测评打分。不知道怎么写?