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

来源:互联网 发布:笔记本电脑录像软件 编辑:程序博客网 时间:2024/05/16 19:05

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" andb 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 lengthx the score increases by x2.
  3. For each block of contiguous "x"s with lengthy 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 equals22 - 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 andb (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 thek-th card of the deck contains "o", thek-th character must be "o". If thek-th card of the deck contains "x", thek-th character must be "x". The number of "o" characters must be equal toa, and the number of "x " characters must be equal tob. 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 thecin, cout streams or the%I64d specifier.

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

可以知道一连串的字符被拆开后,平方和是小于之前的,所以,对于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
原创粉丝点击