Codeforces Round #233 (Div. 1) A. Cards

7 篇文章 0 订阅
7 篇文章 0 订阅

A. Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 x2.
  3. For each block of contiguous "x"s with length y the score decreases by y2.
 

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.

Input

The first line contains two space-separated integers a and b (0 ≤ a, b ≤ 105a + b ≥ 1) — the number of "o" cards and the number of "x" cards.

Output

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.

Sample test(s)
Input
2 3
Output
-1
xoxox
Input
4 0
Output
16
oooo
Input
0 4
Output
-16
xxxx

可以知道一连串的字符被拆开后,平方和是小于之前的,所以,对于o尽可能不拆,拆的话每次拆一个出来分开x串,而且也可以知道分x串的时候,尽可能平均最好。

所以,枚举把x串拆成i段,然后如果还剩余a个x字符,那么就再把这a个字符平均分给i段。


#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
using namespace std;
int main()
{
	long long a,b,ans,div;
	cin>>a>>b;
	ans=a*a-b*b;
	div=1;
	for(long long i=2;i<=b&&i-2<a;i++)
	{
		long long t=i-2+(a-(i-2))*(a-(i-2))-(b%i)*(b/i+1)*(b/i+1)-(i-b%i)*(b/i)*(b/i);
		if(t>ans)
		{
			ans=t;
			div=i;
		}
	}
	string s;
	if(div>1)
		a-=div-2;
	long long n=b%div,m=div-n,len=b/div;
	if(n>0)
	{
		for(long long i=0;i<=len;i++)
			s+='x';
		n--;
	}
	else
	{
		for(long long i=0;i<len;i++)
			s+='x';
		m--;
	}
	for(long long i=0;i<a;i++)
		s+='o';
	for(long long i=0;n!=0||m!=0;i++)
	{
		if(i)
			s+='o';
		if(n>0)
		{
			for(long long j=0;j<=len;j++)
				s+='x';
			n--;
		}
		else
		{
			for(long long j=0;j<len;j++)
				s+='x';
			m--;
		}
	}
	cout<<ans<<endl<<s;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值