cswork / OA打开练习工作台

ZalandoOA #1

Longest String Without AAA or BBB

估计中等可在线判题

考点(AI 标注)贪心调度字符串

There are three kinds of indivisible two-letter blocks, AA, AB, and BB, with counts a, b, and c. You may choose some of the blocks and concatenate them whole in any order to build the longest string that contains neither three consecutive A's nor three consecutive B's. Blocks cannot be split or reversed, and each block is used at most once. Return any longest result; the lexicographically smallest is not required.

输入格式

One line with three integers a b c, giving the counts of AA, AB, and BB blocks in that order. 0≤a,b,c≤10, a+b+c≥1. This corresponds to the original problem's three parameters AA, AB, BB and its non-empty result guarantee, and keeps the original numeric ranges in full.

输出格式

Output one line with a non-empty string containing only A and B, without quotes, spaces, or block separators. It must be built from available whole blocks, contain neither AAA nor BBB, and have maximum length. Any of multiple optimal results is accepted.

样例 1

输入:

5 0 2

输出:

AABBAABBAA

样例 2

输入:

1 2 1

输出:

AABBABAB

样例 3

输入:

0 2 0

输出:

ABAB

样例 4

输入:

0 0 10

输出:

BB

样例说明

The four original inputs are kept. In example 1, the original text's AA-BB-AA-BB-AA correctly concatenates to AABBAABBAA, length 10; the original output was missing an A. In example 2, AA-BB-AB-AB gives AABBABAB, length 8, using all 4 blocks; the original length-7 output and the invalid candidate in its explanation have been corrected. Example 3 uses two AB blocks to get ABAB; example 4 can use at most one BB, giving BB. There is no separate raw version.