CF398A.Cards
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
User ainta loves to play with cards. He has a cards containing letter "o" and b cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below.
- At first, the score is 0.
- For each block of contiguous "o"s with length x the score increases by _x_2.
- For each block of contiguous "x"s with length y the score decreases by _y_2.
For example, if a = 6, b = 3 and ainta have arranged the cards in the order, that is described by string "ooxoooxxo", the score of the deck equals 22 - 12 + 32 - 22 + 12 = 9. That is because the deck has 5 blocks in total: "oo", "x", "ooo", "xx", "o".
User ainta likes big numbers, so he wants to maximize the score with the given cards. Help ainta make the score as big as possible. Note, that he has to arrange all his cards.
用户 ainta 喜欢玩卡片。他有 a 张写有字母 “o” 的卡片和 b 张写有字母 “x” 的卡片。他将这些卡片排成一行,并按以下公式计算该排列的得分:
- 初始得分为 0;
- 对于每一个长度为 x 的连续 “o” 字符块,得分增加 x2;
- 对于每一个长度为 y 的连续 “x” 字符块,得分减少 y2。
例如,若 a=6、b=3,且 ainta 将卡片按字符串 "ooxoooxxo" 所示顺序排列,则该排列的得分为 22−12+32−22+12=9。这是因为该排列共包含 5 个字符块:“oo”、“x”、“ooo”、“xx”、“o”。
用户 ainta 喜欢大的数字,因此他希望在给定卡片数量的前提下使得分尽可能大。请帮助 ainta 实现最大可能得分。注意:他必须用完所有卡片。
输入格式
The first line contains two space-separated integers a and b (0 ≤ a, b ≤ 105; a + b ≥ 1) — the number of "o" cards and the number of "x" cards.
第一行包含两个以空格分隔的整数 a 和 b(0 ≤ a, b ≤ 105;a + b ≥ 1)——分别表示“o”卡片和“x”卡片的数量。
输出格式
In the first line print a single integer v — the maximum score that ainta can obtain.
In the second line print a + b characters describing the deck. If the k-th card of the deck contains "o", the k-th character must be "o". If the k-th card of the deck contains "x", the k-th character must be "x". The number of "o" characters must be equal to a, and the number of "x " characters must be equal to b. If there are many ways to maximize v, print any.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
第一行输出一个整数 v —— ainta 能获得的最高得分。
第二行输出 a+b 个字符,表示牌组。若牌组中第 k 张牌为 "o",则第 k 个字符必须为 "o";若第 k 张牌为 "x",则第 k 个字符必须为 "x"。其中 "o" 的个数必须恰好为 a,"x" 的个数必须恰好为 b。若存在多种方案可使 v 最大化,输出任意一种即可。
请注意:在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。
输入输出样例
输入#1
2 3
输出#1
-1 xoxox
输入#2
4 0
输出#2
16 oooo
输入#3
0 4
输出#3
-16 xxxx
输入解题思路,AI测评打分。不知道怎么写?