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>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,true):false;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,true):false;}
int nextInt() { int x; scanf("%d", &x); return x;}
int main2() {
int X = nextInt();
int Y = nextInt();
int Z = nextInt();
vector<string> v;
REP(i, X) v.push_back("a");
REP(i, Y) v.push_back("b");
REP(i, Z) v.push_back("c");
while (v.size() > 1) {
sort(v.begin(), v.end());
v.front() += v.back();
v.erase(v.begin() + v.size() - 1);
}
cout << v.front() << endl;
return 0;
}
int main() {
for (;!cin.eof();cin>>ws) main2();
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 lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 4005;
#define rend fuck
int x, y, z;
string s;
int dp[51][51][51][51];
int link[51][3]; // -1 if failure, otherwise follow it's next
int fail[51];
bool rend[MAXN];
bool f(int x, int y, int z, int m){
if(m == s.size()) m = fail[m];
if(x + y + z == 0) return rend[m];
if(~dp[x][y][z][m]) return dp[x][y][z][m];
int ret = 0;
if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
return dp[x][y][z][m] = ret;
}
bool trial(){
int p = 0;
for(int i=1; i<s.size(); i++){
while(p && s[i] != s[p]) p = fail[p];
if(s[i] == s[p]) p++;
fail[i+1] = p;
}
for(int i=0; i<s.size(); i++){
for(int j=0; j<3; j++){
int pos = i;
if(s[i] > j + 'a'){
link[i][j] = -1;
continue;
}
while(pos && s[pos] != j + 'a') pos = fail[pos];
if(s[pos] == j + 'a') pos++;
link[i][j] = pos;
}
}
for(int i=0; i<s.size(); i++){
int pos = i;
rend[i] = 1;
for(int j=0; j<s.size(); j++){
pos = link[pos][s[j] - 'a'];
if(pos == -1){
rend[i] = 0;
break;
}
}
}
memset(dp, -1, sizeof(dp));
return f(x, y, z, 0);
}
int main(){
cin >> x >> y >> z;
while(s.size() < x + y + z){
s.push_back('c');
if(trial()) continue;
s.back() = 'b';
if(trial()) continue;
s.back() = 'a';
}
cout << 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<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
putchar('\n');
}
string dp[51][51][51];
int X, Y, Z;
int N;
string S;
// qUUUU >= UUUUU
bool ok() {
REP (x, X+1) REP (y, Y+1) REP (z, Z+1) dp[x][y][z].clear();
REP (x, X+1) REP (y, Y+1) REP (z, Z+1) if (x+y+z == (int)dp[x][y][z].size()) {
for (char c='c'; c>='a'; c--) {
string g = string(1, c) + dp[x][y][z];
string &t = (c=='c'? dp[x][y][z+1]:
(c=='b'? dp[x][y+1][z]: dp[x+1][y][z]));
if (t.empty() || t < g) if (g + S + S > S + S) {
t = g;
}
}
}
return !dp[X][Y][Z].empty();
}
void MAIN() {
scanf("%d%d%d", &X, &Y, &Z);
N = X + Y + Z;
S = string(N, 'a');
REP (i, N) {
S[i] = 'c';
if (!ok()) {
S[i] = 'b';
if (!ok()) S[i] = 'a';
}
}
puts(S.c_str());
}
int main() {
int TC = 1;
// scanf("%d", &TC);
REP (tc, TC) MAIN();
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 <utility>
#define llint long long
using namespace std;
typedef pair<llint, llint> P;
int n;
int x, y, z;
string dp[55][55][55];
string ans;
bool check(string s)
{
while(s.size() < n) s += 'a';
for(int i = 0; i <= x; i++){
for(int j = 0; j <= y; j++){
for(int k = 0; k <= z; k++){
dp[i][j][k] = "";
}
}
}
dp[0][0][0] = s;
for(int i = 0; i <= x; i++){
for(int j = 0; j <= y; j++){
for(int k = 0; k <= z; k++){
if(dp[i][j][k] < s) continue;
if(i+1 <= x) dp[i+1][j][k] = max(dp[i+1][j][k], ('a' + dp[i][j][k]).substr(0, n));
if(j+1 <= y) dp[i][j+1][k] = max(dp[i][j+1][k], ('b' + dp[i][j][k]).substr(0, n));
if(k+1 <= z) dp[i][j][k+1] = max(dp[i][j][k+1], ('c' + dp[i][j][k]).substr(0, n));
}
}
}
return (dp[x][y][z] >= s);
}
int main(void)
{
cin >> x >> y >> z;
n = x + y + z;
for(int i = 0; i < n; i++){
for(int j = 2; j >= 0; j--){
string s = ans + ((char)('a'+j));
if(check(s)){
ans = s;
break;
}
}
}
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 <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>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
template<class T> inline void read(T &x){
int f=0;x=0;char ch=getchar();
for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
if(f)x=-x;
}
string solve(string a,string b,int x,int y){
// assert(a.size()+b.size()<=20);
// cerr<<a<<" "<<b<<" "<<x<<" "<<y<<endl;
if(b+a<a+b) swap(a,b),swap(x,y);
if(!x||!y){
string res;
rep(i,1,x) res+=a;
rep(i,1,y) res+=b;
return res;
}
if(x<y){
int u=y/x,v=y%x;
string A=a,B;
while(u--) A+=b; B=A+b;
return solve(A,B,x-v,v);
}
int u=x/y,v=x%y;
string A,B;
while(u--) A+=a; A+=b; B=a+A;
return solve(A,B,y-v,v);
}
string solve(string a,string b,string c,int x,int y,int z){
if(b+a<a+b) swap(a,b),swap(x,y);
if(c+a<a+c) swap(a,c),swap(x,z);
if(c+b<b+c) swap(b,c),swap(y,z);
if(!x) return solve(b,c,y,z);
if(!y) return solve(a,c,x,z);
if(!z) return solve(a,b,x,y);
vector<string> s(x,a);
REP(i,z) s[i%x]+=c;
int cur=z%x;
REP(i,y){
s[cur++]+=b;
if(cur==x) cur=z%x;
}
map<string,int> t;
REP(i,x) t[s[i]]++;
string S[3]; int C[3]={0,0,0},k=0;
for(auto x:t) S[k]=x.fi,C[k++]=x.se;
return solve(S[0],S[1],S[2],C[0],C[1],C[2]);
}
int main(){
int x,y,z;
cin>>x>>y>>z;
cout<<solve("a","b","c",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<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int C[1100];
int B[1100];
int ad=0;
vector<string> str;
void f(string aa,string bb,string cc,int a,int b,int c){
//printf("%s %s %s %d %d %d\n",aa.c_str(),bb.c_str(),cc.c_str(),a,b,c);
if(a==0){
f(bb,cc,"",b,c,0);
return;
}
if(b+c==0){
for(int i=0;i<a;i++)printf("%s",aa.c_str());printf("\n");return;
}
ad=0;
for(int i=0;i<1100;i++)B[i]=C[i]=0;
while(a==0){
a=b;b=c;c=0;ad++;
}
for(int i=0;i<c;i++){
C[i%a]++;
}
if(C[0]!=C[a-1]){
int f=0;
for(int i=0;i<a;i++)if(C[a-1]==C[i])f++;
for(int i=0;i<b;i++){
B[a-f+i%f]++;
}
}else{
for(int i=0;i<b;i++){
B[i%a]++;
}
}
str.clear();
for(int i=a-1;i>=0;i--){
string tmp="";
tmp+=aa;
for(int j=0;j<C[i];j++)tmp+=cc;//printf("%c",'c'+ad);
for(int j=0;j<B[i];j++)tmp+=bb;//printf("%c",'b'+ad);
str.push_back(tmp);
}
std::sort(str.begin(),str.end());
// for(int i=0;i<str.size();i++)printf("%s\n",str[i].c_str());
string ta="",tb="",tc="";
int va=0;
int vb=0;
int vc=0;
int fi=0;
int ph=0;
for(int i=0;i<a;i++){
if(str[i]==str[fi]){
if(ph==0){va++;ta=str[i];}
if(ph==1){vb++;tb=str[i];}
if(ph==2){vc++;tc=str[i];}
}else{
// printf("%s %s\n",str[i].c_str(),str[fi].c_str());
if(ph==0){ph++;vb++;tb=str[i];fi=i;}
else if(ph==1){ph++;vc++;tc=str[i];fi=i;}
}
}
f(ta,tb,tc,va,vb,vc);
}
int main(){
int a,b,c;scanf("%d%d%d",&a,&b,&c);
f("a","b","c",a,b,c);
/*for(int i=0;i<100;i++){
int a=rand()%10;
int b=rand()%10;
int c=rand()%10;
if(a+b+c==0)continue;
printf("%d %d %d: ",a,b,c);
f("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 namespace std;
int a,b,c;
multiset<string> se;
int main(){
scanf("%d%d%d",&a,&b,&c);
for (int i=1;i<=a;++i) se.insert("a");
for (int i=1;i<=b;++i) se.insert("b");
for (int i=1;i<=c;++i) se.insert("c");
while (se.size()>1){
string x=*se.begin(),y=*se.rbegin();
se.erase(se.begin()); se.erase(--se.end());
se.insert(x+y);
}
puts(se.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 MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int x,y,z;
vector<string> ss;
int main(void){
scanf("%d%d%d",&x,&y,&z);
for(int i=0;i<x;i++){
ss.push_back("a");
}
for(int i=0;i<y;i++){
ss.push_back("b");
}
for(int i=0;i<z;i++){
ss.push_back("c");
}
while(ss.size()>1){
sort(ss.begin(),ss.end());
ss[0]+=ss[ss.size()-1];
ss.pop_back();
}
cout << ss[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<iostream>
#include<set>
using namespace std;
multiset<string> s;
int main()
{
int x,y,z;
cin>>x>>y>>z;
while(x--)s.insert("a");
while(y--)s.insert("b");
while(z--)s.insert("c");
while(s.size()>1)
{
string x=*s.begin()+*--s.end();
s.erase(s.begin());
s.erase(--s.end());
s.insert(x);
}
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 main() {
int x, y, z;
scanf("%d %d %d", &x, &y, &z);
multiset<string> chars;
for (int i = 0; i < x; i++) chars.insert("a");
for (int i = 0; i < y; i++) chars.insert("b");
for (int i = 0; i < z; i++) chars.insert("c");
while (chars.size() > 1) {
string first = *chars.begin();
chars.erase(chars.begin());
string last = *prev(chars.end());
chars.erase(prev(chars.end()));
chars.insert(first + last);
}
printf("%s\n", chars.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 <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int _w;
vector<string> v;
int main() {
int a, b, c;
_w = scanf( "%d%d%d", &a, &b, &c );
for( int i = 0; i < a; ++i ) v.push_back("a");
for( int i = 0; i < b; ++i ) v.push_back("b");
for( int i = 0; i < c; ++i ) v.push_back("c");
while( v.size() > 1 ) {
sort(v.begin(), v.end());
string s1 = v.front(), s2 = v.back();
v.pop_back();
reverse(v.begin(), v.end());
v.pop_back();
v.push_back(s1+s2);
}
cout << v.front() << 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 <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
string solve(string A, int x, string B, int y, string C, int z) {
if (x == 0)
return solve(B, y, C, z, "", 0);
if (y == 0 && z == 0) {
string res = "";
while(x--) res += A;
return res;
}
if (y == 0)
return solve(A, x, C, z, "", 0);
int sum = y + z;
int p = x / sum;
int q = x % sum;
string As = "";
for (int i = 0; i < p; i++)
As += A;
string Ab = As + A;
if (q == 0) {
return solve(As + B, y, As + C, z, "", 0);
}
p = sum - q;
if (z < q) {
return solve(Ab + B, q - z, Ab + C, z, As + B, p);
}
if (z == q) {
return solve(Ab + C, q, As + B, p, "", 0);
}
return solve(Ab + C, q, As + B, y, As + C, z - q);
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int x, y, z;
cin >> x >> y >> z;
cout << solve("a", x, "b", y, "c", 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>
#define gc getchar()
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){char ch=gc;int w=1,s=0;while(!isdigit(ch)){if(ch=='-') w=-1;ch=gc;};while(isdigit(ch)){s=s*10+ch-'0';ch=gc;} return w*s;}
multiset<string> q;
int main()
{
int a=read(),b=read(),c=read();
for(rint i=1;i<=a;++i) q.insert("a");
for(rint i=1;i<=b;++i) q.insert("b");
for(rint i=1;i<=c;++i) q.insert("c");
while(q.size()>=2)
{
string s=(*q.begin())+(*q.rbegin());
q.erase(q.begin());
q.erase(--q.end());
q.insert(s);
}
cout<<(*q.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.lower_bound(a));
s.erase(s.lower_bound(b));
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 {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}
int main(){
multiset<string> S;
rep(i,0,3){
int x;
cin >> x;
rep(j,0,x) S.insert(string(1 , i + 'a'));
}
while(sz(S) > 1){
auto it = S.end();
--it;
string a = *S.begin() + *it;
S.erase(it);
S.erase(S.begin());
S.insert(a);
}
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 <stdio.h>
#include <set>
#include <string>
int main()
{
std::multiset<std::string> set;
for (int i = 0; i < 3; ++ i) {
int x;
scanf("%d", &x);
for (int j = 0; j < x; ++ j)
set.emplace(1, 'a' + i);
}
while (set.size() > 1) {
auto it = -- set.end();
std::string s = *set.begin() + *it;
set.erase(set.begin());
set.erase(it);
set.emplace(s);
}
printf("%s\n", set.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 | //by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
char s[100000];
int it,len;
fastio(){it=len=0;}
inline char get()
{
if(it<len)return s[it++];it=0;
len=fread(s,1,100000,stdin);
if(len==0)return EOF;else return s[it++];
}
bool notend()
{
char c=get();
while(c==' '||c=='\n')c=get();
if(it>0)it--;
return c!=EOF;
}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
ll r=0;bool ng=0;char c;c=_buff.get();
while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
if(c=='-')ng=1,c=_buff.get();
while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
if(x<0)putchar('-'),x=-x;
register short a[20]={},sz=0;
while(x)a[sz++]=x%10,x/=10;
if(sz==0)putchar('0');
for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
string sA="a";
string sB="b";
string sC="c";
int n,A,B,C;
string S;
string dp[52][52][52];
void upd(string &cur,string s,int tlen)
{
if(s.size()==tlen&&s+S+S.substr(0,n-s.size())>=S+S)cur=max(cur,s);
}
bool check()
{
// cerr<<"check:"<<S<<endl;
for(int i=0;i<=A;i++)
{
for(int j=0;j<=B;j++)
{
for(int k=0;k<=C;k++)
{
string &cur=dp[i][j][k];
cur="";
if(i>0)upd(cur,sA+dp[i-1][j][k],i+j+k);
if(j>0)upd(cur,sB+dp[i][j-1][k],i+j+k);
if(k>0)upd(cur,sC+dp[i][j][k-1],i+j+k);
// cerr<<i<<" "<<j<<" "<<k<<":"<<cur<<endl;
}
}
}
return dp[A][B][C].size()==n;
}
int main()
{
cin>>A>>B>>C;
n=A+B+C;
S.resize(n);
for(int i=0;i<n;i++)S[i]='a';
for(int i=0;i<n;i++)
{
for(int j=1;j<3;j++)
{
S[i]='a'+j;
if(!check())
{
S[i]='a'+j-1;
break;
}
}
}
cout<<S<<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 solve(int a, int b, int c) {
bool flag = false;
if (a == 0) {
flag = true;
a = b;
b = c;
c = 0;
}
string res = "";
if (a == 0) {
res = string(b, 'b');
} else {
if (b == 0 && c == 0) {
res = string(a, 'a');
} else {
vector<string> put(a, "a");
for (int i = 0; i < c; i++) {
put[i % a] += 'c';
}
int ptr = c % a;
for (int i = 0; i < b; i++) {
put[ptr] += 'b';
ptr++;
if (ptr == a) {
ptr = c % a;
}
}
map<string, int> mp;
for (auto &s : put) {
mp[s]++;
}
vector< pair<string, int> > v;
for (auto &p : mp) {
v.push_back(p);
}
assert(v.size() <= 3);
while (v.size() < 3) {
v.emplace_back("", 0);
}
string aux = solve(v[0].second, v[1].second, v[2].second);
res = "";
for (int i = 0; i < (int) aux.size(); i++) {
res += v[aux[i] - 'a'].first;
}
}
}
if (flag) {
for (char &c : res) {
c++;
}
}
return res;
}
int main() {
int a, b, c;
scanf("%d %d %d", &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 | 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))
//-------------------------------------------------------
void solve() {
int i,j,k,l,r,x,y; string s;
int A,B,C;
cin>>A>>B>>C;
vector<string> V;
while(A--) V.push_back("a");
while(B--) V.push_back("b");
while(C--) V.push_back("c");
while(V.size()>1) {
sort(ALL(V));
V[0]+=V.back();
V.pop_back();
}
cout<<V[0]<<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 | // 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
multiset<string>s;
signed main()
{
#ifdef M207
freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
#endif
int a,b,c;
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 | #include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
x=0;int _f(0);char ch=getchar();
while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
}
int X,Y,Z;
multiset<string>S;
multiset<string>::iterator it;
string x,y;
int main()
{
file();
read(X),read(Y),read(Z);
For(i,1,X)S.insert("a");
For(i,1,Y)S.insert("b");
For(i,1,Z)S.insert("c");
while(S.size()>1)
{
it=S.begin();
x=*it;S.erase(it);
it=S.end();--it;
y=*it;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 | //minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
struct node{
string s;int c;
inline node(R string ss,R int cc):s(ss),c(cc){}
inline bool operator <(const node &b)const{return s<b.s;}
};set<node>s;
int x,y,z;
int main(){
scanf("%d%d%d",&x,&y,&z);
if(x)s.insert(node("a",x));
if(y)s.insert(node("b",y));
if(z)s.insert(node("c",z));
while(2333){
if(s.size()==1){
node p=*s.begin();
fp(i,1,p.c)cout<<p.s;
puts("");
return 0;
}
R node p=*s.begin(),q=*--s.end();
s.erase(s.begin()),s.erase(--s.end());
R int k=min(p.c,q.c);s.insert(node(p.s+q.s,k));
if(p.c-k)s.insert(node(p.s,p.c-k));
if(q.c-k)s.insert(node(q.s,q.c-k));
}
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() {
int a, b, c;
scanf("%d%d%d", &a, &b, &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);
}
printf("%s\n", 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<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
string solve(vector<string> data, vector<int> cnt) {
if(data.size() == 1) {
string s;
for(int i=0; i<cnt[0]; i++)
s += data[0];
return s;
}
vector<string> base;
for(int i=0; i<cnt[0]; i++) {
base.push_back(data[0]);
}
int pos = 0;
if(data.size() == 3) {
for(int i=0; i<cnt[2]; i++) {
base[i%cnt[0]] += data[2];
}
pos = cnt[2] % cnt[0];
}
for(int i=0; i<cnt[1]; i++) {
base[pos + i % (cnt[0] - pos)] += data[1];
}
vector<string> nextd;
vector<int> nextc;
for(int i=base.size()-1; i>=0; i--) {
if(nextd.size() == 0) {
nextd.push_back(base[i]);
nextc.push_back(1);
continue;
}
if(nextd.back() == base[i]) {
nextc[nextc.size()-1]++;
}
else {
nextd.push_back(base[i]);
nextc.push_back(1);
}
}
return solve(nextd, nextc);
}
int main() {
int a,b,c;
cin >> a >> b >> c;
vector<string> data;
vector<int> val;
if(a!=0) {
data.push_back("a");
val.push_back(a);
}
if(b!=0) {
data.push_back("b");
val.push_back(b);
}
if(c!=0) {
data.push_back("c");
val.push_back(c);
}
string ans = solve(data, val);
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<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int x,y,z;
multiset<string>S;
multiset<string>::iterator it;
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");
while(S.size()>1)
{
it=S.end(); it--;
string ss=(*S.begin())+(*it);
S.erase(S.begin());
S.erase(it);
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<bits/stdc++.h>
using namespace std;
multiset<string> s;
int main(){
//freopen("beargguy.in","r",stdin);
//freopen("beargguy.out","w",stdout);
int r,b,g;
scanf("%d%d%d",&r,&b,&g);
for(int i=1;i<=r;i++){
string a="a";
s.insert(a);
}
for(int i=1;i<=b;i++){
string a="b";
s.insert(a);
}
for(int i=1;i<=g;i++){
string a="c";
s.insert(a);
}
string ans;
while(!s.empty()){
string fir=*s.begin();
s.erase(s.begin());
if(s.empty()){
ans=fir;
break;
}
string las=*(--s.end());
s.erase(--s.end());
if(s.empty()){
ans=fir+las;
break;
}
s.insert(fir+las);
}
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 <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 4005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct node {
string s;int num;
friend bool operator < (const node &a,const node &b) {
return a.s < b.s;
}
};
set<node> S;
int x,y,z;
void Solve() {
read(x);read(y);read(z);
if(x) S.insert((node){"a",x});
if(y) S.insert((node){"b",y});
if(z) S.insert((node){"c",z});
while(1) {
if(S.size() == 1) {
node p = *S.begin();
for(int i = 1 ; i <= p.num ; ++i) {
cout << p.s;
}
enter;
break;
}
node s0 = *S.begin(),t0 = *(--S.end());
S.erase(S.begin());S.erase(--S.end());
int k = min(s0.num,t0.num);
S.insert((node){s0.s + t0.s,k});
if(s0.num > k) S.insert((node){s0.s,s0.num - k});
if(t0.num > k) S.insert((node){t0.s,t0.num - k});
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}
|
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 <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
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) {
string na = A + a + c;
string nb = A + b;
string nc = A + c;
return solve(na, nb, nc, r, y, z - r);
}
else {
string na = A + a + b;
string nb = A + a + c;
string nc = A + b;
return solve(na, nb, nc, 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 | /**
* author: tourist
* created: 08.10.2017 15:50:42
**/
#include <bits/stdc++.h>
using namespace std;
string solve(int a, int b, int c) {
bool flag = false;
if (a == 0) {
flag = true;
a = b;
b = c;
c = 0;
}
string res = "";
if (a == 0) {
res = string(b, 'b');
} else {
if (b == 0 && c == 0) {
res = string(a, 'a');
} else {
vector<string> put(a, "a");
for (int i = 0; i < c; i++) {
put[i % a] += 'c';
}
int ptr = c % a;
for (int i = 0; i < b; i++) {
put[ptr] += 'b';
ptr++;
if (ptr == a) {
ptr = c % a;
}
}
map<string, int> mp;
for (auto &s : put) {
mp[s]++;
}
vector< pair<string, int> > v;
for (auto &p : mp) {
v.push_back(p);
}
assert(v.size() <= 3);
while (v.size() < 3) {
v.emplace_back("", 0);
}
string aux = solve(v[0].second, v[1].second, v[2].second);
res = "";
for (int i = 0; i < (int) aux.size(); i++) {
res += v[aux[i] - 'a'].first;
}
}
}
if (flag) {
for (char &c : res) {
c++;
}
}
return res;
}
int main() {
int a, b, c;
scanf("%d %d %d", &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 | cpp | #include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
string solve(int X,int Y,int Z)
{
//printf("%d %d %d\n",X,Y,Z);
if(Y==0&&Z==0)
{
string ret="";
for(int i=0;i<X;i++) ret+="A";
return ret;
}
if(X==0)
{
string ret=solve(Y,Z,0);
for(int i=0;i<ret.size();i++)
{
if(ret[i]=='A') ret[i]='B';
else ret[i]='C';
}
return ret;
}
else if(Y==0)
{
string ret=solve(X,Z,0);
for(int i=0;i<ret.size();i++) if(ret[i]=='B') ret[i]='C';
return ret;
}
if(Z==0)
{
if(X%Y==0)
{
string ret="";
for(int i=0;i<Y;i++)
{
for(int j=0;j<X/Y;j++) ret+="A";
ret+="B";
}
return ret;
}
string ret=solve(X%Y,Y-(X%Y),0);
string ans="";
for(int i=0;i<ret.size();i++)
{
if(ret[i]=='A')
{
for(int j=0;j<=X/Y;j++) ans+="A";
ans+="B";
}
else
{
for(int j=0;j<X/Y;j++) ans+="A";
ans+="B";
}
}
//printf("%d %d %d : %s\n",X,Y,Z,ans.c_str());
return ans;
}
int z=X%(Y+Z),k=(X+Y+Z-1)/(Y+Z);
if(z==0) z=Y+Z;
if(z<=Z)
{
string ret=solve(z,Y,Z-z);
string ans="";
for(int i=0;i<ret.size();i++)
{
if(ret[i]=='A')
{
for(int j=0;j<k;j++) ans+="A";
ans+="C";
}
else
{
for(int j=0;j<k-1;j++) ans+="A";
ans+=ret[i];
}
}
//printf("%d %d %d : %s\n",X,Y,Z,ans.c_str());
return ans;
}
else
{
string ret=solve(z-Z,Z,Y-(z-Z));
string ans="";
for(int i=0;i<ret.size();i++)
{
if(ret[i]=='C')
{
for(int j=0;j<k-1;j++) ans+="A";
ans+="B";
}
else
{
for(int j=0;j<k;j++) ans+="A";
if(ret[i]=='A') ans+="B";
else ans+="C";
}
}
return ans;
}
return "";
}
int main()
{
int X,Y,Z;
scanf("%d %d %d",&X,&Y,&Z);
string ret=solve(X,Y,Z);
for(int i=0;i<ret.size();i++)
{
if(ret[i]=='A') ret[i]='a';
if(ret[i]=='B') ret[i]='b';
if(ret[i]=='C') ret[i]='c';
}
printf("%s\n",ret.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;
string ans;
int x,y,z;
void dfs(int a,int b,int c,string x,string y,string z)
{
if (a==0) dfs(b,c,0,y,z,"");
else if (c==0&&b==0)
{
for (int i=1;i<=a;i++)
ans+=x;
} else
{
string ra=x,rb,rc;
for (int i=0;i<c/a;i++) ra+=z;
rc=ra+z;
int rrc=c%a;
a-=(c%a);
for (int i=0;i<b/a;i++) ra+=y;
rb=ra+y;
int rrb=b%a;
a-=rrb;
dfs(a,rrb,rrc,ra,rb,rc);
}
}
int main()
{
scanf("%d%d%d",&x,&y,&z);
ans.clear();
dfs(x,y,z,"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<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
multiset<string> s;
int main()
{
int A,B,C;
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-1;i++)
{
string s1,s2;
s1=*s.begin(); s.erase(s.begin());
s2=*(--s.end()); s.erase(--s.end());
s.insert(s1+s2);
}
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;
typedef long long ll;
int x, y, z;
string doit(int d, int e, int f, string x, string y, string z) {
//you have d a's, e b's, and f c's
// cout << d << ' ' << e << ' ' << f << endl;
if (d == 0) {
if (e == 0) {
string t;
for (int i = 0; i < f; ++i)
t += 'c';
return t;
}
string s[e+5];
for (int i = 0; i < e+5; ++i)
s[i] = "";
for (int i = 0; i < e; ++i)
s[i] += 'b';
int ct = 0;
for (int i = 0; i < f; ++i) {
s[ct] += 'c';
ct++;
ct %= e;
}
int c1 = e;
for (int i = 1; i < e; ++i)
if (s[i] != s[i-1])
c1 = i;
string t;
t = doit(0, e-c1, c1, "", s[c1], s[0]);
string ans = "";
for (int i = 0; i < t.length(); ++i) {
if (t[i] == 'b')
ans += s[c1];
else
ans += s[0];
}
return ans;
} else {
string s[d+5];
for (int i = 0; i < d+5; ++i)
s[i] = "";
for (int i = 0; i < d; ++i)
s[i] += 'a';
int ct = 0;
for (int i = 0; i < f; ++i) {
s[ct] += 'c';
ct++;
ct %= d;
}
int ct1 = ct;
for (int i = 0; i < e; ++i) {
s[ct1] += 'b';
ct1++;
if (ct1 >= d)
ct1 = ct;
}
int c1 = d, c2 = d;
for (int i = 1; i < d; ++i) {
if (s[i] != s[i-1]) {
if (c1 == d)
c1 = i;
else
c2 = i;
}
}
string t = doit(d-c2, c2-c1, c1, s[c2], s[c1], s[0]);
string ans = "";
for (int i = 0; i < t.length(); ++i) {
if (t[i] == 'a')
ans += s[c2];
if (t[i] == 'b')
ans += s[c1];
if (t[i] == 'c')
ans += s[0];
}
return ans;
}
}
int main() {
cin >> x >> y >> z;
cout << doit(x, y, z, "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;
multiset<string> s;
int a, b, c;
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");
}
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;
} |
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 <iostream>
#include <set>
using namespace std;
int main() {
int x, y, z; cin >> x >> y >> z;
multiset<string> st;
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) {
auto be = st.begin(), ed = st.end(); ed--;
st.insert(*be + *ed);
st.erase(be), st.erase(ed);
}
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;
int main() {
std::multiset <std::string> M;
int kase;
for (scanf("%d", &kase); kase; --kase) M.insert("a");
for (scanf("%d", &kase); kase; --kase) M.insert("b");
for (scanf("%d", &kase); kase; --kase) M.insert("c");
while (M.size()>1) {
std::string s = *M.begin(), t = *M.rbegin();
M.erase(M.lower_bound(s));
M.erase(M.lower_bound(t));
M.insert(s + t);
}
printf("%s\n", (*M.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;
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int x, y, z;
multiset<string> ms;
int main() {
cin >> x >> y >> z;
rep(i, 0, x) ms.insert("a");
rep(i, 0, y) ms.insert("b");
rep(i, 0, z) ms.insert("c");
while(ms.size() > 1) {
auto itr1 = ms.begin();
auto itr2 = ms.end();
itr2--;
ms.insert(*itr1 + *itr2);
ms.erase(itr1);
ms.erase(itr2);
}
cout << *ms.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 <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;
ll max(ll a, ll b) {
if (a > b) { return a; }
return b;
}
ll min(ll a, ll b) {
if (a > b) { return b; }
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) { return a; }
if (a < b) { return gcd(b, a); }
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
struct edge {
ll ind;
ll fr;
ll to;
ll d;
};
class mint {
long long x;
public:
mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
mint operator-() const {
return mint(-x);
}
mint& operator+=(const mint& a) {
if ((x += a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator-=(const mint& a) {
if ((x += MOD - a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator*=(const mint& a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint& a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint& a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint& a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
// for prime MOD
mint inv() const {
return pow(MOD - 2);
}
mint& operator/=(const mint& a) {
return (*this) *= a.inv();
}
mint operator/(const mint& a) const {
mint res(*this);
return res /= a;
}
friend ostream& operator<<(ostream& os, const mint& m) {
os << m.x;
return os;
}
};
mint pw(mint a, ll b) {
if (b == 0) { return 1; }
mint ret = pw(a, b >> 1);
ret *= ret;
if (b & 1) { ret *= a; }
return ret;
}
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;
/////////////////////////////////////
ll X, Y, Z;
ll M;
bool ch(string s) {
//cout << s << endl;
ll N = s.size();
vvll lis(N+1);
rep(i, N+1) {
//cout << i << endl;
for (ll j = i; j <= N; j++) {
if (s.substr(0, i) > s.substr(j - i, i)) { return false; }
if (s.substr(0, i) == s.substr(j - i, i)) {
lis[j].push_back(i);
//cout << j << " ";
}
}
//cout << endl;
}
vector<vvvll> dp(M + 1, vvvll(N + 1, vvll(X + 1, vll(Y + 1, 0))));
ll xx = X; ll yy = Y;
rep(i, N) {
if (s[i] == 'a') { xx--; }
if (s[i] == 'b') { yy--; }
}
if (xx < 0 || yy < 0||xx+yy>M-N) { return false; }
dp[N][N][xx][yy] = 1;
for (ll i = N; i < M; i++)rep(j, N + 1)rep(x, X + 1)rep(y, Y + 1) {
if (dp[i][j][x][y] == 0) { continue; }
vll d(3,0);
for (ll w : lis[j]) {
if (w == N) { continue; }
rep(k, 3) {
if (s[w] - 'a' > k) { d[k] = -1; }
else if (s[w] - 'a' == k) { d[k] = w + 1; }
}
}
if (d[0] != -1 && x > 0)dp[i + 1][d[0]][x - 1][y] = 1;
if (d[1] != -1 && y > 0) { dp[i + 1][d[1]][x][y - 1] = 1; }
if (d[2] != -1 && i + x + y < M) { dp[i + 1][d[2]][x][y] = 1; }
}
//rep(i, M + 1)rep(j, N + 1)rep(x, X + 1)rep(y, Y + 1) {
// if (dp[i][j][x][y] == 1) { cout << i << j << x << y << endl; }
//}
rep(j, N + 1) {
if (dp[M][j][0][0] == 0) { continue; }
bool b = 1;
rep(k, j + 1) {
string t = s.substr(j - k, k) + s.substr(0, N - k);
if (t < s) { b = 0; }
}
if (b) { return true; }
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> X >> Y >> Z;
M = X + Y + Z;
string s = "";
rep(i, M) {
if (ch(s + 'c')) { s += 'c'; }
else if (ch(s + 'b')) { s += 'b'; }
else if (ch(s + 'a')) { s += 'a'; }
}
cout << 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>
using namespace std;
string solve(int x, int y, int z) {
if (y + z == 0) return string(x, 'a');
if (z + x == 0) return string(y, 'b');
if (x + y == 0) return string(z, 'c');
if (x == 0) {
string nans = solve(y, z, 0);
for (char &c : nans) c += 1;
return nans;
}
if (z == 0) {
string nans = solve(x, 0, y);
for (char &c : nans) if (c == 'c') c = 'b';
return nans;
}
if (x >= z) {
string nans = solve(x - z, z, y);
string ans;
for (char c : nans) {
if (c == 'a') {
ans += 'a';
} else if (c == 'b') {
ans += "ac";
} else {
ans += 'b';
}
}
return ans;
} else {
string nans = solve(x, y, z - x);
string ans;
for (char c : nans) {
if (c == 'a') {
ans += "ac";
} else {
ans += c;
}
}
return ans;
}
}
int main() {
ios_base::sync_with_stdio(false);
int x, y, z;
cin >> x >> y >> z;
cout << solve(x, y, z) << "\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 <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define _int64 long long
int main()
{
int i,j,k,lim,x,y,z,now;
string s,ans;
vector<string> a[2];
scanf("%d%d%d",&x,&y,&z);
a[0].clear();
for (i=0;i<x;i++)
{
s="";
s.push_back('a');
a[0].push_back(s);
}
for (i=0;i<y;i++)
{
s="";
s.push_back('b');
a[0].push_back(s);
}
for (i=0;i<z;i++)
{
s="";
s.push_back('c');
a[0].push_back(s);
}
now=0;
while (a[now].size()>1)
{
sort(a[now].begin(),a[now].end());
s=a[now][0];
//for (i=0;i<a[now].size();i++)
// cout<<a[now][i]<<" ";
//cout<<endl;
for (i=0;i<a[now].size();i++)
if (a[now][i]!=s) break;
if (i==a[now].size()) break;
lim=i;
j=a[now].size()-1;
a[1-now].clear();
for (i=0;i<=j;i++)
{
if ((j>=lim)&&(i<lim))
{
a[1-now].push_back(a[now][i]+a[now][j]);
j--;
}
else
{
a[1-now].push_back(a[now][i]);
}
}
now=1-now;
}
ans="";
for (i=0;i<a[now].size();i++)
ans=ans+a[now][i];
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<bits/stdc++.h>
#define inf 0x7fffffff
#define maxn 10005
#define maxm 120005
typedef long long ll;
using namespace std;
int x, y, z;
multiset<string> Q;
inline int read(){
int x = 0, f = 1;char ch = getchar();
while(ch > '9' || ch < '0'){if(ch == '-') f = -1;ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch -'0';ch = getchar();}
return x * f;
}
int main(){
int i,j,u,v,f;
x = read(), y = read(), z = read();
for(i = 1;i <= x;i++) Q.insert("a");
for(i = 1;i <= y;i++) Q.insert("b");
for(i = 1;i <= z;i++) Q.insert("c");
while(Q.size() > 1){
string a = *Q.begin(), b = *Q.rbegin();
Q.erase(Q.begin()), Q.erase(Q.find(b));
Q.insert(a + b);
}
cout<<*Q.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 <bits/stdc++.h>
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-12;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";
void solve() {
multiset<string> st;
FOR(i, 0, 3) {
int x; cin >> x;
while (x--) {
string s = "";
s += char('a' + i);
st.insert(s);
}
}
while (sz(st) > 1) {
string s = *st.begin();
string t = *st.rbegin();
st.erase(st.find(s));
st.erase(st.find(t));
st.insert(s + t);
}
cout << *st.begin() << "\n";
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int JUDGE_ONLINE = 1;
if (fopen("in.txt", "r")) {
JUDGE_ONLINE = 0;
assert(freopen("in.txt", "r", stdin));
//assert(freopen("out.txt", "w", stdout));
}
solve();
if (!JUDGE_ONLINE) {
cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\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;
const int MX = 1000;
char ans[MX][MX];
void solve2(int x, int y, int p) {
if (x == 0) {
for (int i = 0; i < y; i++) ans[p][i] = 'b';
}
else if (y == 0) {
for (int i = 0; i < x; i++) ans[p][i] = 'a';
}
else if (x >= y) {
int g = (x + y - 1) / y;
int f = x % y;
if (f == 0) f = y;
solve2(f, y - f, p + 1);
for (int i = 0, j = 0; i < y; i++) {
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
if (ans[p + 1][i] == 'a') ans[p][j++] = 'a';
ans[p][j++] = 'b';
}
}
else {
int g = (x + y - 1) / x;
int f = y % x;
if (f == 0) f = x;
solve2(x - f, f, p + 1);
for (int i = 0, j = 0; i < x; i++) {
ans[p][j++] = 'a';
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'b';
if (ans[p + 1][i] == 'b') ans[p][j++] = 'b';
}
}
}
void solve(int x, int y, int z, int p = 0) {
if (x == 0) {
solve2(y, z, p);
for (int i = 0; i < y + z; i++) ans[p][i]++;
}
else if (y == 0) {
solve2(x, z, p);
for (int i = 0; i < x + z; i++)
if (ans[p][i] == 'b')
ans[p][i] = 'c';
}
else if (z == 0) {
solve2(x, y, p);
}
else if (x >= y + z) {
int g = (x + y + z - 1) / (y + z);
int f = x % (y + z);
if (f == 0) f = y + z;
if (z >= f) {
solve(f, y, z - f, p + 1);
for (int i = 0, j = 0; i < y + z; i++) {
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
if (ans[p + 1][i] == 'a') {
ans[p][j++] = 'a';
ans[p][j++] = 'c';
}
else {
ans[p][j++] = ans[p + 1][i];
}
}
}
else {
solve(f - z, z, y + z - f, p + 1);
for (int i = 0, j = 0; i < y + z; i++) {
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
if (ans[p + 1][i] == 'c') {
ans[p][j++] = 'b';
}
else {
ans[p][j++] = 'a';
ans[p][j++] = ans[p + 1][i] + 1;
}
}
}
}
else {
static string S[MX];
for (int i = 0; i < x; i++) S[i] = "a";
for (int i = 0; i < z; i++) S[i % x] += "c";
for (int i = 0; i < y; i++) S[z % x + i % (x - z % x)] += "b";
set<string> strs;
for (int i = 0; i < x; i++) strs.insert(S[i]);
string SS[3];
int cnt[3] = {0, 0, 0}, iter = 0;
for (auto& s : strs) {
SS[iter] = s;
cnt[iter] = 0;
for (int i = 0; i < x; i++) if (S[i] == s) cnt[iter]++;
iter++;
}
solve(cnt[0], cnt[1], cnt[2], p + 1);
for (int i = 0, j = 0; i < x; i++)
for (char c : SS[ans[p + 1][i] - 'a'])
ans[p][j++] = c;
}
}
int main() {
int x, y, z;
ignore = scanf("%d %d %d", &x, &y, &z);
solve(x, y, z);
ans[0][x + y + z] = 0;
printf("%s\n", ans[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>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
typedef v(string) vs;
int main() {
multiset<string> s;
rep(i,3) {
int n;
scanf("%d",&n);
rep(j,n) s.insert(string(1,'a'+i));
}
while (sz(s) > 1) {
auto it = s.end(); --it;
string x = *(s.begin()) + *it;
s.erase(it); s.erase(s.begin());
s.insert(x);
}
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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
public class Main {
static InputStream is;
static PrintWriter out;
static String INPUT = "";
static void solve()
{
int x = ni(), y = ni(), z = ni();
List<String> list = new ArrayList<>();
for(int i = 0;i < x;i++)list.add("a");
for(int i = 0;i < y;i++)list.add("b");
for(int i = 0;i < z;i++)list.add("c");
while(list.size() > 1){
int argmin = 0;
for(int i = 0;i < list.size();i++){
if(list.get(i).compareTo(list.get(argmin)) < 0){
argmin = i;
}
}
String min = list.remove(argmin);
int argmax = 0;
for(int i = 0;i < list.size();i++){
if(list.get(i).compareTo(list.get(argmax)) > 0){
argmax = i;
}
}
String max = list.remove(argmax);
list.add(min+max);
}
out.println(list.get(0));
}
public static void main(String[] args) throws Exception
{
long S = System.currentTimeMillis();
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
solve();
out.flush();
long G = System.currentTimeMillis();
tr(G-S+"ms");
}
private static boolean eof()
{
if(lenbuf == -1)return true;
int lptr = ptrbuf;
while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;
try {
is.mark(1000);
while(true){
int b = is.read();
if(b == -1){
is.reset();
return true;
}else if(!isSpaceChar(b)){
is.reset();
return false;
}
}
} catch (IOException e) {
return true;
}
}
private static byte[] inbuf = new byte[1024];
static int lenbuf = 0, ptrbuf = 0;
private static int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
// private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private static double nd() { return Double.parseDouble(ns()); }
private static char nc() { return (char)skip(); }
private static String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private static char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private static char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
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 int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(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 | cpp | #include<bits/stdc++.h>
using namespace std;
string f(int x, int y, int z, string a, string b, string c) {
//cout << x << ' ' << y << ' ' << z << ' ' << a << ' ' << b << ' ' << c << endl;
if(y == 0 && z == 0) {
string ret;
for(int i = 0; i < x; i++) ret += a;
return ret;
}
if(x == 0) return f(y, z, 0, b, c, a);
if(y == 0 && z) return f(x, z, y, a, c, b);
if(z == 0) {
if(x <= y) {
string na = a;
for(int i = 0; i < y / x; i++) na += b;
return f(x, y % x, 0, na, b, c);
}
else {
string na = a, nb = a + b;
return f(x - y, y, 0, na, nb, c);
}
}
else if(x <= z) {
string na = a + c;
return f(x, y, z - x, na, b, c);
}
else if(x <= y + z) {
string nb = a + c;
return f(x - z, z, y, a, nb, b);
}
else {
string na = a, nb = a + b, nc = a + c;
return f(x - y - z, y, z, na, nb, nc);
}
}
int X, Y, Z;
int main() {
cin >> X >> Y >> Z;
cout << f(X, Y, Z, "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 namespace std;
#define times(n, i) uptil(0, n, i)
#define rtimes(n, i) downto((n) - 1, 0, i)
#define upto(f, t, i) for(int i##_to_ = (t), i = (f); i <= i##_to_; i++)
#define uptil(f, t, i) for(int i##_to_ = (t), i = (f); i < i##_to_; i++)
#define downto(f, t, i) for(int i##_to_ = (t), i = (f); i >= i##_to_; i--)
#define downtil(f, t, i) for(int i##_to_ = (t), i = (f); i > i##_to_; i--)
typedef long double LD;
#define long long long
#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 2
#define _LIBCPP_DEBUG2 2
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '
vector<char> pyon(int x, int y, int z) {
vector<char> ans;
if(!y && !z) {
ans = vector<char>(x, 'a');
} else if(!z && !x) {
ans = vector<char>(y, 'b');
} else if(!x && !y) {
ans = vector<char>(z, 'c');
} else {
bool zoi = !x;
if(zoi) swap(x, y);
ans.reserve(x + y + z);
int p = z / x, s = z % x, q = y / (x - s), t = y % (x - s), u = x - s - t;
for(char c: pyon(u, t, s)) {
ans.push_back(zoi ? 'b' : 'a');
if(c == 'a') {
times(p, o) ans.push_back('c');
times(q, o) ans.push_back('b');
} else if(c == 'b') {
times(p, o) ans.push_back('c');
times(q+1, o) ans.push_back('b');
} else {
times(p+1, o) ans.push_back('c');
}
}
}
if(debug) { cout << x sp << y sp << z tb; for(char c: ans) cout << c; cout ln; }
return ans;
}
signed main() { // long: 64bit
if(!debug) {
cin.tie(0);
ios::sync_with_stdio(0);
}
int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z);
for(char c: pyon(X, Y, Z)) cout << c;
cout ln;
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<string>
int X,Y,Z;
char t[510],s[510];
void dfs(int x,int y,int z,int n){
if(!x&&!y&&!z){
t[n]=0;
bool fl=1;
for(int i=1;i<n&&fl;i++){
int j=0;while(j<n&&t[(i+j)%n]==t[j])j++;
if(j<n&&t[(i+j)%n]<t[j])fl=0;
}
if(fl)for(int i=0;i<=n;i++)s[i]=t[i];
}
else{
if(x)t[n]='a',dfs(x-1,y,z,n+1);
if(y)t[n]='b',dfs(x,y-1,z,n+1);
if(z)t[n]='c',dfs(x,y,z-1,n+1);
}
}
std::string con(int X,int Y,int Z){
std::string S;
if(!X){
if(!Y&&!Z)return S;
S=con(Y,Z,0);
for(int i=0;i<S.length();i++)S[i]++;
return S;
}
if(!Y){
if(!Z){
for(int i=0;i<X;i++)S.push_back('a');
return S;
}
S=con(X,Z,0);
for(int i=0;i<S.length();i++)S[i]=='b'?S[i]='c':1;
return S;
}
if(!Z){
for(int i=1;i<=X;i++){
S.push_back('a');
for(int j=Y*(i-1)/X;j<Y*i/X;j++)S.push_back('b');
}
return S;
}
int t=X-Z%X;
std::string T=con(t-Y%t,Y%t,Z%X);
for(int i=0;i<T.length();i++){
S.push_back('a');
if(T[i]=='a'){
for(int j=0;j<Z/X;j++)S.push_back('c');
for(int j=0;j<Y/t;j++)S.push_back('b');
}
if(T[i]=='b'){
for(int j=0;j<Z/X;j++)S.push_back('c');
for(int j=0;j<Y/t+1;j++)S.push_back('b');
}
if(T[i]=='c'){
for(int j=0;j<Z/X+1;j++)S.push_back('c');
}
}
return S;
}
int main(){
/*
for(X=0;X<=5;X++)
for(Y=0;Y<=8;Y++)
for(Z=0;Z<=8;Z++){
printf("%d,%d,%d: ",X,Y,Z);
dfs(X,Y,Z,0);
for(int i=0,p=0;i<X;i++){
int cs=0;
for(++p;s[p]&&s[p]!='a';p++)if(s[p]=='c')cs++;
printf("%d,",cs);
}
puts(s);
printf("(%d,%d,%d)",X,Y,Z);
puts(con(X,Y,Z).c_str());
if(!X){
printf("(%d,%d,%d)",X,Y,Z);
for(int i=1;i<=Y;i++){
putchar('b');
for(int j=Z*(i-1)/Y;j<Z*i/Y;j++)putchar('c');
}
if(!Y)for(int i=0;i<Z;i++)putchar('c');
puts("");
}
}*/
int X,Y,Z;scanf("%d%d%d",&X,&Y,&Z);
puts(con(X,Y,Z).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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
string slow(int ca, int cb, int cc) {
int n = ca + cb + cc;
string s = "";
for (int i = 0; i < ca; i++) s += 'a';
for (int i = 0; i < cb; i++) s += 'b';
for (int i = 0; i < cc; i++) s += 'c';
string ans = s;
do {
string mn = s;
for (int i = 0; i < n; i++) {
string t = s;
rotate(t.begin(), t.begin() + i, t.end());
mn = min(mn, t);
}
ans = max(ans, mn);
} while (next_permutation(s.begin(), s.end()));
return ans;
}
string lexmin(string s) {
string mn = s;
for (int i = 0; i < (int)s.length(); i++) {
string t = s;
rotate(t.begin(), t.begin() + i, t.end());
mn = min(mn, t);
}
return mn;
}
string solve(vector<string> v) {
sort(v.begin(), v.end());
int n = v.size();
if (v[0] == v[n - 1]) {
string s = "";
for (auto t : v) s += t;
return lexmin(s);
}
map<string, int> mp;
for (auto s : v) mp[s]++;
vector<pair<string, int> > b;
for (auto it : mp) {
b.push_back(it);
}
vector<string> nv;
vector<string> cur(b[0].second, b[0].first);
for (int i = (int)b.size() - 1; i >= 1; i--) {
for (int j = 0; j < b[i].second; j++) {
cur[j % (int)cur.size()] += b[i].first;
}
if (b[i].second % cur.size()) {
int rem = b[i].second % cur.size();
//while (cur.size() > rem) {
for (int l = 0; l < rem; l++) {
nv.push_back(*cur.begin());
//cur.pop_back();
cur.erase(cur.begin());
}
}
}
for (auto s : cur) nv.push_back(s);
return solve(nv);
}
string fast(int ca, int cb, int cc) {
bool f = 0;
if (ca == 0) {
f = 1;
ca = cb;
cb = cc;
cc = 0;
}
if (ca == 0) {
return string(cb, 'c');
}
int n = ca + cb + cc;
vector<string> a(ca, "a");
for (int i = 0; i < cc; i++) {
a[i % ca] += "c";
}
for (int i = 0; i < cb; i++) {
a[(i + cc) % (ca - cc % ca) + cc % ca] += "b";
}
sort(a.begin(), a.end());
string ans = solve(a);
//do {
/*while (1) {
string s = "";
random_shuffle(a.begin(), a.end());
for (string ss : a) s += ss;
string mn = s;
for (int i = 0; i < n; i++) {
string t = s;
rotate(t.begin(), t.begin() + i, t.end());
mn = min(mn, t);
}
ans = max(ans, mn);
if (clock() / (double)CLOCKS_PER_SEC > 1.9) break;
}*/
if (f) {
for (char &c : ans) {
if (c == 'a') c = 'b';
else c = 'c';
}
}
return ans;
}
int main() {
#ifdef HOME
freopen("in", "r", stdin);
#endif
/*int n = 10;
for (int ca = 0; ca <= n; ca++) {
for (int cb = 0; ca + cb <= n; cb++) {
//for (int cc = 0; ca + cb + cc <= n; cc++) {
int cc = n - ca - cb;
string ans1 = fast(ca, cb, cc);
string ans2 = slow(ca, cb, cc);
//string ans2 = ans1;
cout << ca << " " << cb << " " << cc << " " << ans1 << " " << ans2 << endl;
if (ans1 != ans2) {
cout << "FAIL" << endl;
fast(ca, cb, cc);
return 0;
}
}
}
cout << "OK" << endl;*/
int ca, cb, cc;
while (cin >> ca >> cb >> cc) {
cout << fast(ca, cb, cc) << endl;
}
#ifdef HOME
cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
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 <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
using namespace std ;
string trans(string x, string a, string b, string c) {
string ret ;
rep(i, 0, (int) x.length() - 1) {
if (x[i] == 'a') ret += a ;
if (x[i] == 'b') ret += b ;
if (x[i] == 'c') ret += c ;
}
return ret ;
}
void dfs(string a, string b, string c, int x, int y, int z) {
if (!y && !z) {
rep(i, 1, x) cout << a ;
return ;
}
string s[55] ;
rep(i, 1, x) s[i] = 'a' ;
for ( ; z; ) {
for (int i = x; i; -- i) if (z) {
s[i] = s[i] + 'c' ;
-- z ;
}
}
int k = x ;
rep(i, 1, x - 1) if (s[i].length() != s[i + 1].length()) {
k = i ;
break ;
}
for ( ; y; ) {
for (int i = k; i; -- i) if (y) {
s[i] = s[i] + 'b' ;
-- y ;
}
}
int X = 0, Y = 0, Z = 0, d[5] = {0} ;
rep(i, 1, x - 1) if (s[i] != s[i + 1]) {
d[++ d[0]] = i ;
}
d[++ d[0]] = x ;
if (d[0]) X = d[1] ;
if (d[0] > 1) Y = d[2] - d[1] ;
if (d[0] > 2) Z = d[3] - d[2] ;
dfs(trans(s[d[1]], a, b, c), trans(s[d[2]], a, b, c), trans(s[d[3]], a, b, c), X, Y, Z) ;
}
int main() {
int x, y, z ;
string s[55] ;
scanf("%d%d%d", &x, &y, &z) ;
if (!x && !y) {
rep(i, 1, z) printf("%c", 'c') ;
} else
if (!x) {
dfs("b", "c", "a", y, z, x) ;
} else {
dfs("a", "b", "c", x, 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": []
} | IN-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
bmod = B%A
if cmod+bmod<=A:
return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),A-cmod-bmod,bmod,cmod)
else:
return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),bmod,cmod,bmod+cmod-A)
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string f(string s) {
string m(s);
for (int i = 0; i < (s.length()); i++) {
string o;
for (int j = 0; j < (s.length()); j++) o += s[(i + j) % s.length()];
m = min(m, o);
}
return m;
}
int X, Y, Z;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> X >> Y >> Z;
string m = "";
for (int a = 0; a <= X; a++) {
for (int b = 0; b <= Y; b++) {
for (int c = 0; c <= Z; c++) {
if (a + b + c == 0) continue;
if (X >= a && Y >= b && Z >= c) {
} else
continue;
int x = X, y = Y, z = Z;
string pat = "";
for (int _ = 0; _ < (a); _++) pat += 'a';
for (int _ = 0; _ < (c); _++) pat += 'c';
for (int _ = 0; _ < (b); _++) pat += 'b';
string s = "";
int g = 0;
while (x >= a && y >= b && z >= c) {
x -= a, y -= b, z -= c;
s += pat;
g++;
}
if (x >= g || y >= g || z >= g) continue;
string tail = "";
for (int _ = 0; _ < (z); _++) tail += 'c';
for (int _ = 0; _ < (y); _++) tail += 'b';
for (int _ = 0; _ < (x); _++) tail += 'a';
if (tail + s < s + tail) continue;
s += tail;
m = max(m, f(s));
}
}
}
cout << m << "\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": []
} | IN-CORRECT | cpp | #include<cstdio>
int main(){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
int b[x]={};
int c[x]={};
if(x!=0){
if(x>y+z){
for(int i=x-1;i>=x-y;i--){
b[i]++;
}
for(int i=x-y-1;i>=x-y-z;i--){
c[i]++;
}
}else if(x==y+z){
for(int i=x-1;i>=x-z;i--){
c[i]++;
}
for(int i=x-z-1;i>=0;i--){
b[i]++;
}
}else{
if(x<=z){
if(z%x==0){
for(int i=0;i<x;i++){
c[i]+=z/x;
}
for(int i=0;i<x;i++){
b[i]+=y/x;
}
for(int i=x-1;i>=x-y%x;i--){
b[i]++;
}
}else{
for(int i=0;i<x;i++){
c[i]+=z/x;
}
for(int i=x-1;i>=x-z%x;i--){
c[i]++;
}
int k=x-z%x;
for(int i=0;i<k;i++){
b[i]+=y/k;
}
for(int i=0;i<y%k;i--){
b[i]++;
}
}
}else{
for(int i=x-1;i>=x-z;i--){
c[i]++;
}
int k=x-z;
for(int i=0;i<k;i++){
b[i]+=x/k;
}
for(int i=k-1;i>=k-x%k;i--){
b[i]++;
}
}
}
for(int i=0;i<x;i++){
printf("a");
for(int j=0;j<c[i];j++){
printf("c");
}
for(int j=0;j<b[i];j++){
printf("b");
}
}
}else if(y!=0){
if(z==0){
for(int i=0;i<y;i++){
printf("b");
}
}
if(y>z){
for(int i=0;i<z;i++){
printf("c");
for(int j=0;j<y/z;j++){
printf("b");
}
if(i<y%z)printf("c");
}
}else{
for(int i=0;i<z;i++){
printf("c");
if(i<y)printf("b");
}
}
}else{
for(int i=0;i<z;i++){
printf("c");
}
}
printf("\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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int X, Y, Z;
string dp[51][51][51];
int main() {
cin >> X >> Y >> Z;
for (int i = 0; i <= X; i++)
for (int j = 0; j <= Y; j++)
for (int k = 0; k <= Z; k++) {
if (i < X) {
for (int I = 0; I <= i + j + k; I++) {
string now = dp[i][j][k].substr(0, I) + "a" + dp[i][j][k].substr(I);
string ret = now;
for (int J = 1; J < now.size(); J++) {
now = now.substr(1) + now[0];
ret = min(ret, now);
}
dp[i + 1][j][k] = max(dp[i + 1][j][k], ret);
}
}
if (j < Y) {
for (int I = 0; I <= i + j + k; I++) {
string now = dp[i][j][k].substr(0, I) + "b" + dp[i][j][k].substr(I);
string ret = now;
for (int J = 1; J < now.size(); J++) {
now = now.substr(1) + now[0];
ret = min(ret, now);
}
dp[i][j + 1][k] = max(dp[i][j + 1][k], ret);
}
}
if (k < Z) {
for (int I = 0; I <= i + j + k; I++) {
string now = dp[i][j][k].substr(0, I) + "c" + dp[i][j][k].substr(I);
string ret = now;
for (int J = 1; J < now.size(); J++) {
now = now.substr(1) + now[0];
ret = min(ret, now);
}
dp[i][j][k + 1] = max(dp[i][j][k + 1], ret);
}
}
}
cout << dp[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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int read(register int ans = 0, register int sgn = ' ',
register int ch = getchar()) {
for (; ch < '0' || ch > '9'; sgn = ch, ch = getchar())
;
for (; ch >= '0' && ch <= '9'; (ans *= 10) += ch - '0', ch = getchar())
;
return sgn - '-' ? ans : -ans;
}
multiset<string> s;
int X, Y, Z, flag;
string L, T = "\0";
int main() {
X = read(), Y = read(), Z = read();
!X ? !Y ? flag = 2, X = Z : (flag = 1, X = Y, Y = Z), Z = 0 : 0;
for (register int i = 1; i <= X; s.insert("a"), i++)
;
for (register int i = 1; i <= Z; i++)
L = (*s.begin()) + "c", s.erase(s.begin()), s.insert(L);
for (register int i = 1; i <= Y; i++)
L = (*s.begin()) + "b", s.erase(s.begin()), s.insert(L);
for (; s.size() >= 2;
T = T + *s.begin() + *--s.end(), s.erase(s.begin()), s.erase(--s.end()))
;
if (s.size()) T = T + *s.begin();
for (register int i = 0; i < T.length(); T[i] += flag, i++)
;
cerr << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int X, Y, Z;
string f(int x, int y, int z) {
if (x == 0 && y == 0 && z == 0) return "";
if (x == 0) {
string ret = f(y, z, 0);
for (int i = 0; i < ret.size(); i++) ret[i]++;
return ret;
}
string ret;
int q = (x + y + z - 1) / (y + z);
int r = x % (y + z);
if (r == 0) r = y + z;
for (int i = 0; i < q; i++) ret.push_back('a');
for (int i = 0; i < z / r; i++) ret.push_back('c');
for (int i = 0; i < y / (r - z % r); i++) ret.push_back('b');
return ret += f(x - q, y - y / (r - z % r), z - z / r);
}
int main() {
cin >> X >> Y >> Z;
cout << f(X, Y, Z);
}
|
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": []
} | IN-CORRECT | java | import java.io.*;
class Main {
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = new String(in.readLine());
String[] abc = s.split(",");
// 整数の入力
int a = Integer.parseInt(abc[0]);
// スペース区切りの整数の入力
int b = Integer.parseInt(abc[1]);
// スペース区切りの整数の入力
int c = Integer.parseInt(abc[2]);
StringBuilder buff = new StringBuilder();
while(true) {
if(a!=0) {
buff.append("a");
a--;
}else if(c!=0) {
buff.append("c");
}else if(b!=0) {
buff.append("b");
} else {
System.out.println(buff);
return;
}
}
} |
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int x, y, z, tmp;
vector<char> V[55];
int main() {
scanf("%d%d%d", &x, &y, &z);
for (int i = 1; i <= x; i++) {
V[i].push_back('a');
}
tmp = x;
for (int i = z; i >= 1; i--) {
V[tmp--].push_back('c');
if (tmp == 0) tmp = x;
}
tmp = x;
for (int i = y; i >= 1; i--) {
V[tmp--].push_back('b');
if (tmp == 0) tmp = x;
}
for (int i = 1; i <= x; i++) {
for (int j = 0; j < V[i].size(); j++) {
cout << V[i][j];
}
}
cout << 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": []
} | IN-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
bmod = B%(A-cmod)
return work(a+c*(C/A+1),a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),cmod,A-cmod-bmod,bmod)
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string slow(int ca, int cb, int cc) {
int n = ca + cb + cc;
string s = "";
for (int i = 0; i < ca; i++) s += 'a';
for (int i = 0; i < cb; i++) s += 'b';
for (int i = 0; i < cc; i++) s += 'c';
string ans = s;
do {
string mn = s;
for (int i = 0; i < n; i++) {
string t = s;
rotate(t.begin(), t.begin() + i, t.end());
mn = min(mn, t);
}
ans = max(ans, mn);
} while (next_permutation(s.begin(), s.end()));
return ans;
}
string fast(int ca, int cb, int cc) {
bool f = 0;
if (ca == 0) {
f = 1;
ca = cb;
cb = cc;
cc = 0;
}
if (ca == 0) {
return string(cb, 'a');
}
int n = ca + cb + cc;
vector<string> a(ca, "a");
for (int i = 0; i < cc; i++) {
a[i % ca] += "c";
}
for (int i = 0; i < cb; i++) {
a[(i + cc) % (ca - cc % ca) + cc % ca] += "b";
}
sort(a.begin(), a.end());
string ans = "a";
do {
string s = "";
for (string ss : a) s += ss;
string mn = s;
for (int i = 0; i < n; i++) {
string t = s;
rotate(t.begin(), t.begin() + i, t.end());
mn = min(mn, t);
}
ans = max(ans, mn);
if (clock() / (double)CLOCKS_PER_SEC > 1.9) break;
} while (next_permutation(a.begin(), a.end()));
if (f) {
for (char &c : ans) {
if (c == 'a')
c = 'b';
else
c = 'c';
}
}
return ans;
}
int main() {
int ca, cb, cc;
while (cin >> ca >> cb >> cc) {
cout << fast(ca, cb, cc) << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int r, b, g;
multiset<string> s;
int main() {
scanf("%d%d%d", &r, &b, &g);
for (int i = 1; i <= r; i++) s.insert("R");
for (int i = 1; i <= b; i++) s.insert("B");
for (int i = 1; i <= g; i++) s.insert("G");
for (int i = 1; i < r + b + g; i++) {
string a = *s.begin(), b = *(--s.end());
s.erase(s.lower_bound(a)), s.erase(s.lower_bound(b));
s.insert(a + b);
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "sz:" << v.size() << "\n[";
for (const auto& p : v) {
os << p << ",";
}
os << "]\n";
return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
constexpr ll MOD = (ll)1e9 + 7LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;
void place(const int small, const int large, vector<int>& result) {
assert(result.size() == small + large);
if (large == 0) {
for (int i = 0; i < result.size(); i++) {
result[i] = -1;
}
} else if (large == 1) {
for (int i = 0; i < result.size() - 1; i++) {
result[i] = -1;
}
result[result.size() - 1] = 1;
} else if (small >= large) {
const int ssize = (small + large - 1) / large;
const int lsize = ssize - 1;
const int snum = small - (lsize * large);
const int lnum = large - snum;
vector<int> tmp(snum + lnum);
place(snum, lnum, tmp);
int pos = 0;
for (int i = 0; i < tmp.size(); i++) {
if (tmp[i] < 0) {
for (int i = 0; i < ssize; i++) {
result[pos] = -2;
pos++;
}
} else {
for (int i = 0; i < lsize; i++) {
result[pos] = -1;
pos++;
}
}
result[pos] = 1;
pos++;
}
} else {
const int ssize = large / small;
const int lsize = ssize + 1;
const int lnum = large - ssize * small;
const int snum = small - lnum;
vector<int> tmp(snum + lnum);
place(snum, lnum, tmp);
int pos = 0;
for (int i = 0; i < tmp.size(); i++) {
result[pos] = -1;
pos++;
if (tmp[i] < 0) {
for (int i = 0; i < ssize; i++) {
result[pos] = 1;
pos++;
}
} else {
for (int i = 0; i < lsize; i++) {
result[pos] = 2;
pos++;
}
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int X, Y, Z;
cin >> X >> Y >> Z;
string s;
s.resize(X + Y + Z, 'd');
if (X > 0) {
if (Y + Z > 0) {
if (X >= Y + Z) {
assert(false);
vector<int> tmp(X + Y + Z);
place(X, Y + Z, tmp);
for (int i = 0; i < X + Y + Z; i++) {
if (tmp[i] < 0) {
s[i] = 'a';
}
vector<int> smalls;
vector<int> larges;
for (int i = 0; i < tmp.size(); i++) {
if (tmp[i] > 0 and tmp[i - 1] == -1) {
larges.push_back(i);
} else if (tmp[i] > 0 and tmp[i - 1] == -2) {
smalls.push_back(i);
}
}
reverse(smalls.begin(), smalls.end());
for (const int li : larges) {
if (Y > 0) {
s[li] = 'b';
Y--;
} else {
s[li] = 'c';
Z--;
}
}
for (const int si : smalls) {
if (Z > 0) {
s[si] = 'c';
Z--;
} else {
s[si] = 'b';
Y--;
}
}
}
cout << s << endl;
} else {
vector<string> sv(X, "a");
const int slen = Z / X;
const int llen = slen + 1;
const int snum = llen * X - Z;
for (int i = 0; i < snum; i++) {
for (int j = 0; j < slen; j++) {
sv[i].push_back('c');
}
}
for (int i = snum; i < X; i++) {
for (int j = 0; j < llen; j++) {
sv[i].push_back('c');
}
}
const int sslen = Y / snum;
const int lllen = sslen + 1;
const int ssnum = lllen * snum - Y;
for (int i = 0; i < ssnum; i++) {
for (int j = 0; j < sslen; j++) {
sv[i].push_back('b');
}
}
for (int i = ssnum; i < snum; i++) {
for (int j = 0; j < lllen; j++) {
sv[i].push_back('b');
}
}
for (int i = 0; i < X; i++) {
cout << sv[i];
}
cout << endl;
}
} else {
for (int i = 0; i < Y + Z; i++) {
cout << 'a';
}
cout << endl;
return 0;
}
} else {
if (Y > 0) {
if (Z > 0) {
vector<int> tmp(Y + Z);
place(Y, Z, tmp);
for (int i = 0; i < Y + Z; i++) {
if (tmp[i] < 0) {
s[i] = 'b';
} else {
s[i] = 'c';
}
}
cout << s << endl;
return 0;
} else {
for (int i = 0; i < Y; i++) {
cout << 'b';
}
cout << endl;
return 0;
}
} else {
for (int i = 0; i < Z; i++) {
cout << 'c';
}
cout << endl;
return 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-12;
const long double pi = acos(-1.0);
long long mod_pow(long long x, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
struct modint {
long long n;
modint() : n(0) { ; }
modint(long long m) : n(m) {
if (n >= mod)
n %= mod;
else if (n < 0)
n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) {
a.n += b.n;
if (a.n >= mod) a.n -= mod;
return a;
}
modint operator-=(modint& a, modint b) {
a.n -= b.n;
if (a.n < 0) a.n += mod;
return a;
}
modint operator*=(modint& a, modint b) {
a.n = ((long long)a.n * b.n) % mod;
return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0) return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2) res = res * a;
return res;
}
long long inv(long long a, long long p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b) return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
void solve() {
int c[3];
for (int i = 0; i < 3; i++) cin >> c[i];
assert(c[0] > 0);
int num = -1;
for (int i = 1; i <= 50; i++) {
int x = c[0] / i;
if (c[0] % i) x++;
if (x <= c[1] + c[2]) {
num = i;
break;
}
}
vector<string> anss;
for (int i = 0; i < c[0] / num; i++) {
string s;
s.resize(num, 'a');
anss.push_back(s);
}
if (c[0] % num) {
string s;
s.resize(c[0] % num, 'a');
s.push_back('b');
c[1]--;
anss.push_back(s);
}
int d = c[0] / num;
while (c[2] >= d) {
for (int i = 0; i < d; i++) {
anss[i].push_back('c');
}
c[2] -= d;
}
int rest = d;
for (int i = 0; i < c[2]; i++) {
anss[d - 1 - i].push_back('c');
rest--;
}
while (c[1] >= rest) {
for (int i = 0; i < rest; i++) {
anss[i].push_back('b');
}
c[1] -= rest;
}
for (int i = 0; i < c[1]; i++) {
anss[rest - 1 - i].push_back('b');
}
string ans;
for (int i = 0; i < anss.size(); i++) ans += anss[i];
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MX = 1000;
char ans[MX][MX];
void solve2(int x, int y, int p) {
if (x == 0) {
for (int i = 0; i < y; i++) ans[p][i] = 'b';
} else if (y == 0) {
for (int i = 0; i < x; i++) ans[p][i] = 'a';
} else if (x >= y) {
int g = (x + y - 1) / y;
int f = x % y;
if (f == 0) f = y;
solve2(f, y - f, p + 1);
for (int i = 0, j = 0; i < y; i++) {
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
if (ans[p + 1][i] == 'a') ans[p][j++] = 'a';
ans[p][j++] = 'b';
}
} else {
int g = (x + y - 1) / x;
int f = y % x;
if (f == 0) f = x;
solve2(x - f, f, p + 1);
for (int i = 0, j = 0; i < x; i++) {
ans[p][j++] = 'a';
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'b';
if (ans[p + 1][i] == 'b') ans[p][j++] = 'b';
}
}
}
void solve(int x, int y, int z, int p = 0) {
if (x == 0) {
solve2(y, z, p);
for (int i = 0; i < y + z; i++) ans[p][i]++;
} else if (y == 0) {
solve2(x, z, p);
for (int i = 0; i < x + z; i++)
if (ans[p][i] == 'b') ans[p][i] = 'c';
} else if (z == 0) {
solve2(x, y, p);
} else if (x >= y + z) {
int g = (x + y + z - 1) / (y + z);
int f = x % (y + z);
if (f == 0) f = y + z;
if (z >= f) {
solve(f, y, z - f, p + 1);
for (int i = 0, j = 0; i < y + z; i++) {
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
if (ans[p + 1][i] == 'a') {
ans[p][j++] = 'a';
ans[p][j++] = 'c';
} else {
ans[p][j++] = ans[p + 1][i];
}
}
} else {
solve(f - z, z, y + z - f, p + 1);
for (int i = 0, j = 0; i < y + z; i++) {
for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a';
if (ans[p + 1][i] == 'c') {
ans[p][j++] = 'b';
} else {
ans[p][j++] = 'a';
ans[p][j++] = ans[p + 1][i] + 1;
}
}
}
} else {
static string S[MX];
for (int i = 0; i < x; i++) S[i] = "a";
for (int i = 0; i < z; i++) S[i % x] += "c";
for (int i = 0; i < y; i++) S[x - 1 - i % x] += "b";
set<string> strs;
for (int i = 0; i < x; i++) strs.insert(S[i]);
string SS[3];
int cnt[3] = {0, 0, 0}, iter = 0;
for (auto& s : strs) {
SS[iter] = s;
cnt[iter] = 0;
for (int i = 0; i < x; i++)
if (S[i] == s) cnt[iter]++;
iter++;
}
solve(cnt[0], cnt[1], cnt[2], p + 1);
for (int i = 0, j = 0; i < y + z; i++)
for (char c : SS[ans[p + 1][i] - 'a']) ans[p][j++] = c;
}
}
int main() {
int x, y, z;
ignore = scanf("%d %d %d", &x, &y, &z);
solve(x, y, z);
ans[0][x + y + z] = 0;
printf("%s\n", ans[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": []
} | IN-CORRECT | java | import java.io.*;
class Main {
public static void main(String args[]) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s = new String(in.readLine());
String[] abc = s.split(",", 0);
// 整数の入力
int a = Integer.parseInt(abc[0]);
// スペース区切りの整数の入力
int b = Integer.parseInt(abc[1]);
// スペース区切りの整数の入力
int c = Integer.parseInt(abc[2]);
StringBuilder buff = new StringBuilder();
while(true) {
if(a!=0) {
buff.append("a");
a--;
}else if(c!=0) {
buff.append("c");
}else if(b!=0) {
buff.append("b");
} else {
System.out.println(buff);
return;
}
}
} |
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
int rem[55][55][55][55], nxt[55][10], fail[55], T;
bool val[55][55][55][55];
char s[55];
int x, y, z;
bool dfs2(int u, int v, int w, int p) {
if (rem[u][v][w][p] == T) return val[u][v][w][p];
rem[u][v][w][p] = T;
bool &r = val[u][v][w][p];
r = 0;
if (u == 0 && v == 0 && w == 0) return r = 1;
if (u > 0 && s[p] <= 'a') r |= dfs2(u - 1, v, w, nxt[p][0]);
if (r) return 1;
if (v > 0 && s[p] <= 'b') r |= dfs2(u, v - 1, w, nxt[p][1]);
if (r) return 1;
if (w > 0 && s[p] <= 'c') r |= dfs2(u, v, w - 1, nxt[p][2]);
if (r) return 1;
return r = 0;
}
bool checkp(int u, int v, int w, int d) {
s[d] = 0;
for (int i = 0; i < d; i++) {
bool cmp = 0;
for (int j = 0; j < d - i; j++)
if (s[j] != s[i + j]) {
if (s[j] > s[i + j]) cmp = 1;
break;
}
if (cmp) return 0;
}
if (d == 0) return 1;
if (d > 1) nxt[0][s[0] - 'a'] = 1;
for (int i = 1; i < d; i++) {
if (i == 1)
fail[i] = 0;
else
fail[i] = nxt[fail[i - 1]][s[i] - 'a'];
for (int j = 0; j < 3; j++) nxt[i][j] = nxt[fail[i]][j];
if (i + 1 != d) nxt[i][s[i] - 'a'] = i + 1;
}
fail[d] = nxt[fail[d - 1]][s[d] - 'a'];
T++;
return dfs2(u, v, w, fail[d]);
}
bool check(int d) {
for (int i = 0; i < d; i++) {
bool cmp = 0;
for (int j = 0; j < d; j++)
if (s[j] != s[(i + j) % d]) {
if (s[j] > s[(i + j) % d]) cmp = 1;
break;
}
if (cmp) return 0;
}
return 1;
}
void dfs(int u, int v, int w, int d) {
if (!checkp(u, v, w, d)) return;
if (u == 0 && v == 0 && w == 0) {
if (check(d)) {
puts(s);
exit(0);
}
} else {
if (w > 0) s[d] = 'c', dfs(u, v, w - 1, d + 1);
if (v > 0) s[d] = 'b', dfs(u, v - 1, w, d + 1);
if (u > 0) s[d] = 'a', dfs(u - 1, v, w, d + 1);
}
}
int main() {
scanf("%d%d%d", &x, &y, &z);
dfs(x, y, z, 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": []
} | IN-CORRECT | cpp | #include<bits/stdc++.h>
using namespace std;
int main() {
std::multiM <std::string> M;
for (scanf("%d", &i); i; --i) M.insert("a");
for (scanf("%d", &i); i; --i) M.insert("b");
for (scanf("%d", &i); i; --i) M.insert("c");
while (M.size()>1) {
std::string s = *M.begin(), t = *M.rbegin();
M.erase(M.lower_bound(s));
M.erase(M.lower_bound(t));
M.insert(s + t);
}
printf("%s\n", (*M.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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
char s[205];
int a, b, c;
int main() {
scanf("%d%d%d", &a, &b, &c);
for (int i = 0; i < a; i++) s[i] = 'a';
for (int i = a; i < a + b; i++) s[i] = 'b';
for (int i = a + b; i < a + b + c; i++) s[i] = 'c';
for (int l = 0, r = a + b + c - 1; l <= r; l++, r--) {
putchar(s[l]);
if (l != r) putchar(s[r]);
}
}
|
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
os << "[";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << ",";
}
os << "]";
return os;
}
template <typename T>
T input() {
T t;
cin >> t;
return t;
}
template <typename T>
vector<T> input(const int N) {
vector<T> v(N);
for (int i = 0; i < static_cast<int>(N); i++) cin >> v[i];
return v;
}
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int main() {
int X, Y, Z;
cin >> X >> Y >> Z;
string str;
for (int i = 0; i < static_cast<int>(X); i++) {
str += 'a';
}
for (int i = 0; i < static_cast<int>(Y); i++) {
str += 'b';
}
for (int i = 0; i < static_cast<int>(Z); i++) {
str += 'c';
}
string best = str;
string temp;
string temp_small;
do {
temp = str;
temp_small = str;
int size = str.size();
for (int i = 0; i < static_cast<int>(size - 1); i++) {
temp = temp.substr(1, temp.size()) + temp[0];
if (temp < temp_small) {
temp_small = temp;
}
}
if (best < temp_small) {
best = temp_small;
}
} while (next_permutation(str.begin(), str.end()));
cout << best << 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": []
} | IN-CORRECT | java |
import java.util.ArrayList;
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) {
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
multiset<string> st;
int a, b, c;
int main() {
cin >> a >> b >> c;
for (int i = 1; i <= a; i--) {
st.insert("a");
}
for (int i = 1; i <= b; i--) {
st.insert("b");
}
for (int i = 1; i <= c; i--) {
st.insert("c");
}
while ((st.size()) - 1 && st.size()) {
string s = *st.begin(), t = *st.rbegin();
st.erase(st.lower_bound(s));
st.erase(st.lower_bound(t));
st.insert(s + t);
}
printf("%s\n", (*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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
bool check(string s, int a, int b, int c) {
int m = s.size();
int n = a + b + c;
string t;
bool ng = 0;
int len = -1;
bool flag[60] = {};
for (int i = 1; i <= m; i++) {
bool ok = 1;
for (int j = 0; j < (int)(m); ++j) {
if (s[j] != s[j % i]) {
ok = 0;
}
}
if (ok) {
len = i;
break;
}
}
if (len != m) {
string q;
for (int i = 0; i < (int)(len); ++i) {
q.push_back(s[i]);
}
for (int i = 0; i < (int)(7); ++i) {
if (q.size() >= a + b + c) break;
q += q;
}
s = q;
}
m = s.size();
for (int i = 0; i < (int)(n); ++i) {
if (s[i % m] == 'a') {
if (a != 0) {
t.push_back('a');
a--;
} else {
if (b != 0) {
t.push_back('b');
b--;
} else {
t.push_back('c');
c--;
}
}
} else if (s[i % m] == 'b') {
if (b == 0) {
if (c == 0) {
t.push_back('a');
} else {
t.push_back('c');
c--;
}
} else {
t.push_back('b');
b--;
}
} else {
if (c == 0) {
if (b == 0) {
t.push_back('a');
} else {
t.push_back('b');
b--;
}
} else {
t.push_back('c');
c--;
}
}
}
for (int i = 0; i < (int)(n); ++i) {
string p;
for (int j = 0; j < (int)(m); ++j) {
p.push_back(t[(i + j) % n]);
}
if (s > p) return false;
}
return true;
}
int main() {
int a, b, c;
cin >> a >> b >> c;
int n = a + b + c;
string s;
while (s.size() != n) {
string t = s;
t.push_back('c');
if (check(t, a, b, c)) {
s = t;
} else {
t[t.size() - 1] = 'b';
if (check(t, a, b, c)) {
s = t;
} else {
t[t.size() - 1] = 'a';
s = t;
}
}
}
cout << s << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int read(register int ans = 0, register int sgn = ' ',
register int ch = getchar()) {
for (; ch < '0' || ch > '9'; sgn = ch, ch = getchar())
;
for (; ch >= '0' && ch <= '9'; (ans *= 10) += ch - '0', ch = getchar())
;
return sgn - '-' ? ans : -ans;
}
multiset<string> s;
int X, Y, Z;
string L, T = "\0";
int main() {
X = read(), Y = read(), Z = read();
for (register int i = 1; i <= X; s.insert("a"), i++)
;
for (register int i = 1; i <= Y; s.insert("b"), i++)
;
for (register int 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();
cerr << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string f(int x, int y, int z, string a, string b, string c) {
if (y == 0 && z == 0) {
string ret;
for (int i = 0; i < x; i++) ret += a;
return ret;
}
if (x == 0) return f(y, z, 0, b, c, a);
if (y == 0 && z) return f(x, z, y, a, c, b);
if (z == 0) {
if (x <= y) {
string na = a;
for (int i = 0; i < y / x; i++) na += b;
return f(x, y % x, 0, na, b, c);
} else {
string na = a, nb = a + b;
return f(x - y, y, 0, na, nb, c);
}
} else if (x <= y + z) {
string na = a, nb = a;
for (int i = 0; i < z / x; i++) {
na += c;
nb += c;
}
for (int i = 0; i < z % x; i++) nb += c;
return f(x - z % x, z % x, y, na, nb, b);
} else {
string na = a, nb = a + b, nc = a + c;
return f(x - y - z, y, z, na, nb, nc);
}
}
int X, Y, Z;
int main() {
cin >> X >> Y >> Z;
cout << f(X, Y, Z, "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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::abs;
using std::array;
using std::cerr;
using std::cin;
using std::cout;
using std::generate;
using std::make_pair;
using std::map;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::pair;
using std::reverse;
using std::set;
using std::sort;
using std::string;
using std::unique;
using std::vector;
template <typename T>
T input() {
T res;
cin >> res;
{};
return res;
}
template <typename IT>
void input_seq(IT b, IT e) {
std::generate(b, e,
input<typename std::remove_reference<decltype(*b)>::type>);
}
string solve(int a, int b, int c) {
string base = "a";
while (c >= a) base += 'c', c -= a;
while (b >= a) base += 'b', b -= a;
if (b == 0 and c == 0) {
string res = "";
for (int t = 0; t != a; ++t) res += base;
return res;
}
int num = (a + (b + c - 1)) / (b + c);
int free = num * (b + c) - a;
string tmp = "";
for (int i = 0; i != num - 1; ++i) tmp += base;
vector<string> parts;
for (int i = 0; i != (b + c - free); ++i) parts.push_back(tmp + base);
for (int i = 0; i != free; ++i) parts.push_back(tmp);
for (int i = 0; i != c; ++i) parts[i] += 'c';
for (int i = 0; i != b; ++i) parts[c + i] += 'b';
std::sort(parts.begin(), parts.end());
vector<string> cparts = parts;
cparts.resize(std::unique(parts.begin(), parts.end()) - parts.begin());
while (cparts.size() < 3) cparts.push_back("");
assert(int((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;
}
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>();
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';
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
inline int read(register int ans = 0, register int sgn = ' ',
register int ch = getchar()) {
for (; ch < '0' || ch > '9'; sgn = ch, ch = getchar())
;
for (; ch >= '0' && ch <= '9'; (ans *= 10) += ch - '0', ch = getchar())
;
return sgn - '-' ? ans : -ans;
}
multiset<string> s;
int X, Y, Z, flag;
string L, T = "\0";
int main() {
X = read(), Y = read(), Z = read();
!X ? !Y ? flag = 2, X = Z : (flag = 1, X = Y, Y = Z), Z = 0 : 0;
for (register int i = 1; i <= X; s.insert("a"), i++)
;
for (register int i = 1; i <= Z; i++)
L = (*s.begin()) + "c", s.erase(s.begin()), s.insert(L);
for (register int i = 1; i <= Y; i++)
L = (*s.begin()) + "b", s.erase(s.begin()), s.insert(L);
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();
for (register int i = 0; i < T.length(); T[i] += flag, i++)
;
cerr << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
string dp[51][51][51];
void sol(int x, int y, int z) {
if (dp[x][y][z] != "") return;
if (x == 0 && y == 0) {
dp[x][y][z] = string(z, 'c');
return;
}
if (y == 0 && z == 0) {
dp[x][y][z] = string(x, 'a');
return;
}
if (z == 0 && x == 0) {
dp[x][y][z] = string(y, 'b');
return;
}
string res;
using P = pair<string, int>;
vector<P> xs{
{"a", x},
{"b", y},
{"c", z},
};
do {
if (xs[0].second == 0 || xs[1].second == 0) continue;
if (xs[0].first > xs[1].first) continue;
vector<P> v{
{xs[0].second > xs[1].second ? xs[0].first : xs[1].first,
abs(xs[0].second - xs[0].second)},
{xs[0].first + xs[1].first, min(xs[0].second, xs[1].second)},
xs[2],
};
sort((v).begin(), (v).end());
sol(v[0].second, v[1].second, v[2].second);
string &str = dp[v[0].second][v[1].second][v[2].second];
string it;
for (auto &el : str) it += v[el - 'a'].first;
res = max(res, it);
} while (next_permutation((xs).begin(), (xs).end()));
dp[x][y][z] = res;
}
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0);
int x, y, z;
cin >> x >> y >> z;
sol(x, y, z);
cout << dp[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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MX = 300500;
int main(int argc, char** argv) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int x, y, z;
cin >> x >> y >> z;
vector<int> a_pos;
int pos = 0;
int n = x + y + z;
string s;
for (int i = 0; i < n; i++) {
s += "b";
}
while (x--) {
a_pos.push_back(pos);
s[pos] = 'a';
int space_left = n - 1 - pos;
space_left -= x;
space_left /= x + 1;
pos += space_left + 1;
}
for (int j = 0; j < 100; j++) {
for (int i = 0; i < a_pos.size(); i++) {
if (z == 0) break;
s[a_pos[i] + j + 1] = 'c';
z--;
}
}
cout << s << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool smin(T &a, const T &b) {
return a > b ? a = b : a;
}
template <typename T>
inline bool smax(T &a, const T &b) {
return a < b ? a = b : a;
}
const int N = (int)0, mod = (int)0;
int na, nb, nc, n, t[3];
int a[N];
bool check(string p) {
t[0] = na;
t[1] = nb;
t[2] = nc;
int m = (int)p.size();
for (int j = 0; j < m; ++j) {
a[j] = p[j];
for (int ti = 0; ti < 3; ++ti)
if (a[j] == (ti + 'a')) --t[ti];
}
for (int ti = 0; ti < 3; ++ti)
if (t[ti] < 0) return 0;
for (int ch = m; ch < n; ++ch) {
int val = 0;
for (int j = ch - 1; j >= ch - m + 1; --j) {
int flag = 1;
for (int i = j; i < ch; ++i) {
if (p[i - j] < a[i]) {
flag = 0;
break;
}
}
if (flag) val = max(val, p[ch - j] - 'a');
}
int flag = 1;
for (int k = val; k < 3; ++k) {
if (t[k]) {
flag = 0;
--t[k];
a[ch] = k + 'a';
break;
}
}
if (flag) return 0;
}
for (int st = 0; st < n; ++st) {
for (int j = 0; j < m; ++j) {
int pos = (st + j) % n;
if (a[pos] > p[j]) break;
if (a[pos] < p[j]) {
return 0;
}
}
}
return 1;
}
int main() {
cin >> na >> nb >> nc;
n = na + nb + nc;
string res = "";
if (na) {
res = "a";
} else if (nb) {
res = "b";
} else {
res = "c";
}
for (int len = 2; len <= n; ++len) {
for (int c = 2; c >= 0; --c) {
string nxt = res;
nxt += char('a' + c);
if (check(nxt)) {
res = nxt;
break;
}
}
}
cout << res << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f2f1f0f;
const long long LINF = 1ll * INF * INF;
const int MAX_N = 1e2;
int N, Ns[3], Now[MAX_N], Ans[MAX_N], AnsN[3];
int main() {
cin >> Ns[0] >> Ns[1] >> Ns[2];
for (int k = 0; k < 3; k++) N += Ns[k];
for (int k = 0; k < 3; k++) AnsN[k] = Ns[k];
for (int s = 0; s < N; s++) {
bool isFinish = false;
for (int o = 2; o >= 0; o--)
if (isFinish == false && AnsN[o] > 0) {
bool isCan = true;
Ans[s] = o;
int cnt[3];
for (int k = 0; k < 3; k++) cnt[k] = Ns[k];
int en = N / (s + 1) * (s + 1);
for (int p = 0; p < N;) {
bool mustUp = true;
int np = p + (s + 1);
for (int is = 0; is < (s + 1) && p + is < N; is++) {
bool findWell = false;
int start = Ans[is];
if (mustUp == false) start = 0;
for (int k = start; k < 3; k++) {
if (cnt[k] > 0) {
cnt[k]--, Now[p + is] = k;
if (k != Ans[is]) mustUp = false;
findWell = true;
break;
}
}
if (mustUp == false) {
np = p + is + 1;
break;
}
if (findWell == false) isCan = false;
}
if (isCan == false) break;
p = np;
}
if (isCan) {
for (int i = en; i < N; i++) {
for (int j = 0; j < s + 1; j++) {
if (Now[j] < Now[(i + j) % N]) {
break;
} else if (Now[j] > Now[(i + j) % N]) {
isCan = false;
break;
} else
continue;
}
}
}
if (isCan) isFinish = true, AnsN[o]--;
}
}
for (int i = 0; i < N; i++) printf("%c", Ans[i] + 'a');
puts("");
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = 500000004;
const double EPS = 1e-6;
const double PI = acos(-1.0);
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
int C[1100];
int B[1100];
int ad = 0;
vector<string> str;
void f(int a, int b, int c) {
ad = 0;
for (int i = 0; i < 1100; i++) B[i] = C[i] = 0;
while (a == 0) {
a = b;
b = c;
c = 0;
ad++;
}
for (int i = 0; i < c; i++) {
C[i % a]++;
}
if (C[0] != C[a - 1]) {
int f = 0;
for (int i = 0; i < a; i++)
if (C[a - 1] == C[i]) f++;
for (int i = 0; i < b; i++) {
B[a - f + i % f]++;
}
} else {
for (int i = 0; i < b; i++) {
B[i % a]++;
}
}
str.clear();
for (int i = a - 1; i >= 0; i--) {
string tmp = "";
tmp += 'a' + ad;
for (int j = 0; j < C[i]; j++) tmp += 'c' + ad;
for (int j = 0; j < B[i]; j++) tmp += 'b' + ad;
str.push_back(tmp);
}
for (int i = 0; i < a; i++)
for (int j = 0; j < a - 1; j++) {
if (str[j] + str[j + 1] < str[j + 1] + str[j]) swap(str[j + 1], str[j]);
}
for (int i = 0; i < a; i++) printf("%s", str[i].c_str());
printf("\n");
}
int main() {
for (int i = 0; i < 100; i++) {
int a = rand() % 10;
int b = rand() % 10;
int c = rand() % 10;
if (a + b + c == 0) continue;
printf("%d %d %d: ", a, b, c);
f(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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int a, b, c;
cin >> a >> b >> c;
int maxa = max(a, max(b, c));
for (int i = 0; i < maxa; i++) {
if (a > 0) {
cout << 'a';
a--;
}
if (c > 0) {
cout << 'c';
c--;
}
if (b > 0) {
cout << 'b';
b--;
}
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int X, Y, Z;
string ans;
int main() {
cin >> X >> Y >> Z;
ans = "";
for (int i = 0; i < X; i++) ans += 'a';
for (int i = 0; i < Y; i++) {
string nxt = " ";
for (int j = 0; j <= ans.size(); j++) {
string now = ans.substr(0, j) + "b" + ans.substr(j);
string ret = now;
for (int k = 1; k < now.size(); k++) {
now = now.substr(1) + now[0];
ret = min(ret, now);
}
if (nxt < ret) nxt = ret;
}
ans = nxt;
}
for (int i = 0; i < Z; i++) {
string nxt = " ";
for (int j = 0; j <= ans.size(); j++) {
string now = ans.substr(0, j) + "c" + ans.substr(j);
string ret = now;
for (int k = 1; k < now.size(); k++) {
now = now.substr(1) + now[0];
ret = min(ret, now);
}
if (nxt < ret) nxt = ret;
}
ans = nxt;
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
string F(int X, string A) {
string S = "";
while (X--) S += A;
return S;
}
string F(int X, string A, int Y, string B) {
if (!X) return F(Y, B);
if (!Y) return F(X, A);
if (X > Y) {
int x = X / Y;
string a = F(x, A) + B, b = F(x + 1, A) + B;
int y = X - x * Y;
x = Y - y;
return F(y, b, x, a);
} else {
int x = Y / X;
string a = A + F(x, B), b = A + F(x + 1, B);
int y = Y - x * X;
x = X - y;
return F(x, a, y, b);
}
}
string F(int X, string A, int Y, string B, int Z, string C) {
if (!X) return F(Y, B, Z, C);
if (!Y) return F(X, A, Z, C);
if (!Z) return F(X, A, Y, B);
if (X > Y + Z) {
int x = X / (Y + Z), y = X - x * (Y + Z);
if (y >= Z) {
string a = F(x, A) + B, b = F(x + 1, A) + B, c = F(x + 1, A) + C;
int z = Z;
x = Y + Z - y;
y -= z;
return F(y, b, z, c, x, a);
} else {
string a = F(x, A) + B, b = F(x, A) + C, c = F(x + 1, A) + C;
int z = y;
y = Z - z;
x = Y;
return F(z, c, x, a, y, b);
}
}
if (Z > Y) {
int x = Z / Y;
string a = A + F(x, C) + B, b = A + F(x + 1, C) + B;
int y = Z - x * Y;
x = Y - y;
return F(y, b, x, a);
} else {
int x = Y / Z;
string a = A + C + F(x, B), b = A + C + F(x + 1, B);
int y = Y - x * Z;
x = Z - y;
return F(x, a, y, b);
}
}
int main() {
int X, Y, Z;
cin >> X >> Y >> Z;
cout << F(X, "a", Y, "b", Z, "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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f2f1f0f;
const long long LINF = 1ll * INF * INF;
const int MAX_N = 1e2;
int N, Ns[3], Now[MAX_N], Ans[MAX_N], AnsN[3];
int main() {
cin >> Ns[0] >> Ns[1] >> Ns[2];
for (int k = 0; k < 3; k++) N += Ns[k];
for (int k = 0; k < 3; k++) AnsN[k] = Ns[k];
for (int s = 0; s < N; s++) {
bool isFinish = false;
for (int o = 2; o >= 0; o--)
if (isFinish == false && AnsN[o] > 0) {
bool isCan = true;
Ans[s] = o;
int cnt[3];
for (int k = 0; k < 3; k++) cnt[k] = Ns[k];
int en = N / (s + 1) * (s + 1);
for (int p = 0; p < N; p += (s + 1)) {
bool mustUp = true;
for (int is = 0; is < (s + 1) && p + is < N; is++) {
bool findWell = false;
int start = Ans[is];
if (mustUp == false) start = 0;
for (int k = start; k < 3; k++) {
if (cnt[k] > 0) {
cnt[k]--, Now[p + is] = k;
if (k != Ans[is]) mustUp = false;
findWell = true;
break;
}
}
if (findWell == false) isCan = false;
}
if (isCan == false) break;
}
if (isCan) {
for (int i = en; i < N; i++) {
for (int j = 0; j < s + 1; j++) {
if (Now[j] < Now[(i + j) % N]) {
break;
} else if (Now[j] > Now[(i + j) % N]) {
isCan = false;
break;
} else
continue;
}
}
}
if (isCan) isFinish = true, AnsN[o]--;
}
}
for (int i = 0; i < N; i++) printf("%c", Ans[i] + 'a');
puts("");
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": []
} | IN-CORRECT | UNKNOWN | ary = gets.chomp.split(" ").map(&:to_i)
a = ary[0]
b = ary[1]
c = ary[2]
if a > 0
list = []
bb = b/a
ba = b%a
cc = c/a
ca = c%a
a.times do |i|
list.push("c"*cc+"b"*bb)
end
ba.times do |i|
list[i] = list[i]+"b"
end
if ca > 0
[ca,a-ba].min.times do |i|
list[ba+i] = "c"+list[ba+i]
end
if ca > (a-ba)
(ca -(a-ba)).times do |i|
list[i] = "c"+list[i]
end
end
end
str = "a"+list.join("a")
elsif b>0
cc = c/b
cb = c%b
list = []
b.times do |i|
list.push("c"*cc)
end
cb.times do |i|
list[i] = list[i]+"c"
end
str = "b"+list.join("b")
else
str = "c"*c
end
puts 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
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) {
bool found = false;
for (int i = 0; i < N; ++i) {
string nxt = ans;
swap(nxt[i], nxt[(i + 1) % N]);
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int A, B, C;
vector<string> vec;
string maxn = "";
void dfs(vector<string> V, string S) {
if (V.size() == 0) {
string G = S;
for (int i = 0; i < S.size(); i++) {
string I = "";
for (int j = 0; j < S.size(); j++) I += S[(i + j) % S.size()];
G = min(G, I);
}
maxn = max(maxn, G);
return;
}
for (int i = 0; i < V.size(); i++) {
if (i >= 1 && V[i] == V[i - 1]) continue;
vector<string> Z;
for (int j = 0; j < V.size(); j++) {
if (i != j) Z.push_back(V[j]);
}
string ZZ = S + V[i];
dfs(Z, ZZ);
}
}
int main() {
cin >> A >> B >> C;
int P = 0;
while (A == 0) {
A = B;
B = C;
C = 0;
P++;
}
for (int i = 0; i < A; i++) vec.push_back("a");
for (int i = 0; i < C; i++) vec[i % A] += "c";
sort(vec.begin(), vec.end());
int Z = 1;
for (int i = 0; i < (int)vec.size() - 1; i++) {
if (vec[i] == vec[i + 1])
Z = i + 2;
else
break;
}
for (int i = 0; i < B; i++) vec[i % Z] += "b";
sort(vec.begin(), vec.end());
dfs(vec, "");
for (int i = 0; i < maxn.size(); i++) maxn[i] += P;
cout << maxn << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int a, b, c;
string min(string a, string b) {
if ((int)a.size() < (int)b.size()) return a;
if ((int)a.size() > (int)b.size()) return b;
if (a == b) return a;
if (a < b)
return a;
else
return b;
}
string F(string &s) {
string tmp = "";
string ss = "";
string ret = "";
for (int i = 0; i < 50; i++) {
ret += "Z";
}
for (int i = 0; i < (int)s.size(); i++) {
ss += s[i];
tmp = s.substr(i + 1, (int)s.size() - i - 1);
tmp += ss;
ret = min(ret, tmp);
}
return ret;
}
vector<string> V;
struct node {
int A, B, C;
string S;
node() {}
node(int _A, int _B, int _C, string _tmp) {
A = _A;
B = _B;
C = _C;
S = _tmp;
}
bool operator<(const node &a) const {
if (A == a.A) {
if (B == a.B) {
if (C == a.C) {
return S < a.S;
}
return C < a.C;
}
return B < a.B;
}
return A < a.A;
}
};
map<node, bool> dp;
void rek(int A, int B, int C, string tmp) {
if (dp.find(node(A, B, C, tmp)) != dp.end()) return;
if (A == 0 and B == 0 and C == 0) {
V.push_back(F(tmp));
return;
}
if (A - 1 >= 0) {
rek(A - 1, B, C, tmp + "a");
}
if (B - 1 >= 0) {
rek(A, B - 1, C, tmp + "b");
}
if (C - 1 >= 0) {
rek(A, B, C - 1, tmp + "c");
}
dp[node(A, B, C, tmp)] = true;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> a >> b >> c;
V.clear();
rek(a, b, c, "");
sort(V.begin(), V.end());
cout << V[(int)V.size() - 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int cnt[3];
int sm = 0;
int st = -1;
for (int i = 0; i < 3; i++) {
cin >> cnt[i];
if (cnt[i] && st == -1) st = cnt[i];
sm += cnt[i];
}
string seg[55];
string ans;
for (int segn = st; segn <= st; segn++) {
deque<char> deq;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < cnt[i]; j++) {
deq.push_back('a' + i);
}
}
for (int i = 1; i <= segn; i++) {
seg[i].clear();
}
for (int i = 1; i <= segn; i++) {
seg[i] += deq.front();
deq.pop_front();
}
int cur = segn;
int dir = -1;
while (deq.size()) {
seg[cur] += deq.back();
deq.pop_back();
if (dir == 1) {
if (++cur == segn + 1) {
dir = -1;
cur -= 2;
}
} else {
if (--cur == 0) {
dir = 1;
cur += 2;
}
}
}
string cand;
for (int i = 1; i <= segn; i++) {
cand += seg[i];
}
if (cand > ans) ans = cand;
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
string dp[51][51][51];
void sol(int x, int y, int z) {
if (dp[x][y][z] != "") return;
if (x == 0 && y == 0) {
dp[x][y][z] = string(z, 'c');
return;
}
if (y == 0 && z == 0) {
dp[x][y][z] = string(x, 'a');
return;
}
if (z == 0 && x == 0) {
dp[x][y][z] = string(y, 'b');
return;
}
string res;
using P = pair<string, int>;
vector<P> xs{
{"a", x},
{"b", y},
{"c", z},
};
do {
if (xs[0].second == 0 || xs[1].second == 0) continue;
if (xs[0].first > xs[1].first) continue;
vector<P> v{
{xs[0].second > xs[1].second ? xs[0].first : xs[1].first,
abs(xs[0].second - xs[1].second)},
{xs[0].first + xs[1].first, min(xs[0].second, xs[1].second)},
xs[2],
};
sort((v).begin(), (v).end());
sol(v[0].second, v[1].second, v[2].second);
string &str = dp[v[0].second][v[1].second][v[2].second];
string it;
for (auto &el : str) it += v[el - 'a'].first;
res = max(res, it);
} while (next_permutation((xs).begin(), (xs).end()));
dp[x][y][z] = res;
}
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0);
int x, y, z;
cin >> x >> y >> z;
sol(x, y, z);
cout << dp[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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
template <typename... As>
struct tpl : public std::tuple<As...> {
using std::tuple<As...>::tuple;
tpl() {}
tpl(std::tuple<As...> const& b) { std::tuple<As...>::operator=(b); }
template <typename T = tuple<As...>>
typename tuple_element<0, T>::type const& x() const {
return get<0>(*this);
}
template <typename T = tuple<As...>>
typename tuple_element<0, T>::type& x() {
return get<0>(*this);
}
template <typename T = tuple<As...>>
typename tuple_element<1, T>::type const& y() const {
return get<1>(*this);
}
template <typename T = tuple<As...>>
typename tuple_element<1, T>::type& y() {
return get<1>(*this);
}
template <typename T = tuple<As...>>
typename tuple_element<2, T>::type const& z() const {
return get<2>(*this);
}
template <typename T = tuple<As...>>
typename tuple_element<2, T>::type& z() {
return get<2>(*this);
}
template <typename T = tuple<As...>>
typename tuple_element<3, T>::type const& w() const {
return get<3>(*this);
}
template <typename T = tuple<As...>>
typename tuple_element<3, T>::type& w() {
return get<3>(*this);
}
};
using lli = long long int;
using llu = long long unsigned;
using pii = tpl<lli, lli>;
using piii = tpl<lli, lli, lli>;
using piiii = tpl<lli, lli, lli, lli>;
using vi = vector<lli>;
using vii = vector<pii>;
using viii = vector<piii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
using vviii = vector<viii>;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_queue = priority_queue<T>;
template <size_t... I>
struct my_index_sequence {
using type = my_index_sequence;
static constexpr array<size_t, sizeof...(I)> value = {{I...}};
};
namespace my_index_sequence_detail {
template <typename I, typename J>
struct concat;
template <size_t... I, size_t... J>
struct concat<my_index_sequence<I...>, my_index_sequence<J...>>
: my_index_sequence<I..., (sizeof...(I) + J)...> {};
template <size_t N>
struct make_index_sequence
: concat<typename make_index_sequence<N / 2>::type,
typename make_index_sequence<N - N / 2>::type>::type {};
template <>
struct make_index_sequence<0> : my_index_sequence<> {};
template <>
struct make_index_sequence<1> : my_index_sequence<0> {};
} // namespace my_index_sequence_detail
template <class... A>
using my_index_sequence_for =
typename my_index_sequence_detail::make_index_sequence<sizeof...(A)>::type;
template <class T, size_t... I>
void print_tuple(ostream& s, T const& a, my_index_sequence<I...>) {
using swallow = int[];
(void)swallow{0, (void(s << (I == 0 ? "" : ", ") << get<I>(a)), 0)...};
}
template <class T>
ostream& print_collection(ostream& s, T const& a);
template <class... A>
ostream& operator<<(ostream& s, tpl<A...> const& a);
template <class... A>
ostream& operator<<(ostream& s, tuple<A...> const& a);
template <class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a);
template <class T, size_t I>
ostream& operator<<(ostream& s, array<T, I> const& a) {
return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, vector<T> const& a) {
return print_collection(s, a);
}
template <class T, class U>
ostream& operator<<(ostream& s, multimap<T, U> const& a) {
return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, multiset<T> const& a) {
return print_collection(s, a);
}
template <class T, class U>
ostream& operator<<(ostream& s, map<T, U> const& a) {
return print_collection(s, a);
}
template <class T>
ostream& operator<<(ostream& s, set<T> const& a) {
return print_collection(s, a);
}
template <class T>
ostream& print_collection(ostream& s, T const& a) {
s << '[';
for (auto it = begin(a); it != end(a); ++it) {
s << *it;
if (it != prev(end(a))) s << " ";
}
return s << ']';
}
template <class... A>
ostream& operator<<(ostream& s, tpl<A...> const& a) {
s << '(';
print_tuple(s, a, my_index_sequence_for<A...>{});
return s << ')';
}
template <class... A>
ostream& operator<<(ostream& s, tuple<A...> const& a) {
s << '(';
print_tuple(s, a, my_index_sequence_for<A...>{});
return s << ')';
}
template <class A, class B>
ostream& operator<<(ostream& s, pair<A, B> const& a) {
return s << "(" << get<0>(a) << ", " << get<1>(a) << ")";
}
vi redcnt(vi cnt) {
vi cnt2;
for (int i : cnt)
if (i) cnt2.push_back(i);
return cnt2;
}
vi solve_(vi);
vi solve(vi cnt) {
map<int, int> trans;
vi cnt2;
for (lli i = 0; i < (lli)(cnt.size()); ++i) {
if (cnt[i]) {
trans[cnt2.size()] = i;
cnt2.push_back(cnt[i]);
}
}
vi r = solve_(cnt2);
vi r2;
for (int i : r) r2.push_back(trans[i]);
return r2;
}
vi solve_(vi cnt) {
if (cnt.size() == 1) {
vi r;
for (lli i = 0; i < (lli)(cnt[0]); ++i) r.push_back(0);
return r;
}
int k = 1;
while (1) {
int nx = (cnt[0] + k - 1) / k;
int x1 = cnt[0] % nx;
if (x1 == 0) x1 = nx;
int x2 = nx - x1;
map<vi, lli> make_pair;
for (lli j = (cnt.size() - 1); j >= (lli)(1); --j) {
vi base1;
for (lli k_ = 0; k_ < (lli)(k); ++k_) base1.push_back(0);
base1.push_back(j);
vi base2;
for (lli k_ = 0; k_ < (lli)(k - 1); ++k_) base2.push_back(0);
base2.push_back(j);
lli cc = cnt[j];
while (cc && x1) {
cc--;
x1--;
make_pair[base1]++;
}
while (cc && x2) {
cc--;
x2--;
make_pair[base2]++;
}
while (cc) {
cc--;
make_pair[{j}]++;
}
}
if (x1 == 0 && x2 == 0) {
vector<tpl<vi, lli>> mp_;
for (auto p : make_pair) mp_.push_back(make_tuple(p.first, p.second));
vi cnt2;
for (auto p : mp_) cnt2.push_back(p.y());
vi r = solve(cnt2);
vi ans;
for (int i : r) ans.insert(end(ans), begin(mp_[i].x()), end(mp_[i].x()));
return ans;
}
k += 1;
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
lli x, y, z;
cin >> x >> y >> z;
vi r = solve({x, y, z});
string s;
for (int i : r) s += 'a' + i;
cout << s << 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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int A, B, C;
vector<string> vec;
string maxn = "";
void dfs(vector<string> V, string S) {
if (V.size() == 0) {
string G = S;
for (int i = 0; i < S.size(); i++) {
string I = "";
for (int j = 0; j < S.size(); j++) I += S[(i + j) % S.size()];
G = min(G, I);
}
maxn = max(maxn, G);
return;
}
for (int i = 0; i < V.size(); i++) {
if (i >= 1 && V[i] == V[i - 1]) continue;
vector<string> Z;
for (int j = 0; j < V.size(); j++) {
if (i != j) Z.push_back(V[j]);
}
string ZZ = S + V[i];
dfs(Z, ZZ);
}
}
int main() {
cin >> A >> B >> C;
while (A == 0) {
A = B;
B = C;
C = 0;
}
for (int i = 0; i < A; i++) vec.push_back("a");
for (int i = 0; i < C; i++) vec[i % A] += "c";
sort(vec.begin(), vec.end());
int Z = 0;
for (int i = 0; i < vec.size() - 1; i++) {
if (vec[i] == vec[i + 1]) Z = i + 2;
}
for (int i = 0; i < B; i++) vec[i % B] += "b";
sort(vec.begin(), vec.end());
dfs(vec, "");
cout << maxn << 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": []
} | IN-CORRECT | python3 | from itertools import permutations,count,chain
from collections import deque
def helper(s):
for i in range(len(s)):
yield s[i:]+s[:i]
def naive(a,b,c):
return max(min(helper(s)) for s in permutations('a'*a+'b'*b+'c'*c))
def solve(a,b,c):
def helper(a,b,c):
cnt = (a,b,c).count(0)
if cnt == 3:
return []
elif cnt == 2:
n,i = max((x,i) for i,x in enumerate((a,b,c)))
return [i]*n
elif cnt == 1:
(l,nl),(u,nu) = ((i,x) for i,x in enumerate((a,b,c)) if x != 0)
n = nl//nu
return tuple(reversed(([u]+[l]*n)*nu + [l]*(nl-n*nu)))
n0 = c%a
n1 = a - n0
m0 = b%n1
m1 = n1-m0
R = helper(m1,m0,n0)
nc = c//a
nb = b//n1
s = ([0] + [2]*nc + [1]*nb, [0] + [2]*nc + [1]*(nb+1), [0] + [2]*(nc+1))
return tuple(chain.from_iterable(s[r] for r in R))
s = ('a','b','c')
return ''.join(s[i] for i in helper(a,b,c))
print(solve(*map(int,input().split()))) |
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct dice {
mt19937 mt;
dice() {
random_device rd;
mt = mt19937(rd());
}
int operator()(int x) { return this->operator()(0, x - 1); }
int operator()(int x, int y) {
uniform_int_distribution<int> dist(x, y);
return dist(mt);
}
} dc;
string f(string s) {
int N = s.length();
string mi = "z";
for (int t = 0; t < N; t++) {
mi = min(mi, s);
rotate(s.begin(), s.begin() + 1, s.end());
}
return mi;
}
int main() {
int A, B, C;
cin >> A >> B >> C;
string s;
for (int t = 0; t < A; t++) s.push_back('a');
for (int t = 0; t < B; t++) s.push_back('b');
for (int t = 0; t < C; t++) s.push_back('c');
shuffle(s.begin(), s.end(), dc.mt);
int N = s.length();
string ma = f(s);
for (int t = 0; t < 500000; t++) {
int i = dc(N), j = dc(N);
swap(s[i], s[j]);
string mi = f(s);
if (mi < ma)
swap(s[i], s[j]);
else
ma = mi;
}
cout << ma << 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": []
} | IN-CORRECT | UNKNOWN | ($X,$Y,$Z)=glob<>;
$s='a'x$X.'B'x$Y.'C'x$Z;
while($p=$s,$s=~s/^(a*)a?\K(\1.*)([BC])/\l$3$2/){
$t=$s;
for(1..length$s){
$t=~s/(.)(.*)/$2$1/;
if(lc$t lt lc$s){
$s=$t
}
}
if(lc$p gt lc$s){
$s=$p;
last
}
}
print lc$s
|
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z;
vector<char> at[100];
int l = 0;
scanf("%d %d %d", &x, &y, &z);
if (x > y + z && y + z > 0) {
for (int i = (long long int)0; i < y + z; i++) {
at[i % (y + z)].push_back('a');
}
for (int i = (long long int)0; i < z; i++) {
at[i].push_back('c');
}
for (int i = (long long int)0; i < y; i++) {
at[i + z].push_back('b');
}
l = y + z;
} else if (x > 0) {
for (int i = (long long int)0; i < x; i++) {
at[i].push_back('a');
}
for (int i = (long long int)0; i < z; i++) {
at[i % x].push_back('c');
}
for (int i = (long long int)0; i < y; i++) {
at[(i + z) % x].push_back('b');
}
l = x;
} else if (y > 0) {
for (int i = (long long int)0; i < y; i++) {
at[i].push_back('b');
}
for (int i = (long long int)0; i < z; i++) {
at[i % y].push_back('c');
}
l = y;
} else {
for (int i = (long long int)0; i < z; i++) {
at[i].push_back('c');
}
l = z;
}
for (int i = (long long int)0; i < l; i++) {
if (i % 2 == 0) {
for (int j = (long long int)0; j < at[l - 1 - i / 2].size(); j++) {
printf("%c", at[l - 1 - i / 2][j]);
}
} else {
for (int j = (long long int)0; j < at[i / 2].size(); j++) {
printf("%c", at[i / 2][j]);
}
}
}
printf("\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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using namespace std;
int n;
int x, y, z;
string ans;
bool check(string s) {
int rem[3] = {x, y, z};
int p = 0;
for (int i = 0; i < n; i++) {
int c = s[p] - 'a', f = -1;
for (int j = c; j < 3; j++) {
if (rem[j]) {
rem[j]--;
f = j;
break;
}
}
if (f == -1) return false;
if (f > c) {
s[p] = (char)('a' + f);
s.erase(s.begin() + p + 1, s.end());
}
p++;
if (p >= s.size()) p = 0;
}
return p == 0;
}
int main(void) {
cin >> x >> y >> z;
n = x + y + z;
for (int i = 0; i < n; i++) {
for (int j = 2; j >= 0; j--) {
string s = ans + ((char)('a' + j));
if (check(s)) {
ans = s;
break;
}
}
}
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": []
} | IN-CORRECT | cpp | #include <bits/stdc++.h>
using std::abs;
using std::array;
using std::cerr;
using std::cin;
using std::cout;
using std::generate;
using std::make_pair;
using std::map;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::pair;
using std::reverse;
using std::set;
using std::sort;
using std::string;
using std::unique;
using std::vector;
template <typename T>
T input() {
T res;
cin >> res;
{};
return res;
}
template <typename IT>
void input_seq(IT b, IT e) {
std::generate(b, e,
input<typename std::remove_reference<decltype(*b)>::type>);
}
bool dfs(const vector<vector<int>>& graph, vector<char>& type, int v) {
for (int u : graph[v])
if (type[u] == 0) {
type[u] = 3 - type[v];
if (not dfs(graph, type, u)) return false;
} else if (type[u] == type[v]) {
return false;
}
return true;
}
int main() {
std::iostream::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n = input<int>();
int m = input<int>();
vector<vector<int>> graph(n);
for (int i = 0; i != m; ++i) {
int v = input<int>() - 1;
int u = input<int>() - 1;
graph[v].push_back(u);
graph[u].push_back(v);
}
vector<char> type(n, 0);
type[0] = 1;
bool bip = dfs(graph, type, 0);
if (bip) {
int num[2] = {0, 0};
for (int i = 0; i != n; ++i) num[type[i] - 1] += 1;
cout << num[0] * int64_t(num[1]) - m << "\n";
} else {
cout << n * int64_t(n - 1) / 2 - m << "\n";
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.