Search is not available for this dataset
name
stringlengths 2
88
| description
stringlengths 31
8.62k
| public_tests
dict | private_tests
dict | solution_type
stringclasses 2
values | programming_language
stringclasses 5
values | solution
stringlengths 1
983k
|
---|---|---|---|---|---|---|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;
int x, y, z;
multiset<string> s;
int main() {
cin >> x >> y >> z;
rep(i, 1, x) s.insert("a");
rep(i, 1, y) s.insert("b");
rep(i, 1, z) s.insert("c");
while (s.size() > 1) {
string ss = *s.begin() + *--s.end();
s.erase(s.begin());
s.erase(--s.end());
s.insert(ss);
}
cout << *s.begin() << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
multiset<string> S;
multiset<string>::iterator itL, itR;
int X, Y, Z;
int main() {
scanf("%d%d%d", &X, &Y, &Z);
while(X--) S.insert("a");
while(Y--) S.insert("b");
while(Z--) S.insert("c");
while(S.size() > 1) {
itL = S.begin();
itR = S.end(); itR--;
S.insert((*itL) + (*itR));
S.erase(itL); S.erase(itR);
}
printf("%s", S.begin()->c_str());
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <set>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
multiset <string> s;
int main()
{
int X,Y,Z;
scanf("%d%d%d",&X,&Y,&Z);
for(int i = 1;i <= X; ++ i)
s.insert("a");
for(int i = 1;i <= Y; ++ i)
s.insert("b");
for(int i = 1;i <= Z; ++ i)
s.insert("c");
multiset <string>::iterator it;
it = s.end();
it--;
while(s.size() > 1)
{
it = s.begin();
string a = *it;
s.erase(it);
it = s.end();
it--;
string b = *it;
s.erase(it);
string c = a + b;
s.insert(c);
}
cout<<*s.begin()<<endl;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
const db PI = acos(-1);
const db ERR = 1e-12;
const int MX = 2005;
const int MM = 1000000007;
int main()
{
int A, B, C;
multiset<string> L;
scanf("%d%d%d", &A, &B, &C);
for(int i = 1; i <= A; i++) L.insert((string)"a");
for(int i = 1; i <= B; i++) L.insert((string)"b");
for(int i = 1; i <= C; i++) L.insert((string)"c");
while(L.size() > 1){
string P = *L.begin();
while(*L.begin() == P){
L.erase(L.begin());
auto it = L.end(); --it;
string tmp = P + *it;
L.erase(it);
L.insert(tmp);
}
}
cout << *L.begin() << "\n";
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
multiset<string > s;
int a,b,c;
int main()
{
scanf("%d%d%d",&a,&b,&c);
while (a--)s.insert("a");
while (b--)s.insert("b");
while (c--)s.insert("c");
while (s.size()>1)
{
string t=*s.begin()+ *--s.end();
s.erase(s.begin());
s.erase(--s.end());
s.insert(t);
}
cout<<*s.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <set>
#include <iostream>
using std::string;
std::multiset<string> s;
int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
s.insert("a");
}
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
s.insert("b");
}
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
s.insert("c");
}
while(s.size() > 1) {
string a = *s.begin();
string b = *(--s.end());
s.erase(s.begin());
s.erase(--s.end());
s.insert((string)(a + b));
}
std::cout << *s.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
multiset <string> s;
int x,y,z;
int main(){
cin>>x>>y>>z;
while(x--)s.insert("a");
while(y--)s.insert("b");
while(z--)s.insert("c");
while(s.size()>1){
string a=*s.begin();
string b=*s.rbegin();
s.erase(s.begin());
s.erase(--s.end());
s.insert(a+b);
}
cout<<*s.begin()<<endl;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<algorithm>
using namespace std;
const int maxn=200+2;
int tmp,cnt;
string str[maxn];
int main(){
for (char ch='a';ch<='c';ch++){
cin>>tmp;
while (tmp--) str[cnt++]+=ch;
}
while (cnt>1){
sort(str,str+cnt);
str[0]+=str[--cnt];
}
cout<<str[0];
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
multiset<string> s;
int x,y,z;
int main()
{
cin>>x>>y>>z;
for(int i=1;i<=x;i++) s.insert("a");
for(int i=1;i<=y;i++) s.insert("b");
for(int i=1;i<=z;i++) s.insert("c");
while(s.size()>1)
{
string t=*s.begin()+*--s.end();
s.erase(s.begin());
s.erase(--s.end());
s.insert(t);
}
cout<<*s.begin();
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int r,b,g;
multiset<string> st;
int main()
{
// freopen("beargguy.in","r",stdin);
// freopen("beargguy.out","w",stdout);
scanf("%d%d%d",&r,&b,&g);
for(int i=1;i<=r;i++) st.insert("a");
for(int i=1;i<=b;i++) st.insert("b");
for(int i=1;i<=g;i++) st.insert("c");
while(st.size()>1)
{
string s=*st.begin(),t=*st.rbegin();
st.erase(st.lower_bound(s));
st.erase(st.lower_bound(t));
st.insert(s+t);
}
puts((*st.begin()).c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<set>
#include<cstdio>
#include<cctype>
#include<string>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
int main() {
std::multiset<std::string> set;
for(register int i=getint();i;i--) set.insert("a");
for(register int i=getint();i;i--) set.insert("b");
for(register int i=getint();i;i--) set.insert("c");
while(set.size()>1) {
std::string s=*set.begin(),t=*set.rbegin();
set.erase(set.lower_bound(s));
set.erase(set.lower_bound(t));
set.insert(s+t);
}
printf("%s\n",(*set.begin()).c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chkmax(T& a,T b){return a<b?a=b,1:0;}
template<class T> inline bool chkmin(T& a,T b){return a>b?a=b,1:0;}
template<typename T> inline T& read(T& x){
static char c; bool flag=0;
while(!isdigit(c=getchar())) if(c=='-') flag=1;
for(x=c-'0';isdigit(c=getchar());(x*=10)+=c-'0');
if(flag) x=-x;
return x;
}
int x,y,z;
multiset<string> s;
int main(){
#ifdef xffyjq
freopen("exec.in","r",stdin);
freopen("exec.out","w",stdout);
#endif
read(x); read(y); read(z);
for(int i=1;i<=x;i++) s.insert("a");
for(int i=1;i<=y;i++) s.insert("b");
for(int i=1;i<=z;i++) s.insert("c");
for(int i=1;i<x+y+z;i++){
auto it1=s.begin(),it2=s.end(); --it2;
s.insert(*it1+*it2);
s.erase(it1); s.erase(it2);
}
cout<<*s.begin()<<endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string>s;
int main(){
scanf("%d%d%d",&a,&b,&c);
for(int i=1;i<=a;++i)s.insert("a");
for(int i=1;i<=b;++i)s.insert("b");
for(int i=1;i<=c;++i)s.insert("c");
while(s.size()>1){
string ss=*s.begin()+*--s.end();
s.erase(s.begin());
s.erase(--s.end());
s.insert(ss);
}
cout<<*s.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define up(i,j,k) for (int i = (j); i <= (k); i++)
#define down(i,j,k) for (int i = (j); i >= (k); i--)
#define DEBUG printf("Passing [%s] in LINE %d\n", __FUNCTION__, __LINE__)
#define lb long double
#define ll long long
#define ull unsigned long long
#define mp std::make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define mem(a) memset((a), 0, sizeof(a))
#define File(x) \
freopen("" #x ".in", "r", stdin); \
freopen("" #x ".out", "w", stdout);
#define int long long
inline int read() {
int data = 0, w = 1; char ch = 0;
while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (ch >= '0' && ch <= '9') { data = data * 10 + ch - '0'; ch = getchar(); }
return data * w;
}
inline void print (int v) {
if (v < 0) { putchar('-'); v = -v; }
if (v > 9) print(v / 10);
putchar(v % 10 + '0');
}
std::multiset <std::string> s;
signed main () {
int x, y, z;
x = read(); y = read(); z = read();
up (i, 1, x) s.insert("a");
up (i, 1, y) s.insert("b");
up (i, 1, z) s.insert("c");
while (s.size() ^ 1) {
auto l = *s.begin(), r = *s.rbegin();
s.erase(s.lower_bound(l));
s.erase(s.lower_bound(r));
s.insert(l + r);
}
std::cout << *s.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | a,b,c = map(int,input().split())
L = [[0] for _ in range(a)] + [[1] for _ in range(b)] + [[2] for _ in range(c)]
while len(L) > 1:
L[0] += L.pop()
L.sort()
print(''.join(('a','b','c')[i] for i in L[0])) |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<algorithm>
using namespace std;
int X, Y, Z, n;
int D[51][51][51][51], LCP[51], oto[51];
char p[60], q[110];
bool Pos(int pv){
int i, j, k, l;
for(i=1;i<=pv;i++){
for(j=0;j<=pv-i;j++){
if(p[j]!=p[i+j]){
if(p[j] > p[i+j])return false;
else break;
}
}
}
oto[0] = -1;
for(i=0;i<=pv;i++){
int t = oto[i];
while(t!=-1 && p[i]!=p[t])t=oto[t];
oto[i+1] = t+1;
}
int tt = oto[pv+1];
for(i=pv+1;i<n;i++){
p[i] = p[tt];
tt++;
oto[i+1]=oto[i]+1;
}
LCP[0] = 0;
for(i=1;i<=pv;i++){
if(p[LCP[i-1]] > p[i])return false;
int t = LCP[i-1];
while(t!=-1 && p[t]!=p[i])t = oto[t];
LCP[i] = t+1;
}
int c1 = 0, c2 = 0, c3 = 0;
for(i=0;i<=pv;i++){
if(p[i]=='a')c1++;
if(p[i]=='b')c2++;
if(p[i]=='c')c3++;
}
for(i=0;i<=X;i++)for(j=0;j<=Y;j++)for(k=0;k<=Z;k++)for(l=0;l<=n;l++)D[i][j][k][l]=0;
D[c1][c2][c3][pv+1] = 1;
//printf("%s\n",p);
for(i=c1;i<=X;i++){
for(j=c2;j<=Y;j++){
for(k=c3;k<=Z;k++){
for(l=0;l<=n;l++){
if(!D[i][j][k][l])continue;
//printf("%d %d %d %d\n",i,j,k,l);
int tp = l;
if(i!=X && p[tp] <= 'a'){
int t = tp;
while(t!=-1 && p[t]!='a')t = oto[t];
D[i+1][j][k][t+1] = 1;
}
if(j!=Y && p[tp] <= 'b'){
int t = tp;
while(t!=-1 && p[t]!='b')t = oto[t];
D[i][j+1][k][t+1] = 1;
}
if(k!=Z && p[tp] <= 'c'){
int t = tp;
while(t!=-1 && p[t]!='c')t = oto[t];
D[i][j][k+1][t+1] = 1;
}
}
}
}
}
for(i=0;i<=n;i++){
if(!D[X][Y][Z][i])continue;
//printf("%d\n",i);
for(j=0;j<i;j++)q[j] = p[j];
for(j=0;j<n;j++)q[i+j] = p[j];
int ck = 0;
for(j=0;j<=i;j++){
for(k=0;k<n;k++){
if(p[k]!=q[j+k]){
if(p[k] > q[j+k])ck = 1;
else break;
}
}
}
if(!ck){
return true;
}
}
return false;
}
int main(){
int i, j, c1 = 0, c2 = 0, c3 = 0;
scanf("%d%d%d",&X,&Y,&Z);
n = X+Y+Z;
for(i=0;i<n;i++){
p[i] = 'c';
c3++;
if(c3 <= Z && Pos(i)){
if(i!=0 || (!X&&!Y))continue;
}
c3--,c2++;
p[i] = 'b';
if(c2 <= Y && Pos(i)){
if(i!=0 || !X)continue;
}
c2--,c1++;
p[i] = 'a';
}
printf("%s\n",p);
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
for (auto i : a) cerr << i << ' ';\
cerr << '\n'
#define eb emplace_back
#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif
template<typename T>
inline void setmax(T& a, T b) {
if (a < b) a = b;
}
template<typename T>
inline void setmin(T& a, T b) {
if (a > b) a = b;
}
const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;
string min_cyclic_shift (string s) {
s += s;
int n = (int) s.length();
int i=0, ans=0;
while (i < n/2) {
ans = i;
int j=i+1, k=i;
while (j < n && s[k] <= s[j]) {
if (s[k] < s[j])
k = i;
else
++k;
++j;
}
while (i <= k) i += j - k;
}
return s.substr (ans, n/2);
}
vector<string> gen(int x, int y, int z) {
if (x == 0 && y == 0 && z == 0) {
return {""};
}
vector<string> ans;
if (x) for (string s : gen(x - 1, y, z))
ans.eb(s + "a");
if (y) for (string s : gen(x, y - 1, z))
ans.eb(s + "b");
if (z) for (string s : gen(x, y, z - 1))
ans.eb(s + "c");
return ans;
}
string brute(int x, int y, int z) {
vector<string> ss = gen(x, y, z);
string ans = min_cyclic_shift(ss[0]);
for (string s : ss)
setmax(ans, min_cyclic_shift(s));
return ans;
}
const int N = 52;
//string glob[N][N][N];
string solve(int x, int y, int z) {
if (x + y + z <= 4) return brute(x, y, z);
//cerr << "SOLVE: " << x << ' ' << y << ' ' << z << '\n';
//if (!glob[x][y][z].empty()) return glob[x][y][z];
if (y == 0 && z == 0) {
string ans;
forn(i, 0, x) ans += "a";
return ans;
//forn(i, 0, x) glob[x][y][z] += "a";
//return glob[x][y][z];
}
if (x == 0) {
string s = solve(y, z, 0);
for (char& c : s) ++c;
//glob[x][y][z] = s;
return s;
}
if (y == 0) {
string s = solve(x, z, 0);
for (char& c : s) if (c == 'b') c = 'c';
//glob[x][y][z] = s;
return s;
}
vector<string> lets(3);
lets[0] = "a";
while (z >= x) {
lets[0] += "c";
z -= x;
}
string ans, s;
if (z + y >= x) {
lets[1] = lets[0];
lets[0] += "b";
lets[1] += "c";
lets[2] = "b";
x -= z;
y -= x;
s = solve(x, z, y);
} else {
lets[1] = lets[0];
lets[2] = lets[0];
lets[1] += "b";
lets[2] += "c";
s = solve(x - y - z, y, z);
}
for (char c : s) ans += lets[c - 'a'];
//glob[x][y][z] = ans;
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
int x, y, z;
cin >> x >> y >> z;
cout << solve(x, y, z) << '\n';
/*
forn(x, 0, 6) forn(y, 0, 6) forn(z, 0, 6) {
string s1 = solve(x, y, z), s2 = brute(x, y, z);
if (s1 != s2) {
cout << "ERROR!: " << x << ' ' << y << ' ' << z << '\n';
cout << s1 << ' ' << s2 << '\n';
return 0;
}
}*/
//int x = 4, y = 2, z = 3;
//cout << solve(x, y, z) << '\n';
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | /* Stay hungry, stay foolish. */
/* Copyright by HenryLi */
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<sstream>
#include<stack>
#include<ctime>
#include<cmath>
#include<cctype>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<bitset>
#include<complex>
using namespace std;
template <class _T> inline void read(_T &_x) {
int _t; bool _flag=false;
while((_t=getchar())!='-'&&(_t<'0'||_t>'9')) ;
if(_t=='-') _flag=true,_t=getchar(); _x=_t-'0';
while((_t=getchar())>='0'&&_t<='9') _x=_x*10+_t-'0';
if(_flag) _x=-_x;
}
typedef long long LL;
int main() {
//freopen("fuck.in","r",stdin);
//freopen("fuck.out","w",stdout);
multiset<string> s;
int a, b, c;
read(a), read(b), read(c);
for (int i = 1; i <= a; ++i) s.insert("a");
for (int i = 1; i <= b; ++i) s.insert("b");
for (int i = 1; i <= c; ++i) s.insert("c");
while (s.size() > 1) {
string t = *s.begin() + *--s.end();
s.erase(s.begin()), s.erase(--s.end());
s.insert(t);
}
cout << *s.begin() << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | java | // package other2017.codefestival2017.qualb;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
int n = x + y + z;
String ans = "";
for (int i = 0; i < n ; i++) {
if (z >= 1 && isOK(ans + "c", x, y, z-1)) {
z--;
ans += "c";
} else if (y >= 1 && isOK(ans + "b", x, y-1, z)) {
y--;
ans += "b";
} else {
x--;
ans += "a";
}
}
out.println(ans);
out.flush();
}
static boolean isOK(String prefix, int x, int y, int z) {
int prefixState = 0;
for (int i = 1 ; i< prefix.length() ; i++) {
String l = prefix.substring(i, prefix.length());
if (prefix.startsWith(l)) {
prefixState = Math.max(prefixState, l.length());
} else {
if (l.compareTo(prefix) < 0) {
// muri
return false;
}
}
}
int n = prefix.length();
int[][] stateTable = new int[n][3];
for (int i = 0; i < n ; i++) {
for (int j = 0; j < 3 ; j++) {
String s = prefix.substring(0, i) + (char)('a' + j);
if (prefix.startsWith(s)) {
stateTable[i][j] = (s.length() == n) ? 0 : s.length();
} else if (s.compareTo(prefix) < 0) {
stateTable[i][j] = -1;
} else {
stateTable[i][j] = 0;
}
}
}
int L = x+y+z;
int[][][][] dp = new int[L+1][y+1][z+1][n+1];
dp[L][y][z][prefixState] = 1;
for (int i = L ; i >= 1 ; i--) {
for (int b = 0 ; b <= y ; b++) {
for (int c = 0 ; c <= z ; c++) {
int a = i-b-c;
int[] left = {a, b, c};
for (int s = 0 ; s <= n ; s++) {
if (dp[i][b][c][s] == 0) {
continue;
}
for (int u = 0 ; u <= 2 ; u++) {
if (stateTable[s][u] == -1 || left[u] == 0) {
continue;
}
dp[i-1][b-((u==1)?1:0)][c-((u==2)?1:0)][stateTable[s][u]] = 1;
}
}
}
}
}
for (int i = 0 ; i <= n ; i++) {
String pref = prefix.substring(0, i) + prefix;
if ((i == 0 || pref.compareTo(prefix) > 0) && dp[0][0][0][i] == 1) {
return true;
}
}
return false;
}
public static void debug(Object... o) {
System.err.println(Arrays.deepToString(o));
}
public static class InputReader {
private static final int BUFFER_LENGTH = 1 << 12;
private InputStream stream;
private byte[] buf = new byte[BUFFER_LENGTH];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int next() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public char nextChar() {
return (char) skipWhileSpace();
}
public String nextToken() {
int c = skipWhileSpace();
StringBuilder res = new StringBuilder();
do {
res.append((char) c);
c = next();
} while (!isSpaceChar(c));
return res.toString();
}
public int nextInt() {
return (int) nextLong();
}
public long nextLong() {
int c = skipWhileSpace();
long sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = next();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
return Double.valueOf(nextToken());
}
int skipWhileSpace() {
int c = next();
while (isSpaceChar(c)) {
c = next();
}
return c;
}
boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
template<typename T> inline void read(T &x) {
x = 0; char c = getchar(); bool flag = false;
while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
while (isdigit(c)) { x = (x << 1 ) + (x << 3) + (c ^ 48); c = getchar(); }
if (flag) x = -x;
}
using namespace std;
multiset<string> st;
int main() {
int A, B, C; read(A), read(B), read(C);
while (A) st.insert("a"), --A;
while (B) st.insert("b"), --B;
while (C) st.insert("c"), --C;
while (st.size() != 1) {
string smal = *(st.begin()), larg = *(--st.end());
st.erase(st.find(smal)); st.erase(st.find(larg));
st.insert(smal + larg);
}
cout << *st.begin() << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
int x,y,z;
multiset<string> s;
int main(){
scanf("%d %d %d",&x,&y,&z);
for(int i=1;i<=x;i++) s.insert("a");
for(int i=1;i<=y;i++) s.insert("b");
for(int i=1;i<=z;i++) s.insert("c");
multiset<string>::iterator it;
while(s.size()>1){
it=s.begin(); string s1=*it;
s.erase(it);
it=s.end(); it--; string s2=*it;
s.erase(it);
s.insert(s1+s2);
}
it=s.begin();
cout<<*it<<endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
string get(int a, int b, int c)
{
string s;
if (b == 0 && c == 0)
{
for (int i = 0; i < a; i++)s.push_back('a');
return s;
}
if (a == 0)
{
s = get(b, c, 0);
for (int i = 0; i < s.size(); i++)s[i]++;
return s;
}
string sa, sb, sc;
if (c%a == 0)
{
s = get(0, a - b%a, b%a);
sb.push_back('a');
for (int i = 0; i < c / a; i++)sb.push_back('c');
for (int i = 0; i < b / a; i++)sb.push_back('b');
sc = sb;
sc.push_back('b');
}
else
{
s = get(a - c%a - b % (a - c%a), b % (a - c%a), c%a);
sa.push_back('a');
for (int i = 0; i < c / a; i++)sa.push_back('c');
sc = sa;
sc.push_back('c');
for (int i = 0; i < b / (a - c%a); i++)sa.push_back('b');
sb = sa;
sb.push_back('b');
}
string r;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == 'a')r += sa;
if (s[i] == 'b')r += sb;
if (s[i] == 'c')r += sc;
}
return r;
}
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
cout << get(a, b, c) << endl;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
string s[233];
int t,n;
int main(){
for (char c='a';c<='c';c++)
for (cin>>t;t--;) s[n++]+=c;
for (;n>1;){
sort(s,s+n);
s[0]+=s[--n];
}
cout<<s[0];
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <set>
#include <string>
#include <iostream>
int X,Y,Z;
std::multiset<std::string> s;
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0),std::cout.tie(0);
std::cin>>X>>Y>>Z;
while(X--)s.insert(std::string("a"));
while(Y--)s.insert(std::string("b"));
while(Z--)s.insert(std::string("c"));
while((int)s.size()>1)
{
std::string s1=*s.begin(),s2=*--s.end();
s.erase(s.begin()),s.erase(--s.end());
s.insert(s1+s2);
}
std::cout<<*s.begin()<<std::endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<cstring>
#include<set>
using namespace std;
int a,b,c;
char s[155][155];
struct str
{
int ID;
bool friend operator < (str a,str b)
{
return strcmp(s[a.ID],s[b.ID])<0;
}
}t1,t2;
multiset<str> m;
multiset<str>::iterator it;
int main()
{
scanf("%d%d%d",&a,&b,&c);
int cnt=0;
while(a--) s[++cnt][0]='a',m.insert((str){cnt});
while(b--) s[++cnt][0]='b',m.insert((str){cnt});
while(c--) s[++cnt][0]='c',m.insert((str){cnt});
while(m.size()>1)
{
it=m.begin();t1=*it;m.erase(it);
it=m.end();it--;t2=*it;m.erase(it);
strcat(s[t1.ID],s[t2.ID]);
m.insert((str){t1.ID});
}
it=m.begin();
t1=*it;
printf("%s\n",s[t1.ID]);
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | //Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
ll read(){
char ch=getchar();ll x=0;int op=1;
for (;!isdigit(ch);ch=getchar()) if (ch=='-') op=-1;
for (;isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*op;
}
#define N 55
int x,y,z;
multiset<string> s;
int main(){
cin>>x>>y>>z;
rep (i,1,x) s.insert("a");
rep (i,1,y) s.insert("b");
rep (i,1,z) s.insert("c");
while ((int)s.size()>1){
string tmp=*s.begin()+*--s.end();
s.erase(s.begin());
s.erase(--s.end());
s.insert(tmp);
}
cout<<*s.begin()<<'\n';
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
string solve(int na, int nb, int nc) {
if (na == 0 && nb == 0 && nc == 0) return "";
if (na == 0) { string ret = solve(nb, nc, 0); REPSZ(i, ret) ++ret[i]; return ret; }
vector<string> parts;
string cur = "a"; int curcnt = na; na = 0;
while (na+nb+nc>0) {
if (nc >= curcnt) { cur += "c"; nc -= curcnt; continue; }
while (nc > 0) parts.PB(cur + "c"), --curcnt, --nc;
if (nb >= curcnt) { cur += "b"; nb -= curcnt; continue; }
while (nb > 0) parts.PB(cur + "b"), --curcnt, --nb;
}
while (SZ(parts) > 0) {
int rep = curcnt / SZ(parts), rem = curcnt%SZ(parts); if (rem == 0) --rep, rem = SZ(parts);
string pref; REP(i, rep) pref += cur; string nxt = pref + cur + parts[rem - 1];
int nxtcnt = 1; while (nxtcnt < rem&&parts[rem - 1] == parts[rem - 1 - nxtcnt]) ++nxtcnt;
vector<string> nparts; FORSZ(i, rem, parts) nparts.PB(pref + parts[i]); REP(i, rem - nxtcnt) nparts.PB(pref + cur + parts[i]);
parts = nparts; cur = nxt; curcnt = nxtcnt;
}
string ret; REP(i, curcnt) ret += cur; return ret;
}
void run() {
int na, nb, nc;
scanf("%d%d%d", &na, &nb, &nc);
string s = solve(na, nb, nc);
printf("%s\n", s.c_str());
}
string other(int a,int b,int c) {
multiset<string> s;
while (a--) s.insert("a");
while (b--) s.insert("b");
while (c--) s.insert("c");
while ((int)s.size() > 1) {
string t = *s.begin() + *--s.end();
s.erase(s.begin());
s.erase(--s.end());
s.insert(t);
}
return *s.begin();
}
int main() {
run();
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | // Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.
#include <bits/stdc++.h>
using namespace std;
// solve problem when a != 0.
string solve(int a, int b, int c) {
if (b == 0 and c == 0) {
// it is clear, that answer is 'aaa...'.
string res = "";
for (int t = 0; t != a; ++t)
res += 'a';
return res;
}
// lets build our cyclical string.
// we have (a) parts equal to 'a', and b + c other parts.
// clearly, resulting cyclical string has substring of num=ceil(a/(b+c)) symbols 'a'.
//
// if we want to minimize answer, than we shouldn't make it any larger (since it will be start of the minimal cyclical shift)
// so we will have parts of length num and num-1.
int num = (a + (b + c - 1)) / (b + c);
int cnt_short = num * (b + c) - a; // how much parts of "num - 1"
string tmp = "";
for (int i = 0; i != num - 1; ++i)
tmp += 'a';
vector<string> parts;
for (int i = 0; i != (b + c - cnt_short); ++i)
parts.push_back(tmp + 'a'); // put long parts of num "a"
for (int i = 0; i != cnt_short; ++i)
parts.push_back(tmp); // put short parts of (num - 1) "a".
// let's distribute B's and C's.
//
// We can notice, that minimal cyclical shift will start with num "a"s.
// So it is always better to put C's to "long" parts, they are conveniently at the beginning of parts
// array.
for (int i = 0; i != c; ++i)
parts[i] += 'c';
for (int i = 0; i != b; ++i)
parts[c + i] += 'b';
// Now we want to put all parts together to minimize answer, and we are sure,
// that the answer will be smaller than possible, if we try to split parts.
// funny thing: there are no more, than 3 different types of parts, because
// part uniquely defined by whether it has (num) or (num - 1) A's, and whether it has B or C at the end.
// but it is not possible for types (num, B) and (num - 1, C) to exist together.
// so count number of each and call recursion.
sort(parts.begin(), parts.end());
vector<string> cparts = parts;
cparts.resize(std::unique(cparts.begin(), cparts.end()) - cparts.begin());
while (cparts.size() < 3)
cparts.push_back("");
assert(cparts.size() == 3);
string zzans = solve(std::count(parts.begin(), parts.end(), cparts[0]),
std::count(parts.begin(), parts.end(), cparts[1]),
std::count(parts.begin(), parts.end(), cparts[2]));
string ans = "";
for (char ch: zzans)
ans += cparts[ch - 'a'];
return ans;
}
// Time: T(x, y, z) = (x + y + z) + T(a, b, c), where a + b + c = x.
// since X in T(x, y, z) is decreasing in recursion, there are O(N) levels and each is O(N) => O(N^2)
// (actually implementation above is O(N^2 log) due to sort, but one can write without it).
int main() {
int a, b, c;
cin >> a >> b >> c;
// remap 'a', 'b', 'c' in such way, that
// num of 'a' is not zeros.
map<char, char> back;
if (a == 0 and b == 0) {
back['a'] = 'c';
a = c;
b = 0;
c = 0;
} else if (a == 0) {
back['a'] = 'b';
back['b'] = 'c';
a = b;
b = c;
c = 0;
} else {
back['a'] = 'a';
back['b'] = 'b';
back['c'] = 'c';
}
// solve problem when a != 0.
string ans = solve(a, b, c);
for (int i = 0; i != int(ans.size()); ++i)
cout << back[ans[i]];
cout << "\n";
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int A, B, C;
string getans(string S) {
int ca = 0, cb = 0, cc = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == 'a') ca++;
if (S[i] == 'b') cb++;
if (S[i] == 'c') cc++;
}
if (cb == 0) return S;
vector<string>vec;
for (int i = 0; i < ca; i++) vec.push_back("a");
for (int i = 0; i < cc; i++) vec[i%ca] += "c";
sort(vec.begin(), vec.end());
int Z = 1;
for (int i = 1; i < vec.size(); i++) { if (vec[i] == vec[i - 1])Z = i + 1; else break; }
for (int i = 0; i < cb; i++) vec[i%Z] += "b";
sort(vec.begin(), vec.end());
string G = "a"; int I = 0;
for (int i = 1; i < vec.size(); i++) {
if (vec[i] != vec[i - 1]) I++;
G += ('a' + I);
}
vector<string>A = vec; A.erase(unique(A.begin(), A.end()), A.end());
string V = getans(G), U = "";
for (int i = 0; i < V.size(); i++) { U += A[V[i] - 'a']; }
return U;
}
string F;
int main() {
cin >> A >> B >> C;
if (A >= 1) F += "a"; if (B >= 1) F += "b"; if (C >= 1) F += "c";
int P = 0;
while (A == 0) { A = B; B = C; C = 0; }
while (B == 0 && C >= 1) { B = C; C = 0; }
string G = "";
for (int i = 0; i < A; i++) G += "a";
for (int i = 0; i < B; i++) G += "b";
for (int i = 0; i < C; i++) G += "c";
string ret = getans(G);
for (int i = 0; i < ret.size(); i++) ret[i] = F[ret[i] - 'a'];
cout << ret << endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string>s;
int main()
{
scanf("%d%d%d",&a,&b,&c);
for(int i = 1;i<=a;i++)s.insert("a");
for(int i = 1;i<=b;i++)s.insert("b");
for(int i = 1;i<=c;i++)s.insert("c");
for(int i = 1;i<a+b+c;i++)
{
string x = *s.begin(),y = *(--s.end());
s.erase(s.lower_bound(x)),s.erase(s.lower_bound(y));
s.insert(x+y);
}cout<<*s.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include "bits/stdc++.h"
using namespace std;
const int maxn = 55;
string res;
bool vis[maxn][maxn][maxn][maxn];
int failure[maxn], link[maxn][3], final_ok[maxn];
void push(){
memset(failure, 0, sizeof(failure));
for(int s = 2; s <= res.size(); s++){
failure[s] = failure[s-1];
while(failure[s] > 0 && res[failure[s]] != res[s-1])
failure[s] = failure[failure[s]];
if(res[failure[s]] == res[s-1]) ++failure[s];
}
for(int s = 0; s < res.size(); s++){
for(int e = 0; e < 3; e++){
int pos = s;
if(res[s] > 'a' + e) link[s][e] = -1;
else{
while(pos > 0 && res[pos] != 'a' + e) pos = failure[pos];
if(res[pos] == 'a' + e) pos++;
link[s][e] = pos;
}
}
}
for(int s = 0; s < res.size(); s++){
int pos = s;
final_ok[pos] = 1;
for(int e = 0; e < res.size(); e++){
pos = link[pos][res[e] - 'a'];
if(pos == -1){
final_ok[s] = 0;
break;
}
}
}
}
bool solve(int x, int y, int z, int px){
if(px == res.size()) px = failure[px];
if(x + y + z == 0) return final_ok[px];
if(vis[x][y][z][px]) return false;
vis[x][y][z][px] = true;
if(link[px][0] != -1 && x && solve(x - 1, y, z, link[px][0])) return true;
if(link[px][1] != -1 && y && solve(x, y - 1, z, link[px][1])) return true;
if(link[px][2] != -1 && z && solve(x, y, z - 1, link[px][2])) return true;
return false;
}
int M(){
int x, y, z;
if(!(cin >> x >> y >> z)) return 0;
int len = x + y + z;
res.clear();
for(int e = 0; e < len; e++){
res.push_back('c');
push();
memset(vis, 0, sizeof(vis));
if(solve(x, y, z, 0)) continue;
res.back() = 'b';
push();
memset(vis, 0, sizeof(vis));
if(solve(x, y, z, 0)) continue;
res.back() = 'a';
}
cout << res << endl;
return 1;
}
int main(){
while(M());
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <set>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>
using namespace std;
#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define X first
#define Y second
typedef pair<int, int> P;
typedef long long ll;
int cnt[3];
string rek(vector <pair<string, int> > V) {
// TRACE(V.size());
if (V.size() == 1) {
string ret = "";
REP(i, V[0].Y)
ret += V[0].X;
return ret;
}
multiset <string> S;
REP(i, V[0].Y)
S.insert(V[0].X);
for (int i=(int) V.size()-1; i; i--) {
REP(j, V[i].Y) {
auto it = S.begin();
string tmp = *it;
S.erase(it);
tmp += V[i].X;
S.insert(tmp);
}
}
// TRACE(S.size());
vector <pair<string, int> > T;
for (multiset <string> :: iterator it = S.begin(); it != S.end(); ) {
int kol = 0;
multiset <string> :: iterator it2 = it;
for (; it2 != S.end() && *it2 == *it; it2++, kol++);
T.push_back({*it, kol});
it = it2;
}
return rek(T);
}
int main()
{
int n=0;
REP(i, 3) {
scanf("%d", &cnt[i]);
n += cnt[i];
}
vector <pair<string, int> > V;
REP(i, 3) {
if (cnt[i]) {
string tmp = "";
tmp.push_back((char) ('a' + i));
V.push_back({tmp, cnt[i]});
}
}
cout << rek(V) << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<set>
#include<cstdio>
#include<cctype>
#include<string>
inline int Read(){
char a;
int b;
while(!isdigit(a=getchar()));
b=a^'0';
while(isdigit(a=getchar()))b=(((b<<2)+b)<<1)+(a^'0');
return b;
}
int main()
{
std::multiset<std::string> set;
for(int i=Read();i;i--)set.insert("a");
for(int i=Read();i;i--)set.insert("b");
for(int i=Read();i;i--)set.insert("c");
while(set.size()>1){
std::string s=*set.begin(),t=*set.rbegin();
set.erase(set.lower_bound(s));
set.erase(set.lower_bound(t));
set.insert(s+t);
}
printf("%s\n",(*set.begin()).c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main()
{
multiset <string> s;
int a,b,c;
cin>>a>>b>>c;
for(int i=1;i<=a;i++) s.insert("a");
for(int i=1;i<=b;i++) s.insert("b");
for(int i=1;i<=c;i++) s.insert("c");
while(s.size()>1)
{
string x=*s.begin();
string y=*s.rbegin();
s.erase(s.lower_bound(x));
s.erase(s.lower_bound(y));
s.insert(x+y);
}
cout<<*s.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
#include <set>
using namespace std;
int a_num, b_num, c_num;
multiset<string> st;
int main()
{
cin >> a_num >> b_num >> c_num;
for (int i = 1; i <= a_num; i++) st.insert("a");
for (int i = 1; i <= b_num; i++) st.insert("b");
for (int i = 1; i <= c_num; i++) st.insert("c");
while (st.size() > 1)
{
string s = *st.begin(), t = *st.rbegin();
st.erase(st.lower_bound(s)), st.erase(st.lower_bound(t));
st.insert(s + t);
}
cout << *st.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pii;
#define xx first
#define yy second
template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool repr(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool repl(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
#define I inline
#define mset(a,b) memset(a,b,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
#define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define fd0(i,n) for(int i=(n)-1;~i;i--)
#define fd1(i,n) for(int i=n;i;i--)
#define fd(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define foe(i,x)for(__typeof(x.end())i=x.begin();i!=x.end();++i)
struct Cg{I char operator()(){return getchar();}};
struct Cp{I void operator()(char x){putchar(x);}};
#define OP operator
#define RT return *this;
#define RX x=0;char t=P();while((t<'0'||t>'9')&&t!='-')t=P();bool f=0;\
if(t=='-')t=P(),f=1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define RL if(t=='.'){lf u=0.1;for(t=P();t>='0'&&t<='9';t=P(),u*=0.1)x+=u*(t-'0');}if(f)x=-x
#define RU x=0;char t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define TR *this,x;return x;
I bool IS(char x){return x==10||x==13||x==' ';}template<typename T>struct Fr{T P;I Fr&OP,(int &x)
{RX;if(f)x=-x;RT}I OP int(){int x;TR}I Fr&OP,(ll &x){RX;if(f)x=-x;RT}I OP ll(){ll x;TR}I Fr&OP,(char &x)
{for(x=P();IS(x);x=P());RT}I OP char(){char x;TR}I Fr&OP,(char *x){char t=P();for(;IS(t);t=P());if(~t){for(;!IS
(t)&&~t;t=P())*x++=t;}*x++=0;RT}I Fr&OP,(lf &x){RX;RL;RT}I OP lf(){lf x;TR}I Fr&OP,(llf &x){RX;RL;RT}I OP llf()
{llf x;TR}I Fr&OP,(uint &x){RU;RT}I OP uint(){uint x;TR}I Fr&OP,(ull &x){RU;RT}I OP ull(){ull x;TR}};Fr<Cg>in;
#define WI(S) if(x){if(x<0)P('-'),x=-x;char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
#define WL if(y){lf t=0.5;for(int i=y;i--;)t*=0.1;if(x>=0)x+=t;else x-=t,P('-');*this,(ll)(abs(x));P('.');if(x<0)\
x=-x;while(y--){x*=10;x-=floor(x*0.1)*10;P(((int)x)%10+'0');}}else if(x>=0)*this,(ll)(x+0.5);else *this,(ll)(x-0.5);
#define WU(S) if(x){char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
template<typename T>struct Fw{T P;I Fw&OP,(int x){WI(10);RT}I Fw&OP()(int x){WI(10);RT}I Fw&OP,(uint x){WU(10);RT}
I Fw&OP()(uint x){WU(10);RT}I Fw&OP,(ll x){WI(19);RT}I Fw&OP()(ll x){WI(19);RT}I Fw&OP,(ull x){WU(20);RT}I Fw&OP()
(ull x){WU(20);RT}I Fw&OP,(char x){P(x);RT}I Fw&OP()(char x){P(x);RT}I Fw&OP,(const char *x){while(*x)P(*x++);RT}
I Fw&OP()(const char *x){while(*x)P(*x++);RT}I Fw&OP()(lf x,int y){WL;RT}I Fw&OP()(llf x,int y){WL;RT}};Fw<Cp>out;
const int N=53;
char s[N],f[N][N][N][N];
int p[N],n,nxt[N][3];
inline bool dfs2(int a,int b,int c,int i)
{
if(!a&&!b&&!c)
{
fo0(j,n)
{
if(s[i]>s[j])return 0;
i=nxt[i][s[j]-97];
}
return 1;
}
if(~f[a][b][c][i])return f[a][b][c][i];
bool res=0;
if(a&&s[i]<='a')res|=dfs2(a-1,b,c,nxt[i][0]);
if(b&&s[i]<='b')res|=dfs2(a,b-1,c,nxt[i][1]);
if(c&&s[i]<='c')res|=dfs2(a,b,c-1,nxt[i][2]);
return f[a][b][c][i]=res;
}
inline bool chk(int n,int a,int b,int c)
{
//out,"chk:",n,' ',a,' ',b,' ',c,'\n';
::n=n;
p[0]=-1;
fo1(i,n-1)
{
int t=p[i-1];
for(;t!=-1&&s[t+1]!=s[i];t=p[t]);
if(s[t+1]==s[i])p[i]=t+1;
else p[i]=-1;
}
fo(i,0,n)fo0(j,3)
{
int t=i==n?p[i-1]:i-1;
for(;t!=-1&&s[t+1]!=j+97;t=p[t]);
if(t+2==n)t=p[t+1]-1;
if(s[t+1]==j+97)nxt[i][j]=t+2;
else nxt[i][j]=0;
}
//fo(i,0,n)fo0(j,3)out,'/',i,' ',j,' ',nxt[i][j],'\n';
fo(i,0,a)fo(j,0,b)fo(k,0,c)fo0(d,n)f[i][j][k][d]=-1;
return dfs2(a,b,c,0);
}
inline void dfs(int a,int b,int c,int i)
{
//out,a,' ',b,' ',c,' ',i,'\n';
if(!a&&!b&&!c)return;
if(c){s[i]='c';if(chk(i+1,a,b,c-1))return dfs(a,b,c-1,i+1);}
if(b){s[i]='b';if(chk(i+1,a,b-1,c))return dfs(a,b-1,c,i+1);}
if(a){s[i]='a';if(chk(i+1,a-1,b,c))return dfs(a-1,b,c,i+1);}
}
int main()
{
int a,b,c;
in,a,b,c;
dfs(a,b,c,0);
out,s,'\n';
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define re register
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,n,m) for(int i=m;i>=n;i--)
#define rrep(i,m,n) for(register int i=m;i<=n;i++)
#define rper(i,n,m) for(register int i=m;i>=n;i--)
const int N = 5e6 + 10;
const ll mod = 1e9 + 7;
multiset<string> s;
signed main(){
int a,b,c;
cin>>a>>b>>c;
rep(i,1,a)s.insert("a");
rep(i,1,b)s.insert("b");
rep(i,1,c)s.insert("c");
while (s.size()>1){
auto i=s.begin(),j=s.end();
j--;
string tmp=(*i)+(*j);
s.erase(i);s.erase(j);
s.insert(tmp);
}
cout<<(*s.begin());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;
void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
return os<<'('<<p.first<<','<<p.second<<')';
}
template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
print_tuple<0,Args...>(os<<'(',t);
return os<<')';
}
template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
os<<'[';
for(auto i=begin(c);i!=end(c);++i)
os<<(i==begin(c)?"":" ")<<*i;
return os<<']';
}
constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;
int main()
{
#ifndef _GLIBCXX_DEBUG
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
constexpr char endl='\n';
#endif
for(int x,y,z;cin>>x>>y>>z&&x|y|z;){
multiset<string> s;
rep(_,x) s.insert("a");
rep(_,y) s.insert("b");
rep(_,z) s.insert("c");
while(s.size()>1){
auto i=begin(s),j=--end(s);
s.insert(*i+*j);
s.erase(i);
s.erase(j);
}
cout<<*begin(s)<<endl;
}
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define maxn 100086
using namespace std;
int x, y, z;
multiset<string> st;
int main(){
scanf("%d%d%d", &x, &y, &z);
for(int i = 1;i <= x;i++) st.insert("a");
for(int i = 1;i <= y;i++) st.insert("b");
for(int i = 1;i <= z;i++) st.insert("c");
while(st.size() > 1){
string s = *st.begin(), t = *st.rbegin();
st.erase(st.find(s)), st.erase(st.find(t));
st.insert(s + t);
}
printf("%s", st.begin()->c_str());
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
string f(vector<pair<string,int> >A)
{
if(A.size()==1)
{
string ret="";
for(int i=0;i<A[0].second;i++)ret+=A[0].first;
return ret;
}
sort(A.begin(),A.end());
int sum=0;
for(pair<string,int>p:A)
{
sum+=p.second;
}
vector<string>ret;
if(A[0].second*2<=sum)
{
for(int i=0;i<A[0].second;i++)ret.push_back(A[0].first);
int cnt=A[0].second;
A[0].second=0;
int id=A.size()-1;
while(0<id)
{
for(int i=0;i<cnt;i++)
{
while(0<id&&A[id].second==0)id--;
if(id==0)break;
else
{
A[id].second--;
ret[i]+=A[id].first;
}
}
sort(ret.begin(),ret.end());
int ncnt=0;
for(int i=0;i<cnt;i++)if(ret[0]==ret[i])ncnt++;
cnt=ncnt;
}
}
else
{
int cnt=sum-A[0].second;
for(int i=0;i<cnt;i++)
{
ret.push_back("");
for(int j=0;j<A[0].second/cnt+(i<A[0].second%cnt);j++)
{
ret.back()+=A[0].first;
}
}
int id=A.size()-1;
for(string&s:ret)
{
while(A[id].second==0)id--;
A[id].second--;
s+=A[id].first;
}
}
sort(ret.begin(),ret.end());
vector<pair<string,int> >nxt;
nxt.push_back(make_pair(ret[0],1));
for(int i=1;i<ret.size();i++)
{
if(nxt.back().first==ret[i])nxt.back().second+=1;
else nxt.push_back(make_pair(ret[i],1));
}
return f(nxt);
}
int main()
{
int X,Y,Z;
cin>>X>>Y>>Z;
vector<pair<string,int> >A;
if(X>0)A.push_back(make_pair("a",X));
if(Y>0)A.push_back(make_pair("b",Y));
if(Z>0)A.push_back(make_pair("c",Z));
cout<<f(A)<<endl;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}
const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;
int T, n, m;
string solve(int x, const string a) {
string ans = "";
REP(i, x) ans += a;
return ans;
}
string solve(int x, int y, const string a, const string b) {
if (x == 0) return solve(y, b);
if (y == 0) return solve(x, a);
if (x <= y) return solve(x, y - x, a + b, b);
return solve(x - y, y, a, a + b);
}
string solve(int x, int y, int z, const string a, const string b, const string c) {
if(x == 0) return solve(y, z, b, c);
if(y == 0) return solve(x, z, a, c);
if(z == 0) return solve(x, y, a, b);
if(x <= z) return solve(x, y, z - x, a + c, b, c);
if(x <= z + y) return solve(x - z, z, y - (x - z), a + b, a + c, b);
return solve(x - y - z, y, z, a, a + b, a + c);
}
int main(int argc, char *argv[]){
ios::sync_with_stdio(false);
int x, y, z;
cin >> x >> y >> z;
cout << solve(x, y, z, "a", "b", "c") << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
multiset<string> s;
multiset<string> :: iterator it,it1;
int main()
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
for (int u=1;u<=x;u++) s.insert("a");
for (int u=1;u<=y;u++) s.insert("b");
for (int u=1;u<=z;u++) s.insert("c");
while (s.size()>1)
{
it=s.begin();
it1=(--s.end());
s.insert((*it)+(*it1));
s.erase(it);s.erase(it1);
}
cout<<(*s.begin());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string>s;
int main()
{
cin>>a>>b>>c;
for(int i=1;i<=a;i++)s.insert("a");
for(int i=1;i<=b;i++)s.insert("b");
for(int i=1;i<=c;i++)s.insert("c");
while(s.size()>1)
{
string ss=(*s.begin())+(*s.rbegin());
s.erase(s.begin());
s.erase(--s.end());
s.insert(ss);
}
cout<<(*s.begin());
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | x, y, z = map(int, raw_input().split())
a = ['a'] * x + ['b'] * y + ['c'] * z
while len(a) > 1:
a = sorted(a[1:-1] + [a[0] + a[-1]])
print a[0]
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long LL;
multiset<string> S;
int main(){
int n;
scanf("%d", &n);for (int i=0; i<n; i++) S.insert("a");
scanf("%d", &n);for (int i=0; i<n; i++) S.insert("b");
scanf("%d", &n);for (int i=0; i<n; i++) S.insert("c");
while ( S.size() >1){
string s1= *S.begin(), s2= *(--S.end());
string t= s1+s2;
S.erase(S.begin());S.erase(--S.end());
S.insert(t);
}
printf("%s\n", S.begin()->c_str());
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;
string minShift(string s)
{
string res = s;
FOR (it, 0, SZ(s))
{
s += s[0];
s.erase(s.begin());
res = min(res, s);
}
return res;
}
string getString(vector<string> v)
{
string res;
FOR (i, 0, SZ(v))
{
res += v[i];
}
return res;
}
string solveSmall(int a, int b, int c, string A, string B, string C)
{
vector<string> v;
FOR (i, 0, a)
{
v.PB(A);
}
FOR (i, 0, b)
{
v.PB(B);
}
FOR (i, 0, c)
{
v.PB(C);
}
sort(ALL(v));
string res = getString(v);
do
{
res = max(res, minShift(getString(v)));
}while(next_permutation(ALL(v)));
return res;
}
string getString(int cnt, string s)
{
string res;
FOR (i, 0, cnt)
{
res += s;
}
return res;
}
string solveLarge(int a, int b, int c, string A, string B, string C)
{
if (a + b + c <= 3) return solveSmall(a, b, c, A, B, C);
if (a == 0)
{
a = b;
A = B;
b = c;
B = C;
c = 0;
C = "";
}
if (b == 0)
{
b = c;
B = C;
c = 0;
C = "";
}
if (b == 0 && c == 0)
{
return getString(a, A);
}
if (c >= a)
{
c -= a;
A += C;
return solveLarge(a, b, c, A, B, C);
}
C = A + C;
a -= c;
if (b >= a)
{
A += B;
b -= a;
swap(b, c);
swap(B, C);
}
else
{
a -= b;
B = A + B;
}
return solveLarge(a, b, c, A, B, C);
}
int main()
{
//freopen("in.txt", "r", stdin);
//ios::sync_with_stdio(false); cin.tie(0);
int x, y, z;
cin>>x>>y>>z;
string res = solveLarge(x, y, z, "a", "b", "c");
cout<<res<<endl;
// FOR (a, 0, 5)
// {
// FOR (b, 0, 5)
// {
// FOR (c, 0, 5)
// {
// string r = solveSmall(a, b, c, "a", "b", "c");
// string s = solveLarge(a, b, c, "a", "b", "c");
// cout<<r<<endl<<s<<endl;
// if (r != s)
// {
// cout<<"!! "<<endl;
// cout<<a<<' '<<b<<' '<<c<<endl;
// throw -1;
// }
// }
// }
// }
//
// cout<<"Done"<<endl;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
multiset< string > S;
int main() {
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
while(x--) S.insert("a");
while(y--) S.insert("b");
while(z--) S.insert("c");
while(S.size()>1) {
string a=*S.begin(),b=*S.rbegin();
S.erase(S.begin());
S.erase(--S.end());
S.insert(a+b);
}
cout << *S.begin() <<endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | java | import java.io.*;
import java.util.*;
public class Main {
private FastScanner in;
private PrintWriter out;
int cnt = 0;
class T implements Comparable<T> {
String s;
int id = cnt++;
public T(String s) {
this.s = s;
}
@Override
public int compareTo(T o) {
int c = s.compareTo(o.s);
if (c != 0) {
return c;
}
return Integer.compare(id, o.id);
}
}
String getMin(String s) {
String res = s;
for (int i = 1; i < s.length(); i++) {
String t = s.substring(i) + s.substring(0, i);
if (t.compareTo(res) < 0) {
res = t;
}
}
return res;
}
void check(String s) {
ArrayList<Character> a = new ArrayList<>();
for (char c : s.toCharArray()) {
a.add(c);
}
char[] tmp = new char[s.length()];
for (int it = 0; it < 1231; it++) {
Collections.shuffle(a);
int z = 0;
for (char c : a) {
tmp[z++] = c;
}
String xx = new String(tmp);
if (getMin(xx).compareTo(s) > 0) {
throw new AssertionError();
}
}
}
String solve(int x, int y, int z) {
if (x + y + z == 0) {
return "";
}
TreeSet<T> ts = new TreeSet<>();
for (int i = 0; i < x; i++) {
ts.add(new T("a"));
}
for (int i = 0; i < y; i++) {
ts.add(new T("b"));
}
for (int i = 0; i < z; i++) {
ts.add(new T("c"));
}
while (ts.size() > 1) {
T first = ts.pollFirst();
T last = ts.pollLast();
ts.add(new T(first.s + last.s));
}
String res = (ts.first().s);
check(res);
return res;
}
void solve123() {
final int M = 10;
for (int x = 0; x < M; x++) {
for (int y = 0; y < M; y++) {
for (int z = 0; z < M; z++) {
solve(x, y, z);
System.err.println(x + " " + y + " "+ z);
}
}
}
}
void solve() {
int x = in.nextInt();
int y = in.nextInt();
int z = in.nextInt();
out.println(solve(x, y, z));
}
private void run() {
try {
in = new FastScanner(new File("Main.in"));
out = new PrintWriter(new File("Main.out"));
solve();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
private class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] args) {
new Main().runIO();
}
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b) for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
const int N = 100000;
const int oo = 0x3f3f3f3f;
template<typename T> T read() {
T n(0), f(1);
char ch = getchar();
for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48;
return n * f;
}
string solve(int a, int b, int c) {
bool flag = false;
if(!a) {
flag = true;
a = b;
b = c;
c = 0;
}
string res;
if(!a) {
res = string(b, 'b');
}else {
if(!b && !c) {
res = string(a, 'a');
}else {
vector<string> ans(a, "a");
for(int i = 0; i < c; ++i) ans[i % a] += 'c';
int pos = c % a;
for(int i = 0; i < b; ++i) {
ans[pos] += 'b';
if(++ pos == a) pos = c % a;
}
map<string, int> mp;
vector< pair<string, int> > sub;
for(const auto& x : ans) { ++ mp[x]; }
for(const auto& x : mp) { sub.pb(x); }
while(sub.size() < 3) sub.pb(make_pair("", 0));
string tmp = solve(sub[0].snd, sub[1].snd, sub[2].snd);
for(const auto& x : tmp) {
res += sub[x - 'a'].fst;
}
}
}
if(flag) {
for(auto& ch : res) ++ ch;
}
return res;
}
int a, b, c;
int main() {
#ifdef Wearry
freopen("data.txt", "r", stdin);
freopen("ans.txt", "w", stdout);
#endif
cin >> a >> b >> c;
cout << solve(a, b, c) << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | java |
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main {
private static void solve() {
int[] a = na(3);
List<String> list = new ArrayList<>();
for (int j = 0; j < 3; j ++) {
for (int i = 0; i < a[j]; i ++)
list.add("" + (char)('a' + j));
}
while (list.size() > 1) {
Collections.sort(list);
int last = list.size() - 1;
String s = list.get(0) + list.get(last);
list.set(0, s);
list.remove(last);
}
System.out.println(list.get(0));
}
public static void main(String[] args) {
new Thread(null, new Runnable() {
@Override
public void run() {
long start = System.currentTimeMillis();
String debug = System.getProperty("debug");
if (debug != null) {
try {
is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
solve();
out.flush();
tr((System.currentTimeMillis() - start) + "ms");
}
}, "", 64000000).start();
}
private static java.io.InputStream is = System.in;
private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
private static java.util.StringTokenizer tokenizer = null;
private static java.io.BufferedReader reader;
public static String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new java.util.StringTokenizer(reader.readLine());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
private static double nd() {
return Double.parseDouble(next());
}
private static long nl() {
return Long.parseLong(next());
}
private static int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private static char[] ns() {
return next().toCharArray();
}
private static long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nl();
return a;
}
private static int[][] ntable(int n, int m) {
int[][] table = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
table[i][j] = ni();
}
}
return table;
}
private static int[][] nlist(int n, int m) {
int[][] table = new int[m][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
table[j][i] = ni();
}
}
return table;
}
private static int ni() {
return Integer.parseInt(next());
}
private static void tr(Object... o) {
if (is != System.in)
System.out.println(java.util.Arrays.deepToString(o));
}
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | python2 | def work(a,b,c,A,B,C):
if A==0:
return work(b,c,'',B,C,0)
if B==0:
if C==0:
return a*A
else:
return work(a,c,'',A,C,0)
if C==0:
return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0)
cmod = C%A
if B <= A-cmod:
return work(a+c*(C/A),a+c*(C/A)+b,a+c*(C/A+1),A-cmod-B,B,cmod)
else:
bmod = B%(A-cmod)
return work(a+c*(C/A)+b*(B/(A-cmod)),a+c*(C/A)+b*(B/(A-cmod)+1),a+c*(C/A+1),A-bmod-cmod,bmod,cmod)
if __name__ == '__main__':
s = raw_input()
a,b,c = [int(i) for i in s.split()]
print(work('a','b','c',a,b,c))
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using ll = int64_t;
using ld = long double;
using namespace std;
const int MAXN = 51;
using val = vector<int>;
string ans[MAXN];
string solve(int x, int y, int z) {
int n = x + y + z;
if (!x) {
string ans = solve(y, z, 0);
for (char& c : ans) {
c++;
}
return ans;
}
if (y + z == 0) {
string ans = "";
for (int i = 0; i < n; i++)
ans += 'a';
return ans;
}
string vala;
string valb;
string valc;
int nx, ny, nz;
if (x <= z) {
nx = x;
ny = y;
nz = z - x;
vala = "ac";
valb = "b";
valc = "c";
} else {
if (x - z < y) {
vala = "ab";
valb = "ac";
valc = "b";
nx = x - z;
ny = z;
nz = y - (x - z);
} else {
vala = "a";
valb = "ab";
valc = "ac";
nx = x - y - z;
ny = y;
nz = z;
}
}
string ans = solve(nx, ny, nz);
string vl = "";
for (char c : ans) {
if (c == 'a')
vl += vala;
else if (c == 'b')
vl += valb;
else vl += valc;
}
return vl;
}
int main() {
#ifdef PAUNSVOKNO
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20);
int x, y, z;
cin >> x >> y >> z;
string ans = solve(x, y, z);
cout << ans << "\n";
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
int x, y, z;
string a, b, c;
int main() {
scanf("%d%d%d", &x, &y, &z);
a = "a";
b = "b";
c = "c";
while(1) {
if(!x) {
x = y;
a = b;
y = z;
b = c;
z = 0;
}
if(!x) {
x = y;
a = b;
y = 0;
}
if(z) {
if(x <= z) {
for( ; z >= x; z -= x)
a = a + c;
} else {
for( ; x >= y + z; x -= y + z) {
b = a + b;
c = a + c;
}
if(x >= z) {
swap(y, z);
swap(b, c);
b = a + b;
x -= y;
}
}
} else if(y) {
if(x <= y) {
for( ; y >= x; y -= x)
a = a + b;
} else {
for( ; x >= y; x -= y)
b = a + b;
}
} else {
break;
}
}
b = a;
for(int i = 1; i < x; ++i)
a = a + b;
puts(a.c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
int main(void)
{
int a,b,c;
cin>>a>>b>>c;
multiset < string > s;
for (int i = 0;i < a;++i)
s.insert("a");
for (int i = 0;i < b;++i)
s.insert("b");
for (int i = 0;i < c;++i)
s.insert("c");
while (s.size() > 1)
{
string str = *s.begin();
str += *s.rbegin();
s.erase(s.begin());
auto it = s.end();--it;
s.erase(it);
s.insert(str);
}
cout << (*s.begin()) << '\n';
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
int A,B,C;
/*
string hoge(map<string,int> M) {
if(M.size()==1) {
string s="";
while(M.begin()->second--) s+=M.begin()->first;
return s;
}
string s=M.begin()->first;
string t=M.rbegin()->first;
int a=M.begin()->second;
int b=rM.begin()->second;
if(a<=b) {
}
}
*/
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>A>>B>>C;
vector<string> V;
FOR(i,A) V.push_back("a");
FOR(i,B) V.push_back("b");
FOR(i,C) V.push_back("c");
while(V.size()>1) {
sort(ALL(V));
V[0]+=V.back();
V.pop_back();
}
cout<<V[0]<<endl;
/*
map<string,int> M;
if(A) M["a"]=A;
if(B) M["b"]=B;
if(C) M["c"]=C;
cout<<hoge(M)<<endl;
*/
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
long long int X, Y, Z, S, K;
static inline void exap(string &src, string s, long long int t){
for(int i = 0; i < t; ++i)src += s;
}
void twoletter(long long X, long long Y, string xc, string yc){
while(X && Y){
if(X > Y){
X -= Y;
yc = xc + yc;
}else{
K = Y / X;
Y %= X;
X -= Y;
exap(xc, yc, K);
yc = xc + yc;
}
}
for(int i = 0; i < X; ++i)cout << xc;
for(int i = 0; i < Y; ++i)cout << yc;
cout << endl;
return;
}
int main(){
scanf("%lld%lld%lld", &X, &Y, &Z);
S = X + Y + Z;
if(S == X || S == Y || S == Z){
for(int i = 0; i < X; ++i)cout << "a";
for(int i = 0; i < Y; ++i)cout << "b";
for(int i = 0; i < Z; ++i)cout << "c";
cout << endl;
return 0;
}
string A = "a", B = "b", C = "c";
while(1){
//cout << A << X << " " << B << Y << " " << C << Z << endl;
if(X == 0){
twoletter(Y, Z, B, C);
return 0;
}
if(Y == 0){
twoletter(X, Z, A, C);
return 0;
}
if(Z == 0){
twoletter(X, Y, A, B);
return 0;
}
if(X > Z){
X -= Z;
C = A + C;
}else{
K = Z / X;
Z %= X;
X -= Z;
exap(A, C, K);
C = A + C;
}
swap(B, C);
swap(Y, Z);
}
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | // Copyright (C) 2017 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.
#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>
using std::cin;
using std::cout;
using std::cerr;
using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::pair;
using std::make_pair;
using std::min;
using std::abs;
using std::max;
using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;
#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif
template <typename T>
T input() {
T res;
cin >> res;
LASSERT(cin);
return res;
}
template <typename IT>
void input_seq(IT b, IT e) {
std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}
#define SZ(vec) int((vec).size())
#define ALL(data) data.begin(),data.end()
#define RALL(data) data.rbegin(),data.rend()
#define TYPEMAX(type) std::numeric_limits<type>::max()
#define TYPEMIN(type) std::numeric_limits<type>::min()
#define pb push_back
#define eb emplace_back
// solve problem when a != 0.
string solve(int a, int b, int c) {
if (b == 0 and c == 0) {
// it is clear, that answer is 'aaa...'.
string res = "";
for (int t = 0; t != a; ++t)
res += 'a';
return res;
}
// lets build our cyclical string.
// we have a parts equal to 'a', and b + c other parts.
// clearly, resulting cyclical string has substring of num=ceil(a/(b+c)) symbols 'a'.
//
// if we want to minimize answer, than we shouldn't make it any larger (since it will be the minimal cyclical shift)
// so we will have parts of length num and num-1.
int num = (a + (b + c - 1)) / (b + c);
int cnt_short = num * (b + c) - a; // how much parts of "num - 1"
string tmp = "";
for (int i = 0; i != num - 1; ++i)
tmp += 'a';
vector<string> parts;
for (int i = 0; i != (b + c - cnt_short); ++i)
parts.push_back(tmp + 'a'); // put long parts of num "a"
for (int i = 0; i != cnt_short; ++i)
parts.push_back(tmp); // put short parts of (num - 1) "a".
// let's distribute B's and C's.
//
// We can notice, that minimal cyclical shift will start with num "a"s.
// So it is always better to put C's to "long" parts, they are conveniently at the beginning of parts
// array.
for (int i = 0; i != c; ++i)
parts[i] += 'c';
for (int i = 0; i != b; ++i)
parts[c + i] += 'b';
// Now we want to put all parts together to minimize answer, and we are sure,
// that the answer will be smaller than possible, if we try to split parts.
// funny thing: there are no more, than 3 different types of parts, because
// part uniquely defined by whether it has (num) or (num - 1) A's, and whether it has B or C at the end.
// but it is not possible for types (num, B) and (num - 1, C) to exist together.
// so count number of each and call recursion.
std::sort(ALL(parts));
vector<string> cparts = parts;
cparts.resize(std::unique(ALL(cparts)) - cparts.begin());
while (cparts.size() < 3)
cparts.push_back("");
assert(SZ(cparts) == 3);
string zzans = solve(std::count(ALL(parts), cparts[0]),
std::count(ALL(parts), cparts[1]),
std::count(ALL(parts), cparts[2]));
string ans = "";
for (char ch: zzans)
ans += cparts[ch - 'a'];
return ans;
}
// Time: T(x, y, z) = (x + y + z) + T(a, b, c), where a + b + c = x.
// since X in T(x, y, z) is decreasing in recursion, there are O(N) levels and each is O(N) => O(N^2)
// (actually implementation above is O(N^2 log) due to sort, but one can write without it).
int main() {
std::iostream::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int a = input<int>();
int b = input<int>();
int c = input<int>();
// remap 'a', 'b', 'c' in such way, that
// num of 'a' is not zeros.
std::map<char, char> back;
if (a == 0 and b == 0) {
back['a'] = 'c';
a = c;
b = 0;
c = 0;
} else if (a == 0) {
back['a'] = 'b';
back['b'] = 'c';
a = b;
b = c;
c = 0;
} else {
back['a'] = 'a';
back['b'] = 'b';
back['c'] = 'c';
}
// solve problem when a != 0.
string ans = solve(a, b, c);
for (int i = 0; i != SZ(ans); ++i)
cout << back[ans[i]];
cout << "\n";
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int X,Y,Z;
multiset<string>S;
int main(){
scanf("%d%d%d",&X,&Y,&Z);
while (X--) S.insert("a");
while (Y--) S.insert("b");
while (Z--) S.insert("c");
while (S.size()>1){
string t=*S.begin()+*(--S.end());
S.erase(S.begin());S.erase(--S.end());
S.insert(t);
}
cout<<*S.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
#define rep(i, n) for(int i=0;i<n;i++)
int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-12;
string getstr(string sa, string sb, int A, int B) {
if (A == 0 || B == 0) {
string rv;
for (int i = 1; i <= A; i++) rv += sa;
for (int i = 1; i <= B; i++) rv += sb;
return rv;
}
int c = B / A;
string s1 = sa;
string s2 = sa;
for (int i = 1; i <= c; i++) s1 += sb;
for (int i = 1; i <= c + 1; i++) s2 += sb;
return getstr(s1, s2, A - B%A, B%A);
}
string getstr(string sa, string sb, string sc, int A, int B, int C) {
if (A == 0) return getstr(sb, sc, B, C);
if (B == 0) return getstr(sa, sc, A, C);
if (C == 0) return getstr(sa, sb, A, B);
string s1 = sa;
string s2 = sa;
string s3 = sa;
int c1 = C / A, c2 = c1 + 1;
if (A*c1 == C) {
for (int i = 1; i <= c1; i++) {
s1 += sc;
s2 += sc;
}
int b1 = B / A, b2 = b1 + 1;
for (int i = 1; i <= b1; i++) s1 += sb;
for (int i = 1; i <= b2; i++) s2 += sb;
return getstr(s1, s2, A - B%A, B%A);
}
else {
for (int i = 1; i <= c1; i++) {
s1 += sc;
s2 += sc;
}
for (int i = 1; i <= c2; i++) s3 += sc;
int x = A - C%A, y = C%A;
int b1 = B / x, b2 = b1 + 1;
for (int i = 1; i <= b1; i++) s1 += sb;
for (int i = 1; i <= b2; i++) s2 += sb;
return getstr(s1, s2, s3, x - B%x, B%x, y);
}
}
int main() {
int A, B, C;
scanf("%d %d %d", &A, &B, &C);
string ans = getstr(string("a"), string("b"), string("c"), A, B, C);
return !printf("%s\n", ans.c_str());
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <string>
using namespace std;
string solve(string a, string b, string c, int x, int y, int z) {
if (y + z == 0) {
string res = "";
for (int i = 0; i < x; ++i) res += a;
return res;
}
if (x == 0) return solve(b, c, "", y, z, 0);
int p = x / (y + z);
int r = x % (y + z);
string A = "";
for (int i = 0; i < p; ++i) A += a;
if (z >= r) return solve(A + a + c, A + b, A + c, r, y, z - r);
else return solve(A + a + b, A + a + c, A + b, r - z, z, y + z - r);
}
int main() {
int x, y, z;
while (cin >> x >> y >> z) {
cout << solve("a", "b", "c", x, y, z) << endl;
}
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string eval(string s) {
int n = s.size();
s += s;
string ans = "~";
for (int i = 0; i < n; ++i) {
ans = min(ans, s.substr(i, n));
}
return ans;
}
int main() {
int X, Y, Z;
cin >> X >> Y >> Z;
int N = X + Y + Z;
string ans = string(X, 'a') + string(Y, 'b') + string(Z, 'c');
string cur_ev = eval(ans);
while (true) {
// 2-opt
bool found = false;
for (int i = 0; i < N && !found; ++i) {
for (int j = 1; j < N && !found; ++j) {
for (int k = 0; k <= N - j; ++k) {
string cyclic = ans.substr(i) + ans.substr(0, i);
string nxt = cyclic.substr(j, k) + cyclic.substr(0, j) + cyclic.substr(j + k);
string ev = eval(nxt);
if (ev > cur_ev) {
cur_ev = ev;
ans = nxt;
found = true;
break;
}
}
}
}
if (!found) break;
}
cout << cur_ev << endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int a,b,c;
string rec(int x,int y,int z,string X,string Y,string Z){
if(x==0&&y==0&&z==0) return "";
if(x==0&&y==0) return rec(z,0,0,Z,"","");
if(x==0) return rec(y,z,0,Y,Z,"");
if(y==0&&z==0){
string ret="";
rep(i,x) ret += X;
return ret;
}
if(z==0) return rec(x,z,y,X,Z,Y);
if(x >= z){
return rec(x-z,z,y,X,X+Z,Y);
}
else{
return rec(x,y,z-x,X+Z,Y,Z);
}
}
int main(){
cin >> a >> b >> c;
cout << rec(a,b,c,"a","b","c") << endl;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string s[55];
int n,a,b,c;
int main(){
scanf("%d%d%d",&a,&b,&c);
while(a--)s[++n]="a";
while(b--)s[++n]="b";
while(c--)s[++n]="c";
s[51]="cgz ak ioi";
s[52]="ABS ak ioi";
while(n>1){
int mi=51,mx=52;
for(int i=1;i<=n;++i){
if(s[i]<s[mi])mi=i;
if(s[i]>=s[mx])mx=i;
}
s[mi]+=s[mx];
swap(s[mx],s[n--]);
}
cout << s[1] << endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <tuple>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll, ll, ll> T;
int main(){
ll X, Y, Z;
cin >> X >> Y >> Z;
vector<string> v;
for(int i=0;i<X;i++)
v.push_back("a");
for(int i=0;i<Y;i++)
v.push_back("b");
for(int i=0;i<Z;i++)
v.push_back("c");
while(v.size()>1){
v[0] = v[0] + v.back();
v.pop_back();
sort(v.begin(), v.end());
}
cout << v[0] << endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
int main() {
std::multiset<std::string> set;
for(register int i=getint();i;i--) set.insert("a");
for(register int i=getint();i;i--) set.insert("b");
for(register int i=getint();i;i--) set.insert("c");
while(set.size()>1){
std::string s=*set.begin(),t=*set.rbegin();
set.erase(set.lower_bound(s));
set.erase(set.lower_bound(t));
set.insert(s+t);
}
std::cout<<*set.begin();
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
// std::ios::sync_with_stdio(false);
typedef long long LL;
const LL N = 107;
const int M = 2000005;
const int INF = 0x3f3f3f3f;
const double Pi = acos(-1);
int n,m;
int t[5];
multiset <string> st;
string ch(int x)
{
if (x==0)
return "a";
if (x==1)
return "b";
return "c";
}
int main()
{
cin.tie(0);
std::ios::sync_with_stdio(false);
while (cin>>t[0]>>t[1]>>t[2])
{
st.clear();
for (int i=0;i<3;i++)
for (int j=0;j<t[i];j++)
st.insert(ch(i));
while (st.size()>1)
{
multiset <string>::iterator l = st.begin();
multiset <string>::iterator r = --st.end();
st.insert(*l+*r);
st.erase(l);
st.erase(r);
}
cout<<*st.begin()<<endl;
}
return 0;
}
/*
*/
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
multiset<string> s;
int main()
{
int a, b, c, all = 0;
scanf("%d %d %d", &a, &b, &c);
all = a + b + c;
while(a--) s.insert("a");
while(b--) s.insert("b");
while(c--) s.insert("c");
while(1)
{
if(s.size() == 1) break;
string str = (*s.begin()) + *(--s.end());
s.erase(s.begin());
s.erase(--s.end());
s.insert(str);
}
cout << *s.begin() << endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define re return
#define fi first
#define mp make_pair
#define se second
#define sz(a) (int)a.size()
#define prev previ
#define tm tmmm
#define div divv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int ma = 1024 * 1024;
const ll mod = int(1e9) + 7;
int x = 4, y = 5, z = 8;
string s;
int main() {
iostream::sync_with_stdio(0), cin.tie(0);
cin >> x >> y >> z;
s = "";
vector<string> ss;
forn (i, x) {
string t = "a";
ss.push_back(t);
}
forn (i, y) {
string t = "b";
ss.push_back(t);
}
forn (i, z) {
string t = "c";
ss.push_back(t);
}
while (sz(ss) > 1) {
int k = 0;
forn (i, sz(ss))
if (ss[i] == ss[0]) k++;
if (k == sz(ss)) break;
for (int i = 0; i < k && sz(ss) > k; i++) {
ss[i] += ss[sz(ss) - 1];
ss.pop_back();
}
sort(ss.begin(), ss.end());
}
forn (i, sz(ss)) cout << ss[i];
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<cstring>
#include<set>
#include<algorithm>
using namespace std;
char s[100][100];
struct shion
{
int x;
shion(){}
shion(int x):x(x){}
bool operator < (const shion &a)const{return strcmp(s[x],s[a.x])<0;}
}s1,s2;
int pa;
multiset<shion>se;
multiset<shion>::iterator it;
int xi;
int main()
{
scanf("%d",&xi);while(xi--)s[++pa][0]='a',se.insert(shion(pa));
scanf("%d",&xi);while(xi--)s[++pa][0]='b',se.insert(shion(pa));
scanf("%d",&xi);while(xi--)s[++pa][0]='c',se.insert(shion(pa));
while(se.size()>1)
{
it=se.begin(),s1=*it,se.erase(it);
it=se.end(),it--,s2=*it,se.erase(it);
int x=s1.x,y=s2.x;
strcat(s[x],s[y]);
se.insert(shion(x));
}
it=se.begin();
s1=*it;
int x=s1.x;
printf("%s\n",s[x]);
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
char a[55],b[55];
int A,B,C,n,m;
bool f;
void dfs(int x,int y,int z){
memset(b,0,sizeof(b));
int k=0;
if(!y&&!z){
k=x;for(int i=0;i<x;i++)b[i]='a';
}else if(!x){
dfs(y,z,0);
k=m;
for(int i=0;i<m;i++)if(a[i]=='a')b[i]='b';else if(a[i]=='b')b[i]='c';
}else if(x<=z){
dfs(x,y,z-x);
for(int i=0;i<m;i++)if(a[i]=='a')b[k++]='a',b[k++]='c';else b[k++]=a[i];
}else if(x<=y+z){
dfs(x-z,z,y-x+z);
for(int i=0;i<m;i++)if(a[i]=='a')b[k++]='a',b[k++]='b';else if(a[i]=='b')b[k++]='a',b[k++]='c';else b[k++]='b';
}else{
dfs(x-y-z,y,z);
for(int i=0;i<m;i++)if(a[i]=='a')b[k++]='a';else if(a[i]=='b')b[k++]='a',b[k++]='b';else b[k++]='a',b[k++]='c';
}
memcpy(a,b,sizeof(a));m=k;
}
int main(){
scanf("%d%d%d",&A,&B,&C);n=A+B+C;
dfs(A,B,C);
printf("%s\n",a);
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, double> pd;
typedef pair<int, int> pi; typedef pair<ll, int> pli;
typedef pair<ll, ll> pll; typedef pair<ll, pi> plp;
typedef pair<int, pi> pip; typedef tuple<int, int, int> ti;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;
int A, B, C;
int main() {
cin >> A >> B >> C;
multiset<string> S;
for(int i=0; i<A; i++) S.insert("a");
for(int i=0; i<B; i++) S.insert("b");
for(int i=0; i<C; i++) S.insert("c");
for(int k=0; k<A+B+C-1; k++) {
string l = *S.begin();
auto it = S.end(); it--;
string r = *it;
S.erase(S.begin());
S.erase(it);
S.insert(l+r);
}
cout << *S.begin() << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | // start fold
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
using namespace std;
#define ri register int
#define il inline
#define LL long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define enter putchar('\n')
#define size(x) ((int)x.size())
#define mem0(x) memset(x,0,sizeof(x))
template<class T>il void in(T &x)
{
x=0; short f=1; char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') x=x*10+(c^'0'),c=getchar();
x*=f;
}
template <typename T,typename ...Args>il void in(T &x, Args &...args)
{
in(x); in(args...);
}
template<class T>il void out(T x,const char c='\n')
{
static short st[30];
short m=0;
if(x<0) putchar('-'),x=-x;
do st[++m]=x%10,x/=10; while(x);
while(m) putchar(st[m--]|'0');
putchar(c);
}
template <typename T,typename ...Args>il void out(const T &x,const Args &...args)
{
out(x,' '); out(args...);
}
template<class T>il void print(T a[],int n)
{
if(n<=0) return;
for(ri i=0; i<n; ++i) out(a[i],' ');
enter;
}
namespace i207M
{
// end fold
int a,b,c;
multiset<string>s;
signed main()
{
#ifdef M207
freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
#endif
in(a,b,c);
for(ri i=1; i<=a; ++i) s.insert("a");
for(ri i=1; i<=b; ++i) s.insert("b");
for(ri i=1; i<=c; ++i) s.insert("c");
while(size(s)>1)
{
string t=*s.begin()+*s.rbegin();
s.erase(s.begin()),s.erase(--s.end());
s.insert(t);
}
cout<<*s.begin();
return 0;
}
// start fold
}
signed main()
{
i207M::main();
return 0;
}
// end fold |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #pragma GCC optimize(3,"Ofast","inline")
#define R register
#include<iostream>
#include<set>
#include<cstring>
std::multiset <std::string> M;
std::multiset <std::string> :: iterator del;
int X,Y,Z;
int main(void){
std::cin>>X>>Y>>Z;
for(R int i=X;i>0;i--)
M.insert("a");
for(R int i=Y;i>0;i--)
M.insert("b");
for(R int i=Z;i>0;i--)
M.insert("c");
while(M.size()>=2){
std::string start=*M.begin(),ending=*M.rbegin();
del=M.lower_bound(start);
M.erase(del);
del=M.lower_bound(ending);
M.erase(del);
M.insert(start+ending);
}
std::cout<<*M.begin()<<std::endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <assert.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const int MAX=5e5+10;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
const ll MOD=1e9+7;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
bool start=false,neg=false;
char c;
num=0;
while((c=getchar())!=EOF) {
if(c=='-') start=neg=true;
else if(c>='0' && c<='9') {
start=true;
num=num*10+c-'0';
} else if(start) break;
}
if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
ll ret=1;
a%=M;
// b%=M;
while (b){
if (b&1) ret=ret*a%M;
b>>=1;
a=a*a%M;
}
return ret;
}
void open()
{
// freopen("1009.in","r",stdin);
freopen("out.txt","w",stdout);
}
int x,y,z;
vector<string>s;
int main()
{
scanf("%d%d%d",&x,&y,&z);
for(int i=0;i<x;i++)s.pb("a");
for(int i=0;i<y;i++)s.pb("b");
for(int j=0;j<z;j++)s.pb("c");
while(s.size()>1)
{
sort(s.begin(),s.end());
s[0]+=s[s.size()-1];
s.pop_back();
}
cout<<s[0]<<"\n";
}
/*
8
11011011
*/
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<cctype>
using namespace std;
const int N=1e3+50;
multiset <string> v;
int a,b,c;
int main()
{
cin>>a>>b>>c;
for(int i=1;i<=a;i++)
v.insert("a");
for(int i=1;i<=b;i++)
v.insert("b");
for(int i=1;i<=c;i++)
v.insert("c");
while(v.size()>1)
{
string x=*v.begin();
string y=*v.rbegin();
v.erase(v.lower_bound(x));
v.erase(v.lower_bound(y));
v.insert(x+y);
}
cout<<*v.begin();
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
string A[3],B[10];
int x[3],y[10];
string solve(){
if (x[1]==0&&x[2]==0){
string ans="";
for (int i=1;i<=x[0];i++) ans=ans+A[0];
return ans;
}
memset(y,0x00,sizeof y);
int num=x[2]/x[0];
for (int i=1;i<=num;i++) A[0]=A[0]+A[2];
A[2]=A[0]+A[2];
int ne=x[2]%x[0]; x[0]-=ne; x[2]=ne;
num=x[1]/x[0];
for (int i=1;i<=num;i++) A[0]=A[0]+A[1];
A[1]=A[0]+A[1];
ne=x[1]%x[0]; x[0]-=ne; x[1]=ne;
return solve();
}
int main(){
for (int i=0;i<3;i++) scanf("%d",&x[i]);
A[0]='a'; A[1]='b'; A[2]='c';
if (x[0]==0){
x[0]=x[1]; x[1]=x[2];
A[0]=A[1]; A[1]=A[2];
x[2]=0;
}
if (x[0]==0){
x[0]=x[1]; x[1]=x[2];
A[0]=A[1]; A[1]=A[2];
x[2]=0;
}
cout<<solve()<<endl;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO
#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif
typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
/*
ll pw(ll a, ll b) {
ll ans = 1; while (b) {
while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
ans = (ans * a) % MOD, --b;
} return ans;
}
*/
string solve(string sa, int a, string sb, int b, string sc, int c) {
if (a == 0) {
return solve(sb, b, sc, c, "", 0);
}
if (a <= b + c) {
vector<string> vv(a, sa);
int g = c / a;
for (int i = 0; i < vv.size(); ++i)
for (int j = 0; j < g; ++j)
vv[i] += sc;
g = a - c % a;
for (int i = g; i < a; ++i)
vv[i] += sc;
for (int i = 0; i < b; ++i)
vv[i % g] += sb;
sort(vv.begin(), vv.end());
vector<pair<string, int> > go;
int cur = 0;
for (int i = 0; i < vv.size(); ++i) {
++cur;
if (i == vv.size() - 1 || vv[i + 1] != vv[i]) {
go.push_back(make_pair(vv[i], cur));
cur = 0;
}
}
while (go.size() < 3)
go.push_back(make_pair("", 0));
return solve(go[0].first, go[0].second, go[1].first, go[1].second, go[2].first, go[2].second);
}
else {
if (b + c == 0) {
string ans;
for (int i = 0; i < a; ++i)
ans += sa;
return ans;
}
vector<string> vv(b + c);
for (int i = 0; i < a; ++i)
vv[i % (b + c)] += sa;
for (int i = 0; i < c; ++i)
vv[i] += sc;
for (int i = 0; i < b; ++i)
vv[c + i] += sb;
sort(vv.begin(), vv.end());
vector<pair<string, int> > go;
int cur = 0;
for (int i = 0; i < vv.size(); ++i) {
++cur;
if (i == vv.size() - 1 || vv[i + 1] != vv[i]) {
go.push_back(make_pair(vv[i], cur));
cur = 0;
}
}
while (go.size() < 3)
go.push_back(make_pair("", 0));
return solve(go[0].first, go[0].second, go[1].first, go[1].second, go[2].first, go[2].second);
}
}
int main() {
#ifdef FASTIO
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
int a, b, c;
cin >> a >> b >> c;
cout << solve("a", a, "b", b, "c", c) << "\n";
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
using namespace std;
int a, b, c, xa, xb, xc;
string AA, BB, CC, ss[110];
void iter() {
for (int i = 0; i < a; i++)
ss[i] = AA;
// int now = 0;
for (int i = 0; i < c; i++) {
ss[i % a] += CC;
}
int ll = 0;
if (c % a == 0)
ll = 0;
else
ll = (c - 1) % a + 1;
int now = ll;
for (int i = 0; i < b; i++) {
ss[now] += BB;
now += 1;
if (now >= a)
now = ll;
}
sort(ss, ss + a);
// for ()
int cnt = 0;
xa = xb = xc = 0;
for (int i = 0; i < a; i++) {
if (i == 0 || ss[i] != ss[i - 1]) {
cnt += 1;
if (cnt == 1)
AA = ss[i];
else if (cnt == 2)
BB = ss[i];
else CC = ss[i];
}
if (cnt == 1)
xa += 1;
else if (cnt == 2)
xb += 1;
else xc += 1;
}
a = xa;
b = xb;
c = xc;
}
string solve() {
AA = "a";
BB = "b";
CC = "c";
if (a == 0) {
a = b; b = c; c = 0;
AA = BB; BB = CC;
}
string ans = "";
if (a == 0) {
for (int i = 0; i < c; i++)
ans += "c";
// printf("\n");
// return 0;
return ans;
}
while (b + c > 0) {
iter();
}
while (a--) {
// cout << AA;
ans += AA;
// return
}
return ans;
// cout << endl;
}
int main() {
scanf("%d%d%d", &a, &b, &c);
// for (int aa = 0; aa <= 50; aa++)
// for (int bb = 0; bb <= 50; bb++)
// for (int cc = 0; cc <= 50; cc++)
// if (aa + bb + cc > 0 && aa + bb + cc <= 50) {
// // int aa = a, bb = b, cc = c;
// a = aa;
// b = bb;
// c = cc;
// cout << aa << ' ' << bb << ' ' << cc << ' '<< solve() << endl;;
// }
string ans = solve();
cout << ans << endl;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;
int main(){
int X,Y,Z;cin>>X>>Y>>Z;
vector<string> v(X+Y+Z);
repeat(i,X)v[i]="a";
repeat(i,Y)v[X+i]="b";
repeat(i,Z)v[X+Y+i]="c";
while(v.size()>1){
sort(v.begin(),v.end());
v[0]+=v.back();
v.pop_back();
}
cout<<v[0]<<endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cstdio>
#include<set>
#include<string>
using namespace std;
multiset<string>s;
int main(){
int aa,bb,cc,p=0;
scanf("%d%d%d",&aa,&bb,&cc);
p=aa+bb+cc;
for(;aa--;)s.insert("a");
for(;bb--;)s.insert("b");
while(cc--)s.insert("c");
while(--p){
auto st=(*s.begin())+*(--s.end());
s.erase(s.begin());
s.erase(--s.end());
s.insert(st);
}
puts((*s.begin()).c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
//最小に最大をつなげる
vector<string>sts;
int a,b,c,i;cin>>a>>b>>c;
while(a--){sts.pub("a");}
while(b--){sts.pub("b");}
while(c--){sts.pub("c");}
while(sts.size()>1){
int syox=0;
int daix=0;
for(i=1;i<sts.size();i++){
if(sts[syox]>sts[i]){syox=i;}
else if(sts[daix]<sts[i]){daix=i;}
else if(syox==daix&&sts[daix]==sts[i]){daix=i;}
}
sts[syox]+=sts[daix];
sts[daix]=sts.back();
sts.pob();
//for(auto it:sts){cout<<it<<" ";}cout<<endl;
}
cout<<sts[0]<<endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string> S;
string s1,s2,t;
int main()
{
scanf("%d%d%d",&a,&b,&c);
for (int i=1;i<=a;i++) S.insert("a");
for (int i=1;i<=b;i++) S.insert("b");
for (int i=1;i<=c;i++) S.insert("c");
for (int i=1;i<a+b+c;i++) {
t=*S.begin()+*(--S.end());
S.erase(S.begin()); S.erase(--S.end());
S.insert(t);
}
cout << *S.begin();
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string> s;
int main() {
scanf("%d%d%d",&a,&b,&c);
for (int i=1;i<=a;++i) s.insert("a");
for (int i=1;i<=b;++i) s.insert("b");
for (int i=1;i<=c;++i) s.insert("c");
for (int i=1;i<a+b+c;++i) {
auto l=s.begin(),r=s.end();r--;
s.insert(*l+*r);
s.erase(l);s.erase(r);
}
printf("%s\n",s.begin()->c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
int main() {
int x, y, z;
cin >> x >> y >> z;
multiset<string> A;
for (int i = 0; i < x; ++i) A.insert("a");
for (int i = 0; i < y; ++i) A.insert("b");
for (int i = 0; i < z; ++i) A.insert("c");
for (int k = 1; k < x + y + z; ++k) {
auto it1 = A.begin();
auto it2 = prev(A.end());
auto s = *it1 + *it2;
A.erase(it1);
A.erase(it2);
A.insert(s);
}
cout << *A.begin() << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
return sgn-'-'?ans:-ans;
}
multiset<string> s; int X, Y, Z; string L, T = "\0";
int main()
{
X = read(), Y = read(), Z = read();
for(rint i = 1; i <= X; s.insert("a"), i++);
for(rint i = 1; i <= Y; s.insert("b"), i++);
for(rint i = 1; i <= Z; s.insert("c"), i++);
for(; s.size() >= 2; L = *s.begin()+*--s.end(), s.erase(s.begin()), s.erase(--s.end()), s.insert(L));
if(s.size()) T = *s.begin(); cout << T << endl; return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
string ans;
void dfs(int a,int b,int c,string aa,string bb,string cc)
{
string nowa,nowb,nowc;
if (a==0)
{
dfs(b,c,0,bb,cc,"");
return;
}
if ((b==0)&&(c==0))
{
int i;
for (i=0;i<a;i++)
{
ans+=aa;
}
return;
}
nowa=aa;
int j;
for (j=0;j<c/a;j++)
{
nowa+=cc;
}
int newc=c%a;
nowc=nowa+cc;
a-=newc;
for (j=0;j<b/a;j++)
{
nowa+=bb;
}
int newb=b%a;
nowb=nowa+bb;
a-=newb;
dfs(a,newb,newc,nowa,nowb,nowc);
}
int main()
{
#ifdef absi2011
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
dfs(a,b,c,"a","b","c");
cout<<ans<<endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int a,b,c;
multiset<string> s;
int main()
{
scanf("%d%d%d",&a,&b,&c);
for (int i=0;i<a;i++)
{
s.insert("a");
}
for (int i=0;i<b;i++)
{
s.insert("b");
}
for (int i=0;i<c;i++)
{
s.insert("c");
}
multiset<string>::iterator it;
while (s.size()!=1)
{
string x=*s.begin();
string y=*s.rbegin();
it=s.find(x);
s.erase(it);
it=s.find(y);
s.erase(it);
s.insert(x+y);
}
cout<<*s.begin()<<endl;
return 0;
}
//直道相思了无益,未妨惆怅是清狂。
//——李商隐《无题》 |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.a<<","<<p.b<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ";
dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,"Line:",__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif
using uint=unsigned;
using ull=unsigned long long;
template<int i,class T>
void print_tuple(ostream&,const T&){
}
template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
if(i)os<<",";
os<<get<i>(t);
print_tuple<i+1,T,Args...>(os,t);
}
template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
os<<"{";
print_tuple<0,tuple<Args...>,Args...>(os,t);
return os<<"}";
}
void print(ll x,int suc=1){
cout<<x;
if(suc==1)
cout<<"\n";
if(suc==2)
cout<<" ";
}
ll read(){
ll i;
cin>>i;
return i;
}
vi readvi(int n,int off=0){
vi v(n);
rep(i,n)v[i]=read()+off;
return v;
}
template<class T>
void print(const vector<T>&v,int suc=1){
rep(i,v.size())
print(v[i],i==int(v.size())-1?suc:2);
}
string readString(){
string s;
cin>>s;
return s;
}
template<class T>
T sq(const T& t){
return t*t;
}
//#define CAPITAL
void yes(bool ex=true){
#ifdef CAPITAL
cout<<"YES"<<endl;
#else
cout<<"Yes"<<endl;
#endif
if(ex)exit(0);
}
void no(bool ex=true){
#ifdef CAPITAL
cout<<"NO"<<endl;
#else
cout<<"No"<<endl;
#endif
if(ex)exit(0);
}
constexpr ll ten(int n){
return n==0?1:ten(n-1)*10;
}
const ll infLL=LLONG_MAX/3;
#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif
int topbit(signed t){
return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
return __builtin_popcount(t);
}
int popcount(ll t){
return __builtin_popcountll(t);
}
bool ispow2(int i){
return i&&(i&-i)==i;
}
int mask(int i){
return (int(1)<<i)-1;
}
bool inc(int a,int b,int c){
return a<=b&&b<=c;
}
template<class t> void mkuni(vc<t>&v){
sort(all(v));
v.erase(unique(all(v)),v.ed);
}
ll rand_int(ll l, ll r) { //[l, r]
#ifdef LOCAL
static mt19937_64 gen;
#else
static random_device rd;
static mt19937_64 gen(rd());
#endif
return uniform_int_distribution<ll>(l, r)(gen);
}
template<class t>
int lwb(const vc<t>&v,const t&a){
return lower_bound(all(v),a)-v.bg;
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int x,y,z;cin>>x>>y>>z;
multiset<string> s;
rep(i,x)s.insert("a");
rep(i,y)s.insert("b");
rep(i,z)s.insert("c");
while(s.size()>1){
auto itr=s.bg;
string a=*itr;
s.erase(itr);
itr=prev(s.ed);
a+=*itr;
s.erase(itr);
s.insert(a);
}
cout<<*s.bg<<endl;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | // This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
char t=getchar();
bool neg=false;
x=0;
for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
if(t=='-')neg=true,t=getchar();
for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
if(x<0)putchar('-'),x=-x;
short a[20]= {},sz=0;
while(x>0)a[sz++]=x%10,x/=10;
if(sz==0)putchar('0');
for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);
int a,b,c;
string now,dp[55][55][55];
bool ok[55][55][55];
void update(int i,int j,int k,const string&s)
{
if(s+now>=now+now.substr(0,s.size()))
{
if(!ok[i][j][k])
{
ok[i][j][k]=1;
dp[i][j][k]=s;
}
else if(dp[i][j][k]<s)dp[i][j][k]=s;
}
}
bool check()
{
memset(ok,0,sizeof(ok));
ok[0][0][0]=1;dp[0][0][0]="";
for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)for(int k=0;k<=c;k++)
{
if(!ok[i][j][k])continue;
if(i<a)update(i+1,j,k,'a'+dp[i][j][k]);
if(j<b)update(i,j+1,k,'b'+dp[i][j][k]);
if(k<c)update(i,j,k+1,'c'+dp[i][j][k]);
}
return ok[a][b][c];
}
int main()
{
cin>>a>>b>>c;
for(int i=0;i<a+b+c;i++)now+='a';
for(int i=0,j;i<a+b+c;i++)
{
for(j='b';j<='c';j++)
{
now[i]=j;
if(!check())break;
}
now[i]=j-1;
}
cout<<now<<endl;
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
int main() {
std::multiset<std::string> set;
for(register int i=getint();i;i--) set.insert("a");
for(register int i=getint();i;i--) set.insert("b");
for(register int i=getint();i;i--) set.insert("c");
while(set.size()>1) {
std::string s=*set.begin(),t=*set.rbegin();
set.erase(set.lower_bound(s));
set.erase(set.lower_bound(t));
set.insert(s+t);
}
printf("%s\n",(*set.begin()).c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include "bits/stdc++.h"
using namespace std;
multiset < string > s;
int a , b , c;
int main(){
cin >> a >> b >> c;
for(int i = 0 ; i < a ; ++i){
s.insert("a");
}
for(int i = 0 ; i < b ; ++i){
s.insert("b");
}
for(int i = 0 ; i < c ; ++i){
s.insert("c");
}
while(s.size() > 1){
string str = (*s.begin()) + (*prev(s.end()));
s.erase(s.begin());
s.erase(prev(s.end()));
s.insert(str);
}
cout << *(s.begin()) << endl;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include "bits/stdc++.h"
using namespace std;
const int maxn = 55;
string res;
int M(){
int x, y, z;
if(!(cin >> x >> y >> z)) return 0;
multiset<string> v;
for(int e = 0; e < x; e++) v.insert("a");
for(int e = 0; e < y; e++) v.insert("b");
for(int e = 0; e < z; e++) v.insert("c");
while(v.size() > 1){
string fi = *(v.begin());
string se = *(--v.end());
v.erase(v.begin());
v.erase(--v.end());
v.insert(fi + se);
}
cout << *(v.begin()) << endl;
return 1;
}
int main(){
while(M());
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | python3 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
x,y,z = LI()
a = ['a' for _ in range(x)] + ['b' for _ in range(y)] + ['c' for _ in range(z)]
while len(a) > 1:
a.sort()
a[0] += a[-1]
a = a[:-1]
return a[0]
print(main())
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
multiset<string> sp;
int main() {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
while(x--)
sp.insert("a");
while(y--)
sp.insert("b");
while(z--)
sp.insert("c");
while(sp.size() > 1) {
string fir = *sp.begin();
sp.erase(sp.begin());
string las = *sp.rbegin();
sp.erase(sp.find(las));
sp.insert(fir + las);
}
puts(sp.begin() -> c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
string solve(int x,int y,int z){
if(x==0){
string s=solve(y,z,0);
rep(i,s.size()){
if(s[i]=='a')s[i]='b';
else if(s[i]=='b')s[i]='c';
}
return s;
}
if(y==0&&z){
string s=solve(x,z,0);
rep(i,s.size()){
if(s[i]=='b')s[i]='c';
}
return s;
}
if(y==0)return string(x,'a');
if(z==0){
if(x<=y){
string s=solve(x,y%x,0);
string t;
rep(i,s.size()){
if(s[i]=='a'){
t+="a";
t+=string(y/x,'b');
}
else{
t+="b";
}
}
return t;
}
string s=solve(x-y,y,0);
string t;
rep(i,s.size()){
if(s[i]=='a'){
t+="a";
}
else{
t+="ab";
}
}
return t;
}
if(x<=z){
string s=solve(x,y,z%x);
string t;
rep(i,s.size()){
if(s[i]=='a'){
t+="a";
t+=string(z/x,'c');
}
else if(s[i]=='b'){
t+="b";
}
else{
t+="c";
}
}
return t;
}
int q=y%(x-z);
int p=x-z-q;
int r=z;
string s=solve(p,q,r);
string t;
rep(i,s.size()){
if(s[i]=='a'){
t+="a";
t+=string(y/(x-z),'b');
}
else if(s[i]=='b'){
t+="a";
t+=string(y/(x-z)+1,'b');
}
else{
t+="ac";
}
}
return t;
}
signed main(){
int X,Y,Z;
cin>>X>>Y>>Z;
cout<<solve(X,Y,Z)<<endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string a;
multiset <string> se;
int main()
{
// cin >> a;
// for(int i=0;i<a.length();i++)
// se.insert(a.substr(i,1));
int x,y,z;
cin >> x >> y >> z;
for(int i=1;i<=x;i++)
se.insert("a");
for(int i=1;i<=y;i++)
se.insert("b");
for(int i=1;i<=z;i++)
se.insert("c");
while(se.size()>1)
{
string tem=*se.begin()+*--se.end();
se.erase(se.begin());
se.erase(--se.end());
se.insert(tem);
}
cout << *se.begin() << endl;
return 0;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main() {
multiset<std::string> set;
int i;
for(cin>>i; i; i--) set.insert("a");
for(cin>>i; i; i--) set.insert("b");
for(cin>>i; i; i--) set.insert("c");
while(set.size()>1) {
std::string s=*set.begin(),t=*set.rbegin();
set.erase(set.lower_bound(s));
set.erase(set.lower_bound(t));
set.insert(s+t);
}
printf("%s\n",(*set.begin()).c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
string operator*(string a,int k){
string s;
rep(i,k) s += a;
return s;
}
string solve(int A,int B,int C,string a,string b,string c){
// puts("-------------");
// printf("A,B,C = %d,%d,%d\n",A,B,C);
// show(a);
// show(b);
// show(c);
// puts("-------------");
if(B+C==0){
return a*A;
}
if(A+C==0){
return b*B;
}
if(B+A==0){
return c*C;
}
if(A==0){
return solve(B,C,0,b,c,"");
}
//aaa.aaa.aaa.aa.aa.
int q = A/(B+C);
int r = A%(B+C);
string o = a*q;
if(r<=C){
return solve(r,B,C-r,o+a+c,o+b,o+c);
}else{
return solve(r-C,C,B-(r-C),o+a+b,o+a+c,o+b);
}
}
int main(){
int A,B,C;
cin>>A>>B>>C;
cout<<solve(A,B,C,"a","b","c")<<endl;
}
|
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | // ※※※ 解答不能 ※※※
// snuke氏.
// https://atcoder.jp/contests/code-festival-2017-qualb/submissions/1636517
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int main(){
multiset<string> s;
rep(i, 3){
int n;
scanf("%d", &n);
rep(j, n) s.insert(string(1, 'a' + i));
}
while(s.size() > 1){
auto it = s.end();
--it;
string x = *(s.begin()) + *it;
s.erase(it);
s.erase(s.begin());
s.insert(x);
}
string ans = *(s.begin());
printf("%s\n", ans.c_str());
return 0;
} |
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift | For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`).
You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically.
Compute the lexicographically largest possible value of f(T).
Constraints
* 1 \leq X + Y + Z \leq 50
* X, Y, Z are non-negative integers.
Input
Input is given from Standard Input in the following format:
X Y Z
Output
Print the answer.
Examples
Input
2 2 0
Output
abab
Input
1 1 1
Output
acb | {
"input": [
"2 2 0",
"1 1 1"
],
"output": [
"abab",
"acb"
]
} | {
"input": [],
"output": []
} | CORRECT | cpp | #include <cstdio>
#include <iostream>
#include <set>
using namespace std;
inline char nc() {
static char buf[100000], *l = buf, *r = buf;
return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
x = 0; int f = 1, ch = nc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
x *= f;
}
int X, Y, Z;
multiset<string> s;
int main() {
// freopen("testdata.in", "r", stdin);
read(X), read(Y), read(Z);
for(int i = 1; i <= X; ++i) {
s.insert("a");
}
for(int i = 1; i <= Y; ++i) {
s.insert("b");
}
for(int i = 1; i <= Z; ++i) {
s.insert("c");
}
set<string> :: iterator it;
while(s.size() > 1) {
string a, b;
it = s.begin(); a = *it; s.erase(it);
it = s.end(); b = *(--it); s.erase(it);
s.insert(a + b);
}
cout << *s.begin() << endl;
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.