-
Notifications
You must be signed in to change notification settings - Fork 2
/
cards.cpp
60 lines (52 loc) · 1.24 KB
/
cards.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
typedef long long ll;
ll first,second;
ll ans = -100000000000;
int gap = -1;
int main(){
cin >> first >> second;
if(first==0){
cout << -second*second << endl;
for(int x = 0;x<second;x++) cout << "x";
cout << endl;
return 0;
}
if(second==0){
cout << first*first << endl;
for(int x = 0;x<first;x++) cout << "o";
cout << endl;
return 0;
}
for(ll x = 1;x<=first;x++){//number of gaps
ll cur = x-1+(first-x+1)*(first-x+1);
ll minus = (x+1)*(second/(x+1))*(second/(x+1))+(second%(x+1))*(1+(second/(x+1))*2);
if(cur-minus>ans){
gap = x;
ans = cur-minus;
}
}
ll width = second/(gap+1);
ll bonus = second%(gap+1);
string done = "";
for(int x = 0;x<gap;x++){
for(int a = 0;a<width;a++){
done+='x';
}
if(bonus>0){
done+='x';
bonus--;
}
done+='o';
if(x==0){
for(int a = 0;a<first-gap;a++) done+='o';
}
}
for(int a = 0;a<width;a++){
done+='x';
}
cout << ans << endl << done << endl;
return 0;
}