A9458 | Cards
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
1. At first, the score is $0$ .
2. For each block of contiguous "o"s with length $x$ the score increases by $x^{2}$ .
3. 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 $2^{2}-1^{2}+3^{2}-2^{2}+1^{2}=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.
1. At first, the score is $0$ .
2. For each block of contiguous "o"s with length $x$ the score increases by $x^{2}$ .
3. 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 $2^{2}-1^{2}+3^{2}-2^{2}+1^{2}=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.
输入格式
The first line contains two space-separated integers $a$ and $b$ ( $0<=a,b<=10^{5}; a+b>=1$ ) — the number of "o" cards and the number of "x" cards.
输出格式
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.
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.
输入输出样例
输入 #1
2 3
输出 #1
-1 xoxox
输入 #2
4 0
输出 #2
16 oooo
输入 #3
0 4
输出 #3
-16 xxxx
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted