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": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 55; string res; bool vis[maxn][maxn][maxn][maxn]; int failure[maxn]; void push() { memset(failure, 0, sizeof(failure)); for (int s = 2; s <= res.size(); s++) { failure[s] = failure[s - 1]; while (failure[s] > 0 && res[failure[s]] != res[s - 1]) failure[s] = failure[failure[s]]; if (res[failure[s]] == res[s - 1]) ++failure[s]; } } bool solve(int qx, int qy, int qz, int pos) { if (qx + qy + qz == 0) { string pref; for (int e = 0; e < pos; e++) pref.push_back(res[e]); pref += res; for (int f = 0; f < pref.size() - res.size() + 1; f++) { bool ok = true; for (int e = 0; e < res.size() && ok; e++) { if (pref[e + f] < res[e]) ok = false; if (pref[e + f] > res[e]) break; } if (!ok) return false; } return true; } if (vis[qx][qy][qz][pos]) return false; vis[qx][qy][qz][pos] = 1; if (qz > 0) { int nxt = pos; if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'c' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'c') nxt++; if (solve(qx, qy, qz - 1, nxt)) return true; } if (res[pos] != 'c' && qy > 0) { int nxt = pos; if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'b' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'b') nxt++; if (solve(qx, qy - 1, qz, nxt)) return true; } if (res[pos] != 'c' && res[pos] != 'b' && qx > 0) { int nxt = pos; if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'a' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'a') nxt++; if (solve(qx - 1, qy, qz, nxt)) return true; } return false; } int M() { int x, y, z; if (!(cin >> x >> y >> z)) return 0; int len = x + y + z; res.clear(); for (int e = 0; e < len; e++) { { if (z > 0) { res.push_back('c'); push(); memset(vis, false, sizeof(vis)); if (solve(x, y, z - 1, 0)) { z--; continue; } res.pop_back(); } } { if (y > 0) { res.push_back('b'); push(); memset(vis, false, sizeof(vis)); if (solve(x, y - 1, z, 0)) { y--; continue; } res.pop_back(); } } { if (x > 0) { res.push_back('a'); push(); memset(vis, false, sizeof(vis)); if (solve(x - 1, y, z, 0)) { x--; continue; } res.pop_back(); } } assert(0); } cout << res << endl; return 1; } int main() { while (M()) ; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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 && !found; ++i) { for (int j = 0; j < N; ++j) { string nxt = ans; char ch = nxt[i]; nxt.erase(nxt.begin() + i); nxt.insert(nxt.begin() + j, ch); 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; 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 flag = 0; bool ng = 0; for (int i = 0; i < (int)(n); ++i) { if (flag) { if (c != 0) { t.push_back('c'); c--; } else { t.push_back('b'); b--; } } else { if (s[i % m] == 'a') { if (a != 0) { t.push_back('a'); a--; } else { flag = 1; if (c != 0) { t.push_back('c'); c--; } else { t.push_back('b'); b--; } } } else if (s[i % m] == 'b') { if (b == 0) { if (c == 0) { ng = 1; } else { t.push_back('c'); c--; } } else { t.push_back('b'); b--; } } else { if (c == 0) { ng = 1; } else { t.push_back('c'); c--; } } } } if (ng) return false; 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; for (int i = 0; i < (int)(n); ++i) { 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; const double TIME_LIMIT = 1.5; const unsigned int RANDMAX = -1; unsigned int randxor() { static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned int t; t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); i++) { os << v[i] << (i + 1 == v.size() ? "" : " "); } return os; } namespace Timer { bool is_started = false; unsigned long long int cycle_per_sec = 2800000000; unsigned long long int beginCycle; unsigned long long int get_cycle() { unsigned int low, high; __asm__ volatile("rdtsc" : "=a"(low), "=d"(high)); return ((unsigned long long int)low) | ((unsigned long long int)high << 32); } double time_elapsed() { assert(is_started); return (double)(get_cycle() - beginCycle) / cycle_per_sec; } void reset_timer() { is_started = true; beginCycle = get_cycle(); } bool is_TLE(double limit) { assert(is_started); return time_elapsed() >= limit; } }; // namespace Timer using namespace Timer; string sorted(string s) { string t = s + s; string mx = "~"; for (int i = 0; i < s.size(); i++) { mx = min(mx, t.substr(i, s.size())); } return mx; } int main() { long long X, Y, Z; cin >> X >> Y >> Z; string w; for (int i = 0; i < X; i++) w += "a"; for (int i = 0; i < Y; i++) w += "b"; for (int i = 0; i < Z; i++) w += "c"; reset_timer(); string cur; while (!is_TLE(TIME_LIMIT)) { random_shuffle(w.begin(), w.end()); w = sorted(w); cur = max(w, cur); while (true) { bool update = false; for (int i = 0; i < w.size(); i++) { for (int j = i; j < w.size(); j++) { swap(w[i], w[j]); string t = sorted(w); if (cur < t) { cur = t; update = true; cout << cur << endl; } else { swap(w[i], w[j]); } } } if (!update) break; } } cout << cur << 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; long long s[200000]; long long t[200000]; int main() { char x[50]; int a, b, c; cin >> a >> b >> c; for (int i = 0; i < a; i++) x[i] = 'a'; for (int i = 0; i < b; i++) x[i + a] = 'b'; for (int i = 0; i < c; i++) x[i + a + b] = 'c'; bool k = 1, m = 1; while (k || m) { k = 0; m = 0; for (int i = 0; i < a + b + c - 1; i++) { if (x[i] == x[i + 1]) { swap(x[i], x[i + 1]); k = 1; } } for (int i = a + b + c; i > 0; i--) { if (x[i] == x[i - 1]) { swap(x[i], x[i - 1]); m = 1; } } } cout << x; }
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; long long fastpow(int a, int b, int MOD) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % MOD; } y = (y * y) % MOD; b /= 2; } return x; } long long InverseEuler(int n, int MOD) { return fastpow(n, MOD - 2, MOD); } long long f[300000]; bool init; long long C(int n, int r, int MOD) { if (!init) { init = 1; f[0] = 1; for (int i = 1; i < 300000; i++) f[i] = (f[i - 1] * i) % MOD; } return (f[n] * ((InverseEuler(f[r], MOD) * InverseEuler(f[n - r], MOD)) % MOD)) % MOD; } int N; string S = ""; vector<int> res; vector<char> tok; string solve(int A, int B, int C) { string res = ""; if (A == 1 || B == 1 || C == 1) { for (int i = 0; i < A; i++) res += "a"; for (int i = 0; i < C; i++) res += "c"; for (int i = 0; i < B; i++) res += "b"; return res; } int ka = (A + 1) / 2; int kb = B / 2; int kc = C / 2; return solve(ka, kb, kc) + solve(A - ka, B - kb, C - kc); } int main() { int A, B, C; std::ios::sync_with_stdio(false); cin >> A >> B >> C; string res = solve(A, B, C); 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; set<string> s; int main() { int aa, bb, cc; scanf("%d%d%d", &aa, &bb, &cc); for (; aa--;) s.insert("a"); for (; bb--;) s.insert("b"); while (cc--) s.insert("c"); while (s.size() - 1) { auto st = *s.begin() + *(--s.end()); s.erase(s.begin()); s.erase(--s.end()); s.insert(st); } puts((*s.begin()).c_str()); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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>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"); } } 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
UNKNOWN
ary = gets.chomp.split(" ").map(&:to_i) a = ary[0] b = ary[1] c = ary[2] if a > 0 bb = b/a ba = b%a cc = c/a ca = c%a kihonkei = "a"+"c"*cc+"b"*bb str = kihonkei*a+"c"*ca+"b"*ba elsif b>0 cc = c/b cb = c%b kihonkei = "b"+"c"*cb str = kihonkei*b+"c"*cb 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; int A, B, C; vector<string> vec; string maxn = ""; int cnt = 0; string shifts(string G) { string T = G; for (int i = 0; i < G.size(); i++) { string TT = ""; for (int j = 0; j < G.size(); j++) TT += G[(i + j) % G.size()]; T = min(T, TT); } return T; } void dfs(vector<string> V, string S) { cnt++; if (shifts(S) < maxn.substr(0, S.size())) return; 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; } int G = rand() % V.size(); for (int h = G; h < V.size() + G; h++) { int i = h % V.size(); 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()); vector<string> vec2; for (int i = 1; i < vec.size(); i++) vec2.push_back(vec[i]); dfs(vec2, vec[0]); 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
java
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { static InputStream is; static PrintWriter out; static String INPUT = ""; static void solve() { int x = ni(), y = ni(), z = ni(); int n = x+y+z; int[] f = new int[]{x, y, z}; if(x == 0 && y == 0){ for(int i = 0;i < z;i++){ out.print("c"); } out.println(); return; } if(x == 0){ f[0] = f[1]; f[1] = f[2]; f[2] = 0; } String ans = ""; for(int ar = 1;ar <= n;ar++){ int na = 0; int nbc = 0; for(int i = 0;i < n;i+=ar+1){ if(i+ar+1 > n){ na += n-i-1; nbc++; }else{ na += ar; nbc += 1; } } assert na + nbc == n; if(na >= f[0]){ for(int pe = n;pe >= ar+1;pe--){ int lna = 0; for(int i = 0;i < n;i+=pe){ if(i+pe > n){ lna += Math.min(ar, n-1-i); }else{ lna += ar; } } if(lna >= f[0]){ // tr("OK", pe, lna, f[0], na, ar); int[] g = Arrays.copyOf(f, 3); char[] t = new char[n]; int[] h = new int[n]; for(int j = 0;j < pe;j++){ for(int k = j;k < n-1;k+=pe){ if(g[0] > 0){ h[k/pe]++; g[0]--; t[k] = 'a'; } } } for(int l = 0;l < n;l++){ if(h[l] == 0){ if(h[0] == h[l-1]){ for(int j = 0;j < pe;j++){ for(int k = j+pe*50;k >= j;k-=pe){ if(k >= n)continue; if(t[k] != 0)continue; if(g[2] > 0){ g[2]--; t[k] = 'c'; } } } for(int j = 0;j < n;j++){ if(t[j] == 0){ t[j] = 'b'; } } }else{ int u = 0; for(;u < l && h[0] == h[u];u++); for(int j = 0;j < pe;j++){ for(int k = j+(u-1)*pe;k >= j;k-=pe){ if(k >= n)continue; if(t[k] != 0)continue; if(g[2] > 0){ g[2]--; t[k] = 'c'; } } } for(int j = 0;j < n;j++){ if(t[j] == 0){ t[j] = 'b'; } } } String can = new String(t); can = rotate(can); if(can.compareTo(ans) > 0){ ans = can; } break; } } } } } } if(x == 0){ ans = ans.replace("b", "c"); ans = ans.replace("a", "b"); } out.println(ans); } static String rotate(String s) { String t = s; for(int i = 0;i < s.length();i++){ String v = s.substring(i) + s.substring(0, i); if(v.compareTo(t) < 0){ t = v; } } return t; } 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": [] }
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; } const int oo = 0x3f3f3f3f; const int maxn = 60; int a, b, c; int main() { scanf("%d%d%d", &a, &b, &c); if (!a) { for (int i = (0), i_end_ = (b); i < i_end_; ++i) putchar('b'); for (int i = (0), i_end_ = (c); i < i_end_; ++i) putchar('c'); return 0; } if (b + c <= a) { for (int i = (0), i_end_ = (a - b - c); i < i_end_; ++i) { putchar('a'); } for (int i = (0), i_end_ = (c); i < i_end_; ++i) putchar('a'), putchar('c'); for (int i = (0), i_end_ = (b); i < i_end_; ++i) putchar('a'), putchar('b'); return 0; } do { putchar('a'); static bool f[maxn + 5][maxn + 5][maxn + 5]; memset(f, 0, sizeof f); f[a][b][c] = 1; while (1) { static bool nxt[maxn + 5][maxn + 5][maxn + 5]; memset(nxt, 0, sizeof nxt); bool ok = 0; for (int i = (0), i_end_ = (a + 1); i < i_end_; ++i) for (int j = (0), j_end_ = (b + 1); j < j_end_; ++j) for (int k = (0), k_end_ = (c + 1); k < k_end_; ++k) if (f[i][j][k]) { if (k >= i) { ok = 1; nxt[i][j][k - i] = 1; } } if (ok) { memcpy(f, nxt, sizeof f); putchar('c'); --c; } else { ok = 0; for (int i = (0), i_end_ = (a + 1); i < i_end_; ++i) for (int j = (0), j_end_ = (b + 1); j < j_end_; ++j) for (int k = (0), k_end_ = (c + 1); k < k_end_; ++k) if (f[i][j][k]) { for (int l = (0), l_end_ = (min(i, j) + 1); l < l_end_; ++l) if (l + k >= i) { ok = 1; nxt[l][j - l][k - (i - l)] = 1; } } if (ok) { memcpy(f, nxt, sizeof f); putchar('b'); --b; } else break; } } } while (--a); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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)55, 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; 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) { if (b + a < a + b) swap(a, b), swap(x, y); if (!x || !y) { string res; for (int i = (1); i <= (x); i++) res += a; for (int i = (1); i <= (y); i++) 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); if (x <= y + z) { int u = (y + z) / x, R = (y + z) % x, L = x - R; if (R * (u + 1) + min(u, z / L) * L <= z) { int u0 = (z - R * (u + 1)) / L, v0 = (z - R * (u + 1)) % L; string A = a, B = a, C = a; for (int i = (1); i <= (u0); i++) A += c; for (int i = (u0 + 1); i <= (u); i++) A += b; for (int i = (1); i <= (u0 + 1); i++) B += c; for (int i = (u0 + 2); i <= (u); i++) B += b; for (int i = (1); i <= (u + 1); i++) C += c; return solve(A, B, C, L - v0, v0, R); } int u0 = min(u, z / L), z0 = z - u0 * L; string A = a, B = a, C = a; for (int i = (1); i <= (u0); i++) A += c; for (int i = (u0 + 1); i <= (u); i++) A += b; int u1 = z0 / R, v1 = z0 % R; for (int i = (1); i <= (u1); i++) B += c; for (int i = (u1 + 1); i <= (u + 1); i++) B += b; for (int i = (1); i <= (u1 + 1); i++) C += c; for (int i = (u1 + 2); i <= (u + 1); i++) C += b; return solve(A, B, C, L, R - v1, v1); } int u = x / (y + z), v = x % (y + z); string A, B, C; int X = 0, Y = 0, Z = 0, now = 0; for (int i = (1); i <= (y + z); i++) { if (i <= v && now < z) { if (!X) { for (int i = (1); i <= (u + 1); i++) A += a; A += c; } X++, now++; } else if (i > v && now == z) { if (!Z) { for (int i = (1); i <= (u); i++) C += a; C += b; } Z++; } else if (now < z) { if (!Y) { for (int i = (1); i <= (u); i++) B += a; B += c; } Y++, now++; } else { if (!Y) { for (int i = (1); i <= (u + 1); i++) B += a; B += b; } Y++; } } return solve(A, B, C, X, Y, Z); } 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": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:336777216") using namespace std; const int MAXN = 50 + 2; int A, B, C, N; int L; char Fill[MAXN]; int Tmp[MAXN * 2]; int Check(int a, int b, int c, string S) { int Len = S.length(); for (int i = 0; i < N * 2; i++) Tmp[i] = 255; for (int i = 0; i < Len; i++) Tmp[i] = Tmp[i + N] = S[i]; for (int k = 1; k < Len; k++) for (int i = 0; i < N; i++) if (Tmp[i] != Tmp[k + i]) { if (Tmp[i] > Tmp[k + i]) return 0; break; } return 1; } string DP[MAXN][MAXN][MAXN]; int Test() { for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) DP[i][j][k] = ""; DP[0][0][0] = (string)Fill; for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) { if (DP[i][j][k].length() != i + j + k + L) continue; string tmp; if (i < A) { tmp = DP[i][j][k] + 'a'; if (Check(A - i - 1, B - j, C - k, tmp) && tmp > DP[i + 1][j][k]) DP[i + 1][j][k] = tmp; } if (j < B) { tmp = DP[i][j][k] + 'b'; if (Check(A - i, B - j - 1, C - k, tmp) && tmp > DP[i][j + 1][k]) DP[i][j + 1][k] = tmp; } if (k < C) { tmp = DP[i][j][k] + 'c'; if (Check(A - i, B - j, C - k - 1, tmp) && tmp > DP[i][j][k + 1]) DP[i][j][k + 1] = tmp; } } return (DP[A][B][C].length() == A + B + C + L); } void Work() { scanf("%d%d%d", &A, &B, &C); N = A + B + C; for (L = 1; L <= N; L++) { Fill[L] = 0; if (C > 0) { Fill[L - 1] = 'c'; C--; if (Test()) continue; C++; } if (B > 0) { B--; Fill[L - 1] = 'b'; if (Test()) continue; B++; } A--; Fill[L - 1] = 'a'; } printf("%s\n", Fill); } int main() { Work(); 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 <class S, class T> ostream& operator<<(ostream& o, const pair<S, T>& p) { return o << "(" << p.first << "," << p.second << ")"; } template <class T> ostream& operator<<(ostream& o, const vector<T>& vc) { o << "sz = " << vc.size() << endl << "["; for (const T& v : vc) o << v << ","; o << "]"; return o; } string operator*(string a, int k) { string s; for (int i = 0; i < (int)(k); i++) s += a; return s; } string solve(int A, int B, int C, string a, string b, string c) { if (B + C == 0) { return a * A; } if (A + C == 0) { return b * B; } if (B + A == 0) { return c * C; } if (A == 0) { return solve(B, C, 0, b, c, ""); } int q = A / (B + C); int r = A % (B + C); string o = a * q; if (r <= C) { return solve(r, B, C - r, o + a + c, o + b, o + c); } else { return solve(r - C, C, B - r, o + a + b, o + a + c, o + b); } } int main() { int A, B, C; cin >> A >> B >> C; cout << solve(A, B, C, "a", "b", "c") << endl; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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; } const int oo = 0x3f3f3f3f; const int maxn = 60; int a, b, c; int main() { scanf("%d%d%d", &a, &b, &c); do { putchar('a'); static bool f[maxn + 5][maxn + 5][maxn + 5]; memset(f, 0, sizeof f); f[a][b][c] = 1; while (1) { static bool nxt[maxn + 5][maxn + 5][maxn + 5]; memset(nxt, 0, sizeof nxt); bool ok = 0; for (int i = (0), i_end_ = (a + 1); i < i_end_; ++i) for (int j = (0), j_end_ = (b + 1); j < j_end_; ++j) for (int k = (0), k_end_ = (c + 1); k < k_end_; ++k) if (f[i][j][k]) { if (k >= i) { ok = 1; nxt[i][j][k - i] = 1; } } if (ok) { memcpy(f, nxt, sizeof f); putchar('c'); --c; } else { ok = 0; for (int i = (0), i_end_ = (a + 1); i < i_end_; ++i) for (int j = (0), j_end_ = (b + 1); j < j_end_; ++j) for (int k = (0), k_end_ = (c + 1); k < k_end_; ++k) if (f[i][j][k]) { for (int l = (0), l_end_ = (min(i, j) + 1); l < l_end_; ++l) if (l + k >= i) { ok = 1; nxt[l][j - l][k - (i - l)] = 1; } } if (ok) { memcpy(f, nxt, sizeof f); putchar('b'); --b; } else break; } } } while (--a); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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) { 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; string res = ""; vector<string> v; void change(int z, int y, int x) { vector<string> s; for (int i = 0; i < (int)v.size(); i++) { string temp = v[i]; if (x > 0) { x--; temp += 'a'; } else if (y > 0) { y--; temp += 'b'; } else if (z > 0) { z--; temp += 'c'; } s.push_back(temp); } v = s; return; } void solve(int x, int y, int z, int tot) { if (tot == 0) { if (x > 0) { res += 'a'; for (int i = 0; i < x; i++) { v.push_back("a"); } solve(0, y, z, x); } else if (y > 0) { res += 'b'; for (int i = 0; i < y; i++) { v.push_back("b"); } solve(x, 0, z, y); } else { res += 'c'; for (int i = 0; i < z; i++) { v.push_back("c"); } solve(x, y, 0, z); } } else { if (tot <= z) { res += 'c'; solve(x, y, z - tot, tot); change(tot, 0, 0); } else if (tot <= y + z) { res += 'b'; int aux = tot; int used = y >= aux ? aux : y; aux -= used; int used2 = z >= aux ? aux : z; change(used2, used, 0); solve(x, y - used, z - used2, tot); } else if (tot <= x + y + z) { res += 'a'; int aux = tot; int used = x >= aux ? aux : x; aux -= used; int used2 = y >= aux ? aux : y; aux -= used2; int used3 = z >= aux ? aux : z; change(used3, used2, used); solve(x - used, y - used2, z - used3, tot); } else { for (int i = (int)v.size() - 1; i >= 0; i--) { if (x > 0) { v[i] += 'a'; x--; } else if (y > 0) { v[i] += 'b'; y--; } else if (z > 0) { v[i] += 'c'; z--; } } } } return; } int main(void) { int x, y, z; scanf(" %d %d %d", &x, &y, &z); solve(x, y, z, 0); for (int i = 0; i < (int)v.size(); i++) { cout << v[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; string solve(int x, int y, int z) { cout << x << " " << y << " " << z << endl; if (y == 0 && z == 0) { string ans; for (int i = 0; i < x; i++) ans += 'a'; return ans; } if (x == 0) { string str = solve(y, z, 0); for (int i = 0; i < str.size(); i++) str[i]++; return str; } if (z == 0) { string str = solve(x, 0, y); for (int i = 0; i < str.size(); i++) { if (str[i] == 'c') str[i] = 'b'; } return str; } if (z >= x) { string str = solve(x, y, z - x); string ans; for (int i = 0; i < str.size(); i++) { if (str[i] == 'a') { ans += 'a'; ans += 'c'; } else { ans += str[i]; } } return ans; } if (x > z) { string str = solve(x - z, z, y); string ans; for (int i = 0; i < str.size(); i++) { if (str[i] == 'a') { ans += 'a'; } else if (str[i] == 'b') { ans += 'a'; ans += 'c'; } else if (str[i] == 'c') { ans += 'b'; } } return ans; } } int main() { int x, y, z; cin >> x >> y >> z; cout << solve(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
cpp
#include <bits/stdc++.h> using namespace std; inline char nc() { static char buf[100000], *l = buf, *r = buf; return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) ? EOF : *l++; } template <class T> void read(T &x) { x = 0; int f = 1, ch = nc(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = nc(); } while (ch >= '0' && ch <= '9') { x = x * 10 - '0' + ch; ch = nc(); } x *= f; } int X, Y, Z; multiset<char> s; int main() { read(X), read(Y), read(Z); for (int i = 1; i <= X; ++i) { s.insert('a'); } for (int i = 1; i <= Y; ++i) { s.insert('b'); } for (int i = 1; i <= Z; ++i) { s.insert('c'); } set<char>::iterator it; while (true) { if (s.empty()) break; it = s.begin(); putchar(*it); s.erase(it); if (s.empty()) break; it = s.end(); putchar(*(--it)); s.erase(it); } 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; 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; } string solve(int A, int B, int 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 < 10000; 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; } return s; } int main() { int A, B, C; cin >> A >> B >> C; string ma = ""; for (int t = 0; t < 50; t++) ma = max(ma, solve(A, B, C)); 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
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'); int N = s.length(); string ma = f(s); for (int t = 0; t < 10000; 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
cpp
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:336777216") using namespace std; const int MAXN = 100 + 2; int A, B, C, N; int L; char Fill[MAXN]; int Tmp[MAXN * 2]; int Check(int ta, int tb, int tc, string S) { int a, b, c; int Len = S.length(); for (int i = 0; i < Len; i++) Tmp[i] = S[i]; a = ta; b = tb; c = tc; if (S[0] == 'b' && a > 0) return 0; if (S[0] == 'c' && (a > 0 || b > 0)) return 0; if (a > 0 && b == 0 && c == 0) for (int i = Len; i < N; i++) Tmp[i] = 'a'; else if (b > 0 && a == 0 && c == 0) for (int i = Len; i < N; i++) Tmp[i] = 'b'; else for (int i = Len; i < N; i++) Tmp[i] = 'c'; for (int k = 1; k < N; k++) for (int i = 0; i < N; i++) if (Tmp[i] != Tmp[(k + i) % N]) { if (Tmp[i] > Tmp[(k + i) % N]) return 0; break; } int Best = 1; for (int k = 1; k < N; k++) for (int i = 0; i < N; i++) if (Tmp[(Best + i) % N] != Tmp[(k + i) % N]) { if (Tmp[(Best + i) % N] > Tmp[(k + i) % N]) Best = k; break; } for (int i = 0; i < N; i++) if (Tmp[(Best + i) % N] != Tmp[i]) { if (Tmp[(Best + i) % N] != 255) return 1; if (Tmp[i] == 'a') { if (b > 0 || c > 0) return 1; if (a == 0) return 0; a--; } else if (Tmp[i] == 'b') { if (c > 0) return 1; if (b == 0) return 0; b--; } else { if (c == 0) return 0; c--; } } return 1; } void Update(string& To, string From) { if (To == "" || To > From) To = From; } string DP[MAXN][MAXN][MAXN]; int Test() { for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) DP[i][j][k] = ""; DP[0][0][0] = (string)Fill; for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) { if (DP[i][j][k].length() != i + j + k + L) continue; string tmp; if (i < A) { tmp = DP[i][j][k] + 'a'; if (Check(A - i - 1, B - j, C - k, tmp)) Update(DP[i + 1][j][k], tmp); } if (j < B) { tmp = DP[i][j][k] + 'b'; if (Check(A - i, B - j - 1, C - k, tmp)) Update(DP[i][j + 1][k], tmp); } if (k < C) { tmp = DP[i][j][k] + 'c'; if (Check(A - i, B - j, C - k - 1, tmp)) Update(DP[i][j][k + 1], tmp); } } return (DP[A][B][C].length() == A + B + C + L); } void Work() { scanf("%d%d%d", &A, &B, &C); N = A + B + C; for (L = 1; L <= N; L++) { Fill[L] = 0; if (C > 0) { Fill[L - 1] = 'c'; C--; if (Test()) continue; C++; } if (B > 0) { B--; Fill[L - 1] = 'b'; if (Test()) continue; B++; } A--; Fill[L - 1] = 'a'; } printf("%s\n", Fill); } int main() { Work(); 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; unsigned long long over = 1000000007; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; int a, b, c; cin >> a >> b >> c; if (a == 0 && b == 0) { for (int i = 0; i < c; ++i) cout << "c"; cout << endl; return 0; } if (b == 0 && c == 0) { for (int i = 0; i < a; ++i) cout << "a"; cout << endl; return 0; } if (c == 0 && a == 0) { for (int i = 0; i < b; ++i) cout << "b"; cout << endl; return 0; } string ans_str; if (a == 0) { int k = min(b, c); vector<string> ans(k); for (int i = 0; i < b; ++i) ans[i % k] += "b"; for (int i = 0; i < c; ++i) ans[i % k] += "c"; for (int i = 0; i < k; ++i) ans_str += ans[i]; } else if (b == 0) { int k = min(a, c); vector<string> ans(k); for (int i = 0; i < a; ++i) ans[i % k] += "a"; for (int i = 0; i < c; ++i) ans[i % k] += "c"; for (int i = 0; i < k; ++i) ans_str += ans[i]; } else if (c == 0) { int k = min(a, b); vector<string> ans(k); for (int i = 0; i < a; ++i) ans[i % k] += "a"; for (int i = 0; i < b; ++i) ans[i % k] += "b"; for (int i = 0; i < k; ++i) ans_str += ans[i]; } else { int k = min(a, min(b, c)); vector<string> ans(k); for (int i = 0; i < a; ++i) ans[i % k] += "a"; for (int i = 0; i < c; ++i) ans[i % k] += "c"; for (int i = 0; i < b; ++i) ans[(i + c) % k] += "b"; for (int i = 0; i < k; ++i) ans_str += ans[i]; } string ans_min = ans_str; for (int i = 1; i < ans_str.size(); ++i) { ans_min = min(ans_min, ans_str.substr(i, ans_str.size() - i) + ans_str.substr(0, i)); } cout << ans_min << 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 s[100]; int main() { scanf("%d%d%d", &x, &y, &z); if (!x) { for (int i = 1; i <= y; ++i) s[i] = 'b'; for (; z;) { for (int i = y; i; --i) if (z) { s[i] = s[i] + 'c'; --z; } } for (int i = 1; i <= y; ++i) for (int j = 0; j <= (int)s[i].length() - 1; ++j) { printf("%c", s[i][j]); } } else { for (int i = 1; i <= x; ++i) s[i] = 'a'; for (; z;) { for (int i = x; i; --i) if (z) { s[i] = s[i] + 'c'; --z; } } int k = x; for (int i = 1; i <= x - 1; ++i) 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; } } for (int i = 1; i <= x; ++i) for (int j = 0; j <= (int)s[i].length() - 1; ++j) { printf("%c", s[i][j]); } } 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 solve(int a, int b, int c) { if (b == 0 and c == 0) { string res = ""; for (int t = 0; t != a; ++t) res += 'a'; return res; } int num = (a + (b + c - 1)) / (b + c); int cnt_short = num * (b + c) - a; string tmp = ""; for (int i = 0; i != num - 1; ++i) tmp += 'a'; vector<string> parts; for (int i = 0; i != (b + c - cnt_short); ++i) parts.push_back(tmp + 'a'); for (int i = 0; i != cnt_short; ++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'; sort(parts.begin(), parts.end()); vector<string> cparts = parts; cparts.resize(std::unique(parts.begin(), parts.end()) - cparts.begin()); while (cparts.size() < 3) cparts.push_back(""); assert(cparts.size() == 3); string zzans = solve(std::count(parts.begin(), parts.end(), cparts[0]), std::count(parts.begin(), parts.end(), cparts[1]), std::count(parts.begin(), parts.end(), cparts[2])); string ans = ""; for (char ch : zzans) ans += cparts[ch - 'a']; return ans; } int main() { int a, b, c; cin >> a >> b >> c; 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; int x, y, z; string s[105]; string doit(int d, int e, int f, string x, string y, string z) { 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; } for (int i = 0; i < e; ++i) { s[ct] += 'b'; ct++; ct %= d; } 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": [] }
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) { 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++) { for (int j = (long long int)0; j < at[i].size(); j++) { printf("%c", at[i][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 a,b,c; multiset<string>s; int main() { scanf("%d%d%d",&a,&b,&c); for(int i = 1;i<=a;i++)s.insert("a"); for(int i = 1;i<=b;i++)s.insert("b"); for(int i = 1;i<=c;i++)s.insert("c"); for(int i = 1;i<r+b+g;i++) { string x = *s.begin(),y = *(--s.end()); s.erase(s.lower_bound(x)),s.erase(s.lower_bound(y)); s.insert(x+y); }cout<<*s.begin(); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int maxn = 101; int x, y, z; string a, b, c; int main() { scanf("%d%d%d", &x, &y, &z); a = "a"; b = "b"; c = "c"; while (1) { if (!x) { x = y; a = b; y = z; b = c; } if (!x) { x = y; a = b; } if (z) { if (x <= z) { for (; z >= x; z -= x) a = a + c; } else { for (; x >= y + z; x -= y + z) { b = a + b; c = a + c; } if (x >= z) { swap(y, z); swap(b, c); b = a + b; x -= y; } } } else if (y) { if (x <= y) { for (; y >= x; y -= x) a = a + b; } else { for (; x >= y; x -= y) b = a + b; } } else { break; } } b = a; for (int i = 1; i < x; ++i) a = a + b; puts(a.c_str()); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-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 = 1; i <= c / a; i++) ra += z; rc = ra + z; int rrc = c % a; a -= (c % a); for (int i = 1; i <= b / a; i++) ra += y; rb = ra + y; int rrb = b % 1; 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": [] }
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; inline long long quickpow(long long m, long long n, long long p) { long long b = 1; while (n) { if (n & 1) b = b * m % p; n = n >> 1; m = m * m % p; } return b; } inline long long getinv(long long x, long long p) { return quickpow(x, p - 2, p); } inline long long read(void) { long long x = 0, f = 1; char ch = cin.get(); while (!isdigit(ch)) { f = ch == '-' ? -1 : 1; ch = cin.get(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - '0'; ch = cin.get(); } return x * f; } string ans; signed main(signed argc, char *argv[]) { ios::sync_with_stdio(false); long long x = read(), y = read(), z = read(), sum = x + y + z; while (1) { if (!sum) break; if (sum == 1) { if (x) ans += 'a'; if (y) ans += 'b'; if (z) ans += 'c'; --sum; continue; } if (x && z) { --x; --z; ans += "ac"; sum -= 2; continue; } if (x && y) { --x; --y; ans += "ab"; sum -= 2; continue; } if (y && z) { --y; --z; ans += "bc"; sum -= 2; continue; } if (x) { x -= 2; ans += "aa"; sum -= 2; continue; } if (y) { y -= 2; ans += "bb"; sum -= 2; continue; } if (z) { z -= 2; ans += "cc"; sum -= 2; continue; } } 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; int A, B, C; string getans(string S) { int ca = 0, cb = 0, cc = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == 'a') ca++; if (S[i] == 'b') cb++; if (S[i] == 'c') cc++; } if (cb == 0) return S; vector<string> vec; for (int i = 0; i < ca; i++) vec.push_back("a"); for (int i = 0; i < cc; i++) vec[i % ca] += "c"; sort(vec.begin(), vec.end()); int Z = 1; for (int i = 1; i < vec.size(); i++) { if (vec[i] == vec[i - 1]) Z = i + 1; else break; } for (int i = 0; i < cb; i++) vec[i % Z] += "b"; sort(vec.begin(), vec.end()); string G = "a"; int I = 0; for (int i = 1; i < vec.size(); i++) { if (vec[i] != vec[i - 1]) I++; G += ('a' + I); } vector<string> A = vec; A.erase(unique(A.begin(), A.end()), A.end()); string V = getans(G), U = ""; for (int i = 0; i < V.size(); i++) { U += A[V[i] - 'a']; } return U; } string F; int main() { cin >> A >> B >> C; if (A >= 1) F += "a"; if (B >= 1) F += "b"; if (C >= 1) F += "c"; int P = 0; while (A == 0) { A = B; B = C; C = 0; } while (B == 0) { B = C; C = 0; } string G = ""; for (int i = 0; i < A; i++) G += "a"; for (int i = 0; i < B; i++) G += "b"; for (int i = 0; i < C; i++) G += "c"; string ret = getans(G); for (int i = 0; i < ret.size(); i++) ret[i] = F[ret[i] - 'a']; cout << ret << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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 < x; i++) { at[y + z - 1 - (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 > z && z > 0) { for (int i = (long long int)0; i < y; i++) { at[z - 1 - (i % z)].push_back('b'); } for (int i = (long long int)0; i < z; i++) { at[i].push_back('c'); } l = z; } else if (y > z) { for (int i = (long long int)0; i < y; i++) { at[0].push_back('b'); } 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 a, b, c; char model[55]; vector<char> ans[55]; int p; void solve() { for (int i = (1); i <= (a); i++) ans[i].push_back('a'); int id = 1; for (int i = (1); i <= (c); i++) { ans[id].push_back('c'); id = id % a + 1; } int flag = id; for (int i = (1); i <= (b); i++) { ans[id].push_back('b'); id = id % a + 1; if (id == 1 && flag > 1) { id = flag; flag = 1; } } for (int i = (1); i <= (a); i++) { for (auto out : ans[i]) { printf("%c", out); } } } int main() { scanf("%d %d %d", &a, &b, &c); if (a == 0 && b == 0) { for (int i = (1); i <= (c); i++) printf("c"); } else if (a == 0) { int boc = c / b; model[++p] = 'b'; for (int i = (1); i <= (boc); i++) model[++p] = 'c'; c %= b; for (int i = (1); i <= (b); i++) { printf("%s", model + 1); if (c > 0) { printf("c"); c--; } } } else solve(); 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; long long int X, Y, Z, S, Q, R, K; void twoletter(long long X, long long Y, char xc, char yc) { bool f = false; if (X > Y) { swap(X, Y); swap(xc, yc); f = true; } long long xq = S / X, xr = S % X, yq = Y / X, yr = Y % X; for (int i = 0; i < X; ++i) { if (!f) cout << xc; for (int j = (i < xr) ^ f; j < xq; ++j) { cout << yc; } if (f) cout << xc; } } int main() { scanf("%lld%lld%lld", &X, &Y, &Z); S = X + Y + Z; if (S == X || S == Y || S == Z) { for (int i = 0; i < X; ++i) cout << 'a'; for (int i = 0; i < Y; ++i) cout << 'b'; for (int i = 0; i < Z; ++i) cout << 'c'; cout << endl; return 0; } if (X == 0) { twoletter(Y, Z, 'b', 'c'); return 0; } else { if (Y == 0) { twoletter(X, Z, 'a', 'c'); return 0; } if (Z == 0) { twoletter(X, Y, 'a', 'b'); return 0; } K = min({X, Y, Z}), Q = K; if (K == X) { long long Yq = Y / X, Yr = Y % X, Zq = Z / X, Zr = Z % X; for (int i = 0; i < Q; ++i) { cout << 'a'; for (int j = i < Zr; j < Zq; ++j) cout << 'c'; for (int j = i < Yr; j < Yq; ++j) cout << 'b'; } } else if (K == Y) { long long Xq = X / Y, Xr = X % Y, Zq = Z / Y, Zr = Z % Y; for (int i = 0; i < Q; ++i) { for (int j = i < Xr; j < Xq; ++j) cout << 'a'; for (int j = i < Zr; j < Zq; ++j) cout << 'c'; cout << 'b'; } } else { long long Xq = X / Z, Xr = X % Z, Yq = Y / Z, Yr = Y % Z; for (int i = 0; i < Q; ++i) { for (int j = i < Xr; j < Xq; ++j) cout << 'a'; cout << 'c'; for (int j = i < Yr; j < Yq; ++j) cout << '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
// eddy1021 #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef double D; typedef long double LD; typedef long long LL; typedef pair<int,int> PII; typedef pair<LL,LL> PLL; #define mod9 1000000009LL #define mod7 1000000007LL #define INF 1023456789LL #define INF16 10000000000000000LL #define eps 1e-9 #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(), (x).end() #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #ifndef ONLINE_JUDGE #define debug(...) printf(__VA_ARGS__) #else #define debug(...) #endif inline LL getint(){ LL _x=0,_tmp=1; char _tc=getchar(); while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar(); if( _tc == '-' ) _tc=getchar() , _tmp = -1; while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar(); return _x*_tmp; } inline LL add( LL _x , LL _y , LL _mod = mod7 ){ _x += _y; return _x >= _mod ? _x - _mod : _x; } inline LL sub( LL _x , LL _y , LL _mod = mod7 ){ _x -= _y; return _x < 0 ? _x + _mod : _x; } inline LL mul( LL _x , LL _y , LL _mod = mod7 ){ _x *= _y; return _x >= _mod ? _x % _mod : _x; } LL mypow( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 1LL; LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = mul( _ret , _a , _mod ); return _ret; } LL mymul( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 0LL; LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = add( _ret , _a , _mod ); return _ret; } inline bool equal( D _x , D _y ){ return _x > _y - eps && _x < _y + eps; } #define Bye exit(0) int __ = 1 , _cs; /*********default*********/ void build(){ } string mcp(string s){ int n = s.length(); s += s; int i=0, j=1; while (i<n && j<n){ int k = 0; while (k < n && s[i+k] == s[j+k]) k++; if (s[i+k] <= s[j+k]) j += k+1; else i += k+1; if (i == j) j++; } int ans = i < n ? i : j; return s.substr(ans, n); } int a , b , c; void init(){ cin >> a >> b >> c; } int gcd( int x , int y ){ if( x == 0 or y == 0 ) return x + y; return __gcd( x , y ); } int mxa; bool ok = false; inline string cal2( const vector<int>& v ){ int perc = c / (int)v.size(); int resc = c % (int)v.size(); int ress = (int)v.size() - resc; if( ress == 0 ) ress = (int)v.size(); int perb = b / ress; int resb = b % ress; //cout << perc << " " << resc << " " << perb << " " << resb << endl; vector<int> tmp; for( int i = 0 ; i < (int)v.size() ; i ++ ) if( i < resc ) tmp.push_back( 0 ); else tmp.push_back( 1 ); vector<int> tmp2; for( int i = 0 ; i < ress ; i ++ ) if( i < resb ) tmp2.push_back( 1 ); else tmp2.push_back( 0 ); string ret = "0"; do{ for( size_t i = 0 ; i < v.size() ; i ++ ){ string got = ""; for( size_t j = 0 ; j < v.size() ; j ++ ){ for( int k = 0 ; k < mxa - 1 ; k ++ ) got += "a"; if( v[ j ] == 0 ) got += "a"; for( int k = 0 ; k < perc ; k ++ ) got += "c"; if( tmp[ j ] == 0 ) got += "c"; if( i == j ){ for( int k = 0 ; k < b ; k ++ ) got += "b"; } } string got2 = mcp( got ); if( got == got2 ) ok = true; ret = max( ret , got2 ); } sort( tmp2.begin() , tmp2.end() ); do{ int ptr = 0; string got = ""; for( size_t j = 0 ; j < v.size() ; j ++ ){ for( int k = 0 ; k < mxa - 1 ; k ++ ) got += "a"; if( v[ j ] == 0 ) got += "a"; for( int k = 0 ; k < perc ; k ++ ) got += "c"; if( tmp[ j ] == 0 ) got += "c"; else{ for( int k = 0 ; k < perb ; k ++ ) got += "b"; if( tmp2[ ptr ++ ] ) got += "b"; } } string got2 = mcp( got ); if( got == got2 ) ok = true; ret = max( ret , got2 ); }while( next_permutation( tmp2.begin() , tmp2.end() ) ); if( ok ) return ret; }while( next_permutation( tmp.begin() , tmp.end() ) ); return ret; } inline string cal(){ mxa = 2; while( a / mxa > b + c ) mxa ++; int tot = a / (mxa - 1); int mr = a - tot * (mxa - 1); // mr with mxa, tot - mr with mxa - 1 vector<int> tmp; if( mr ) tmp.push_back( 0 ); for( int i = 0 ; i < tot - mr ; i ++ ) tmp.push_back( 1 ); for( int i = 1 ; i < mr ; i ++ ) tmp.push_back( 0 ); string bst = "0"; do{ bst = max( bst , cal2( tmp ) ); if( ok ) return bst; }while( next_permutation( tmp.begin() , tmp.end() ) ); return bst; } void real_solve(){ if( a == 0 and b == 0 ){ for( int i = 0 ; i < c ; i ++ ) putchar( 'c' ); puts( "" ); Bye; } bool noa = false; if( a == 0 ){ a = b; b = c; c = 0; noa = true; } int gg = gcd( a , gcd( b , c ) ); a /= gg; b /= gg; c /= gg; string tmp = cal(); string ans = ""; while( gg -- ) ans += tmp; if( noa ){ for( size_t i = 0 ; i < ans.length() ; i ++ ) ans[ i ] ++; } cout << ans << endl; Bye; } void solve(){ real_solve(); vector<char> v; 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' ); string bst = "0"; do{ string ret = ""; for( auto i : v ) ret += i; bst = max( bst , mcp( ret ) ); }while( next_permutation( v.begin() , v.end() ) ); cout << bst << endl; } int main(){ build(); //__ = getint(); while( __ -- ){ init(); 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": [] }
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; } const int oo = 0x3f3f3f3f; int a, b, c; int main() { scanf("%d%d%d", &a, &b, &c); do { putchar('a'); int resc = c, resb = b; while (1) { if (resc >= a) putchar('c'), resc -= a, --c; else if (resb + resc >= a) { putchar('b'); int tmp = min(resb, a); resb -= tmp; resc -= a - tmp; --b; } else break; } } while (--a); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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; } if (y + z == 0) { string ret; for (int i = 0; i < x; i++) ret.push_back('a'); 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
cpp
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:336777216") using namespace std; const int MAXN = 100 + 2; int A, B, C, N; int L; char Fill[MAXN]; int Tmp[MAXN * 2]; int Check(int a, int b, int c, string S) { int Len = S.length(); for (int i = 0; i < N * 2; i++) Tmp[i] = 255; for (int i = 0; i < Len; i++) Tmp[i] = Tmp[i + N] = S[i]; for (int k = 1; k < Len; k++) for (int i = 0; i < N; i++) if (Tmp[i] != Tmp[k + i]) { if (Tmp[i] > Tmp[k + i]) return 0; break; } return 1; } void Update(string& To, string From) { if (To == "" || To > From) To = From; } string DP[MAXN][MAXN][MAXN]; int Test() { for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) DP[i][j][k] = ""; DP[0][0][0] = (string)Fill; for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) { if (DP[i][j][k].length() != i + j + k + L) continue; string tmp; if (i < A) { tmp = DP[i][j][k] + 'a'; if (Check(A - i - 1, B - j, C - k, tmp)) Update(DP[i + 1][j][k], tmp); } if (j < B) { tmp = DP[i][j][k] + 'b'; if (Check(A - i, B - j - 1, C - k, tmp)) Update(DP[i][j + 1][k], tmp); } if (k < C) { tmp = DP[i][j][k] + 'c'; if (Check(A - i, B - j, C - k - 1, tmp)) Update(DP[i][j][k + 1], tmp); } } return (DP[A][B][C].length() == A + B + C + L); } void Work() { scanf("%d%d%d", &A, &B, &C); N = A + B + C; for (L = 1; L <= N; L++) { Fill[L] = 0; if (C > 0) { Fill[L - 1] = 'c'; C--; if (Test()) continue; C++; } if (B > 0) { B--; Fill[L - 1] = 'b'; if (Test()) continue; B++; } A--; Fill[L - 1] = 'a'; } printf("%s\n", Fill); } int main() { Work(); 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 <= sm; 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; while (deq.size()) { seg[cur] += deq.back(); deq.pop_back(); if (--cur == 0) cur = segn; } 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
python3
from itertools import permutations def shift(seq): res = [] for _ in range(len(seq)): res.append(seq) seq = seq[1:]+seq[0] return min(res) N = [int(i) for i in input().split(" ")] seq = "a"*N[0] + "b"*N[1] + "c"*N[2] print(max([shift("".join(i)) for i in set([s for s in permutations(seq)])]))
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]; } string calc(int x, int y, int z) { int c[3] = {x, y, z}; if (y == 0 && z == 0) { string res; res.resize(x, 'a'); return res; } if (x == 0) { if (z == 0) { string res; res.resize(y, 'b'); return res; } string res; res.resize(y + z, 'b'); int d = (y + z) / z; int r = (y + z) % z; int cur = 0; for (int i = 0; i < z; i++) { cur += d; if (i < r) cur++; res[cur - 1] = 'c'; } return res; } 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--; } int m2 = d - rest; while (c[1] >= rest) { for (int i = 0; i < rest; i++) { anss[i].push_back('b'); } c[1] -= rest; } int m1 = c[1]; for (int i = 0; i < c[1]; i++) { anss[rest - 1 - i].push_back('b'); } int m0 = rest - c[1]; string rec = calc(m0, m1, m2); vector<string> vans; for (int i = 0; i < rec.size(); i++) { if (rec[i] == 'a') { vans.push_back(anss[0]); } else if (rec[i] == 'b') { vans.push_back(anss[m0]); } else { vans.push_back(anss[m0 + m1]); } } if (anss.size() > m1 + m2 + m0) vans.push_back(anss.back()); string res; for (int i = 0; i < vans.size(); i++) res += vans[i]; return res; } void solve() { int c[3]; for (int i = 0; i < 3; i++) cin >> c[i]; string ans = calc(c[0], c[1], c[2]); 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> #pragma comment(linker, "/STACK:336777216") using namespace std; const int MAXN = 50 + 2; int A, B, C, N; string DP[MAXN][MAXN][MAXN]; int Tmp[MAXN * 2]; int Check(string S) { int Len = S.length(); for (int i = 0; i < N * 2; i++) Tmp[i] = 255; for (int i = 0; i < Len; i++) Tmp[i] = Tmp[i + N] = S[i]; for (int k = 1; k < Len; k++) for (int i = 0; i < N; i++) if (Tmp[i] != Tmp[k + i]) { if (Tmp[i] > Tmp[k + i]) return 0; break; } return 1; } void Work() { scanf("%d%d%d", &A, &B, &C); N = A + B + C; for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) { string tmp; if (i < A) { tmp = DP[i][j][k] + 'a'; if (Check(tmp) && tmp > DP[i + 1][j][k]) DP[i + 1][j][k] = tmp; } if (j < B) { tmp = DP[i][j][k] + 'b'; if (Check(tmp) && tmp > DP[i][j + 1][k]) DP[i][j + 1][k] = tmp; } if (k < C) { tmp = DP[i][j][k] + 'c'; if (Check(tmp) && tmp > DP[i][j][k + 1]) DP[i][j][k + 1] = tmp; } } printf("%s\n", DP[A][B][C].c_str()); } int main() { Work(); 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 flag = 0; bool ng = 0; for (int i = 0; i < (int)(n); ++i) { if (flag) { if (c != 0) { t.push_back('c'); c--; } else { t.push_back('b'); b--; } } else { if (s[i % m] == 'a') { if (a != 0) { t.push_back('a'); a--; } else { flag = 1; if (c != 0) { t.push_back('c'); c--; } else { t.push_back('b'); b--; } } } else if (s[i % m] == 'b') { if (b == 0) { if (c == 0) { ng = 1; } else { t.push_back('c'); c--; } } else { t.push_back('b'); b--; } } else { if (c == 0) { ng = 1; } else { t.push_back('c'); c--; } } } } if (ng) return false; 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; string s = "a"; int n = a + b + c; for (int i = 0; i < (int)(n - 1); ++i) { 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; const int maxn = 200; char s[maxn]; int main() { int A, B, C, N = 0; scanf("%d%d%d", &A, &B, &C); for (int i = 0; i < A; i++) s[N++] = 'a'; for (int i = 0; i < B; i++) s[N++] = 'b'; for (int i = 0; i < C; i++) s[N++] = 'c'; for (int i = 0, j = N - 1, k = 0; k < N; k++) if (k & 1) printf("%c", s[j--]); else printf("%c", s[i++]); 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 = 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 % 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
// eddy1021 #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef double D; typedef long double LD; typedef long long LL; typedef pair<int,int> PII; typedef pair<LL,LL> PLL; #define mod9 1000000009LL #define mod7 1000000007LL #define INF 1023456789LL #define INF16 10000000000000000LL #define eps 1e-9 #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(), (x).end() #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #ifndef ONLINE_JUDGE #define debug(...) printf(__VA_ARGS__) #else #define debug(...) #endif inline LL getint(){ LL _x=0,_tmp=1; char _tc=getchar(); while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar(); if( _tc == '-' ) _tc=getchar() , _tmp = -1; while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar(); return _x*_tmp; } inline LL add( LL _x , LL _y , LL _mod = mod7 ){ _x += _y; return _x >= _mod ? _x - _mod : _x; } inline LL sub( LL _x , LL _y , LL _mod = mod7 ){ _x -= _y; return _x < 0 ? _x + _mod : _x; } inline LL mul( LL _x , LL _y , LL _mod = mod7 ){ _x *= _y; return _x >= _mod ? _x % _mod : _x; } LL mypow( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 1LL; LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = mul( _ret , _a , _mod ); return _ret; } LL mymul( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 0LL; LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = add( _ret , _a , _mod ); return _ret; } inline bool equal( D _x , D _y ){ return _x > _y - eps && _x < _y + eps; } #define Bye exit(0) int __ = 1 , _cs; /*********default*********/ void build(){ } string mcp(string s){ int n = s.length(); s += s; int i=0, j=1; while (i<n && j<n){ int k = 0; while (k < n && s[i+k] == s[j+k]) k++; if (s[i+k] <= s[j+k]) j += k+1; else i += k+1; if (i == j) j++; } int ans = i < n ? i : j; return s.substr(ans, n); } int a , b , c; void init(){ cin >> a >> b >> c; } int gcd( int x , int y ){ if( x == 0 or y == 0 ) return x + y; return __gcd( x , y ); } int mxa; bool ok = false; inline string cal2( const vector<int>& v ){ int perc = c / (int)v.size(); int resc = c % (int)v.size(); int ress = (int)v.size() - resc; if( ress == 0 ) ress = (int)v.size(); int perb = b / ress; int resb = b % ress; //cout << perc << " " << resc << " " << perb << " " << resb << endl; vector<int> tmp; for( int i = 0 ; i < (int)v.size() ; i ++ ) if( i < resc ) tmp.push_back( 0 ); else tmp.push_back( 1 ); vector<int> tmp2; for( int i = 0 ; i < ress ; i ++ ) if( i < resb ) tmp2.push_back( 1 ); else tmp2.push_back( 0 ); string ret = "0"; do{ for( size_t i = 0 ; i < v.size() ; i ++ ){ string got = ""; for( size_t j = 0 ; j < v.size() ; j ++ ){ for( int k = 0 ; k < mxa - 1 ; k ++ ) got += "a"; if( v[ j ] == 0 ) got += "a"; for( int k = 0 ; k < perc ; k ++ ) got += "c"; if( tmp[ j ] == 0 ) got += "c"; if( i == j ){ for( int k = 0 ; k < b ; k ++ ) got += "b"; } } string got2 = mcp( got ); if( got == got2 ) ok = true; ret = max( ret , got2 ); } sort( tmp2.begin() , tmp2.end() ); do{ int ptr = 0; string got = ""; for( size_t j = 0 ; j < v.size() ; j ++ ){ for( int k = 0 ; k < mxa - 1 ; k ++ ) got += "a"; if( v[ j ] == 0 ) got += "a"; for( int k = 0 ; k < perc ; k ++ ) got += "c"; if( tmp[ j ] == 0 ) got += "c"; else{ for( int k = 0 ; k < perb ; k ++ ) got += "b"; if( tmp2[ ptr ++ ] ) got += "b"; } } string got2 = mcp( got ); if( got == got2 ) ok = true; ret = max( ret , got2 ); }while( next_permutation( tmp2.begin() , tmp2.end() ) ); if( ok ) return ret; }while( next_permutation( tmp.begin() , tmp.end() ) ); return ret; } inline string cal(){ mxa = 2; while( a / mxa > b + c ) mxa ++; int tot = a / (mxa - 1); int mr = a - tot * (mxa - 1); // mr with mxa, tot - mr with mxa - 1 vector<int> tmp; if( mr ) tmp.push_back( 0 ); for( int i = 0 ; i < tot - mr ; i ++ ) tmp.push_back( 1 ); for( int i = 1 ; i < mr ; i ++ ) tmp.push_back( 0 ); string bst = "0"; do{ bst = max( bst , cal2( tmp ) ); //if( ok ) return bst; }while( next_permutation( tmp.begin() , tmp.end() ) ); return bst; } void real_solve(){ if( a == 0 and b == 0 ){ for( int i = 0 ; i < c ; i ++ ) putchar( 'c' ); puts( "" ); Bye; } bool noa = false; if( a == 0 ){ a = b; b = c; c = 0; noa = true; } int gg = gcd( a , gcd( b , c ) ); a /= gg; b /= gg; c /= gg; string tmp = cal(); string ans = ""; while( gg -- ) ans += tmp; if( noa ){ for( size_t i = 0 ; i < ans.length() ; i ++ ) ans[ i ] ++; } cout << ans << endl; Bye; } void solve(){ real_solve(); vector<char> v; 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' ); string bst = "0"; do{ string ret = ""; for( auto i : v ) ret += i; bst = max( bst , mcp( ret ) ); }while( next_permutation( v.begin() , v.end() ) ); cout << bst << endl; } int main(){ build(); //__ = getint(); while( __ -- ){ init(); 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": [] }
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 id = -1; bool flag[60] = {}; for (int i = 1; i < m; i++) { bool ppp = 1; for (int j = 0; j < (int)(m - i); ++j) { if (s[j] != s[i + j]) { ppp = 0; } } flag[i] = ppp; } for (int i = 1; i < m; i++) { if (flag[i]) id = i; } if (id != -1) { while (flag[id]) { id--; } id++; string q; for (int i = 0; i < (int)(id); ++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; const int MAX_N = 100005; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> 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; unsigned long long over = 1000000007; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; int a, b, c; cin >> a >> b >> c; if (a == 0 && b == 0) { for (int i = 0; i < c; ++i) cout << "c"; cout << endl; return 0; } if (b == 0 && c == 0) { for (int i = 0; i < a; ++i) cout << "a"; cout << endl; return 0; } if (c == 0 && a == 0) { for (int i = 0; i < b; ++i) cout << "b"; cout << endl; return 0; } string ans_str; if (a == 0) { int k = min(b, c); vector<string> ans(k); for (int i = 0; i < b; ++i) ans[i % k] += "b"; for (int i = 0; i < c; ++i) ans[i % k] += "c"; for (int i = 0; i < k; ++i) ans_str += ans[i]; sort(ans.begin(), ans.end()); do { string ans_n = ""; for (int i = 0; i < k; ++i) ans_n += ans[i]; ans_str = min(ans_n, ans_str); } while (next_permutation(ans.begin(), ans.end())); } else if (b == 0) { int k = min(a, c); vector<string> ans(k); for (int i = 0; i < a; ++i) ans[i % k] += "a"; for (int i = 0; i < c; ++i) ans[i % k] += "c"; for (int i = 0; i < k; ++i) ans_str += ans[i]; sort(ans.begin(), ans.end()); do { string ans_n = ""; for (int i = 0; i < k; ++i) ans_n += ans[i]; ans_str = min(ans_n, ans_str); } while (next_permutation(ans.begin(), ans.end())); } else if (c == 0) { int k = min(a, b); vector<string> ans(k); for (int i = 0; i < a; ++i) ans[i % k] += "a"; for (int i = 0; i < b; ++i) ans[i % k] += "b"; for (int i = 0; i < k; ++i) ans_str += ans[i]; sort(ans.begin(), ans.end()); do { string ans_n = ""; for (int i = 0; i < k; ++i) ans_n += ans[i]; ans_str = min(ans_n, ans_str); } while (next_permutation(ans.begin(), ans.end())); } else { if (a <= b + c) { vector<string> ans(a, "a"); for (int i = 0; i < c; ++i) ans[i % a] += "c"; for (int i = 0; i < b; ++i) ans[i % (a - c % a) + c % a] += "b"; for (int i = 0; i < a; ++i) ans_str += ans[i]; sort(ans.begin(), ans.end()); do { string ans_n = ""; for (int i = 0; i < a; ++i) ans_n += ans[i]; ans_str = min(ans_n, ans_str); } while (next_permutation(ans.begin(), ans.end())); } else { vector<string> ans(b + c); for (int i = 0; i < a; ++i) ans[i % (b + c)] += "a"; for (int i = 0; i < c; ++i) ans[i] += "c"; for (int i = c; i < b + c; ++i) ans[i] += "b"; for (int i = 0; i < b + c; ++i) ans_str += ans[i]; sort(ans.begin(), ans.end()); do { string ans_n = ""; for (int i = 0; i < b + c; ++i) ans_n += ans[i]; ans_str = min(ans_n, ans_str); } while (next_permutation(ans.begin(), ans.end())); } } cout << ans_str << 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, xa, xb, xc; string AA, BB, CC, ss[110]; void iter() { for (int i = 0; i < a; i++) ss[i] = AA; for (int i = 0; i < c; i++) { ss[i % a] += CC; } int ll = 0; if (c % a == 0) ll = a; else ll = (c - 1) % a; int now = 0; for (int i = 0; i < b; i++) { ss[i % (ll)] += BB; now += 1; if (now >= a) now = ll; } sort(ss, ss + a); int cnt = 0; xa = xb = xc = 0; for (int i = 0; i < a; i++) { if (i == 0 || ss[i] != ss[i - 1]) { cnt += 1; if (cnt == 1) AA = ss[i]; else if (cnt == 2) BB = ss[i]; else CC = ss[i]; } if (cnt == 1) xa += 1; else if (cnt == 2) xb += 1; else xc += 1; } a = xa; b = xb; c = xc; } int main() { scanf("%d%d%d", &a, &b, &c); AA = "a"; BB = "b"; CC = "c"; if (a == 0) { a = b; b = c; AA = BB; BB = CC; } if (a == 0) { for (int i = 0; i < c; i++) printf("c"); printf("\n"); return 0; } while (b + c > 0) { iter(); } while (a--) { cout << AA; } cout << 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; int a, b, c; char sa[55], sb[55], sc[55]; char ua[55], ub[55], uc[55]; int pa, pb, pc; void solve() { if (a == 0 && b == 0) { for (int i = (1); i <= (c); i++) printf("%s", sc); printf("\n"); return; } else if (a == 0) { int good = c % b, bad = b - c % b; for (int i = (1); i <= (b); i++) { printf("%s", sb); if (i * bad / b != (i - 1) * bad / b) { for (int j = (1); j <= (c / b); j++) printf("%s", sc); } else { for (int j = (1); j <= (c / b + 1); j++) printf("%s", sc); } } printf("\n"); return; } else { if (b == 0) { strcpy(sb, sa); b = a, a = 0; solve(); return; } else if (c == 0) { strcpy(sc, sb); strcpy(sb, sa); c = b, b = a, a = 0; solve(); return; } memset(ua, 0, sizeof(ua)); memset(ub, 0, sizeof(ub)); memset(uc, 0, sizeof(uc)); pa = pb = pc = 0; strcpy(ua, sa); pa += strlen(sa); strcpy(ub, sa); pb += strlen(sa); strcpy(uc, sa); pc += strlen(sa); int na, nb, nc, nab; int iter = c / a + (c % a > 0); for (int i = (1); i <= (iter); i++) { if (i < iter || c % a == 0) { strcpy(ua + pa, sc); pa += strlen(sc); } if (i < iter || c % a == 0) { strcpy(ub + pb, sc); pb += strlen(sc); } strcpy(uc + pc, sc); pc += strlen(sc); } nc = c % a; nab = a - nc; iter = b / nab + (b % nab > 0); for (int i = (1); i <= (iter); i++) { if (i < iter || b % nab == 0) { strcpy(ua + pa, sb); pa += strlen(sb); } strcpy(ub + pb, sb); pb += strlen(sb); } nb = b % nab; na = nab - nb; strcpy(sa, ua); a = na; strcpy(sb, ub); b = nb; strcpy(sc, uc); c = nc; solve(); } } int main() { scanf("%d %d %d", &a, &b, &c); sa[0] = 'a'; sb[0] = 'b'; sc[0] = 'c'; 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
// ayy // ' lamo #include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; //CARE typedef complex<ld> pt; #define fi first #define se second #define pb push_back const ld eps=1e-8; const int inf=1e9+99; const ll linf=1e18+99; const int P=1e9+7; string g1(string A,int X) { string Z=""; // cerr<<A<<" * "<<X<<endl; for(;X--;) Z+=A; return Z; } string g2(string A,string B,int X,int Y) { // cerr<<"g2"<<" "<<A<<" "<<B<<" "<<X<<" "<<Y<<endl; assert(A<B); if(!X) return g1(B,Y); if(!Y) return g1(A,X); string AA=A; string BB=A; for(int i=0;i*X<Y;i++) AA+=B, BB+=B; AA+=B; int XX=Y%X; int YY=X-XX; return g2(BB,AA,YY,XX); } string g3(string A,string B,string C,int X,int Y,int Z) { // cerr<<"g3"<<" "<<A<<" "<<B<<" "<<C<<" "<<X<<" "<<Y<<" "<<Z<<endl; assert(A<B && B<C); if(!X) return g2(B,C,Y,Z); if(!Y) return g2(A,C,X,Z); if(!Z) return g2(A,B,X,Y); string AA=A; string BB=A; string CC=A; for(int i=1;i*X<=Z;i++) AA+=C, BB+=C, CC+=C; AA+=C; int XX=Z%X; int qq=X-XX; assert(qq>=1); for(int i=1;i*qq<=Y;i++) BB+=B, CC+=B; BB+=B; int YY=Y%qq; int ZZ=qq-YY; assert(XX+YY+ZZ == X); return g3(CC,BB,AA,ZZ,YY,XX); } int32_t main() { int X,Y,Z; cin>>X>>Y>>Z; cout<<g3("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": [] }
IN-CORRECT
java
public class Main { private static void solve() { int[] a = na(3); int n = a[0] + a[1] + a[2]; char[] ret = new char[n]; for (int i = 0; i < n; i ++) { int v = i % 2 == 0 ? 1 : -1; int ptr = i % 2 == 0 ? 0 : 2; while (a[ptr] == 0) ptr += v; ret[i] = (char)('a' + ptr); a[ptr] --; } System.out.println(ret); } 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; template <class T> inline void gmin(T &x, const T &y) { if (x > y) x = y; } template <class T> inline void gmax(T &x, const T &y) { if (x < y) x = y; } const int BufferSize = 1 << 16; char buffer[BufferSize], *Bufferhead, *Buffertail; bool Terminal; inline char Getchar() { if (Bufferhead == Buffertail) { int l = fread(buffer, 1, BufferSize, stdin); if (!l) { Terminal = 1; return 0; } Buffertail = (Bufferhead = buffer) + l; } return *Bufferhead++; } template <class T> inline bool read(T &x) { x = 0; char c = Getchar(), rev = 0; while (c < '0' || c > '9') { rev |= c == '-'; c = Getchar(); if (Terminal) return 0; } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = Getchar(); if (c == '.') { c = Getchar(); double t = 0.1; while (c >= '0' && c <= '9') x = x + (c - '0') * t, c = Getchar(), t = t / 10; } x = rev ? -x : x; return 1; } template <class T1, class T2> inline bool read(T1 &x, T2 &y) { return read(x) & read(y); } template <class T1, class T2, class T3> inline bool read(T1 &x, T2 &y, T3 &z) { return read(x) & read(y) & read(z); } template <class T1, class T2, class T3, class T4> inline bool read(T1 &x, T2 &y, T3 &z, T4 &w) { return read(x) & read(y) & read(z) & read(w); } inline bool reads(char *x) { char c = Getchar(); while (c < 33 || c > 126) { c = Getchar(); if (Terminal) return 0; } while (c >= 33 && c <= 126) (*x++) = c, c = Getchar(); *x = 0; return 1; } template <class T> inline void print(T x, const char c = '\n') { if (!x) { putchar('0'); putchar(c); return; } if (x < 0) putchar('-'), x = -x; int m = 0, a[20]; while (x) a[m++] = x % 10, x /= 10; while (m--) putchar(a[m] + '0'); putchar(c); } const int inf = 0x3f3f3f3f; const int N = 105, M = 100005, mod = 1e9 + 7; template <class T, class S> inline void ch(T &x, const S y) { x = (x + y) % mod; } inline int exp(int x, int y, const int mod = ::mod) { int ans = 1; while (y) { if (y & 1) ans = (long long)ans * x % mod; x = (long long)x * x % mod; y >>= 1; } return ans; } int n, pl = -1; int g[5], a[N], s[N]; inline int check(int l, int r, int p, int q) { for (int i = l, j = p; i <= r && j <= q; i++, j++) if (a[i] > a[j]) return 1; else if (a[i] < a[j]) return -1; return 0; } inline bool check() { for (int i = 2; i <= n; i++) { int tmp = check(1, n, i, n); if (tmp == 1) return 0; if (tmp == -1) continue; if (check(n - i + 2, n, 1, i - 1) == 1) return 0; } return 1; } inline bool check(int m) { bool tag = 0; if (m == 2 && s[m] == 2) tag = 1; vector<int> now = vector<int>{0}; int cnt[5]; memcpy(cnt, g, sizeof(cnt)); for (int i = 1; i <= m; i++) a[i] = s[i], cnt[a[i]]--; for (int i = 2; i <= m; i++) { int tmp = check(1, m, i, m); if (tmp == 1) return 0; if (tmp == 0) now.push_back(m - i + 1); } for (int i = m + 1; i <= n; i++) { int mx = 1; for (int j = 0; j < now.size(); j++) if (now[j] < m) gmax(mx, a[now[j] + 1]); while (mx < 4 && !cnt[mx]) mx++; if (mx == 4) return 0; a[i] = mx; cnt[mx]--; vector<int> tn = vector<int>{0}; for (int j = 0; j < now.size(); j++) if (now[j] < m && a[now[j] + 1] == mx) tn.push_back(now[j] + 1); now = tn; } return check(); } int main() { read(g[1], g[2], g[3]); n = g[1] + g[2] + g[3]; if (!g[1]) { g[1] = g[2], g[2] = g[3], g[3] = 0; pl++; } if (!g[1]) { for (int i = 1; i <= n; i++) putchar('c'); puts(""); return 0; } int cnt[5]; memcpy(cnt, g, sizeof(cnt)); s[1] = 1; cnt[1]--; for (int i = 2; i <= n; i++) { for (int j = 3; j; j--) { if (!cnt[j]) continue; s[i] = j; if (check(i)) break; } cnt[s[i]]--; } for (int i = 1; i <= n; i++) putchar('a' + s[i] + pl); 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; 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 < x; i++) { at[y + z - 1 - (i % (y + z))].push_back('a'); } 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 + 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[x - 1 - (i + z) % x].push_back('b'); } l = x; } else if (y > z && z > 0) { for (int i = (long long int)0; i < y; i++) { at[z - 1 - (i % z)].push_back('b'); } for (int i = (long long int)0; i < z; i++) { at[i].push_back('c'); } l = z; } else if (y > z) { for (int i = (long long int)0; i < y; i++) { at[0].push_back('b'); } 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; 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) { 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'; } } if (X >= Y + Z) { 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--; } } } else { vector<int> smalls; vector<int> larges; const int slen = (Y + Z) / X; const int llen = slen + 1; for (int i = 0; i < tmp.size(); i++) { if (tmp[i] < 0 and tmp[i + 1] == 1) { smalls.push_back(i + 1); } else if (tmp[i] < 0 and tmp[i + 1] == 2) { larges.push_back(i + 1); } } reverse(larges.begin(), larges.end()); for (int i = 0; i < llen; i++) { for (const int li : larges) { if (Y > 0) { s[li + i] = 'b'; Y--; } else { s[li + i] = 'c'; Z--; } } } for (int i = 0; i < slen; i++) { for (const int si : smalls) { if (Z > 0) { s[si + i] = 'c'; Z--; } else { s[si + i] = 'b'; Y--; } } } } cout << s << 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; string solve(string a, string b, string c, int x, int y, int z) { if (y + z == 0) { string res = ""; for (int i = 0; i < x; ++i) res += a; return res; } if (x == 0) return solve(b, c, "", y, z, 0); int p = x / (y + z); int r = x % (y + z); string A = ""; for (int i = 0; i < p; ++i) A += a; if (z >= r) return solve(A + a + c, A + b, A + c, r, y, z - r); else return solve(A + a + b, A + a + c, A + b + c, 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": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<string> v; int main() { int x, y, z, k; scanf("%d %d %d", &x, &y, &z); for (k = 0; k <= 50; k++) { if (k * (y + z) >= x) break; } if (k == 51) { cout << string(x, 'a'); } if (k == 0) { if (y == 0) { cout << string(z, 'c'); return 0; } if (z == 0) { cout << string(y, 'b'); return 0; } for (k = 0; k <= 50; k++) { if (k * z >= y) break; } int q = y / k, r = y % k; if (r) { string S = ""; S += string(k - 1, 'b'); v.push_back(S + "c"); z -= k - r; q = r; } int qc = z / q, rc = z % q; if (rc) { for (int i = 0; i < q - rc; i++) v.push_back(string(k, 'b') + string(qc, 'c')); q = rc; qc++; } vector<string> v2; for (int i = 0; i < q; i++) v2.push_back(string(k, 'b') + string(qc, 'c')); sort(v.begin(), v.end()); int sz = v.size(); for (int i = 0; i < sz; i++) v2[i % q] += v[sz - i - 1]; for (int i = 0; i < q; i++) cout << v2[i]; } else { int q = x / k, r = x % k; if (r) { string S = ""; S += string(k - 1, 'a'); if (y >= q - r) { for (int i = 0; i < q - r; i++) v.push_back(S + "b"); y -= q - r; } else { for (int i = 0; i < y; i++) v.push_back(S + "b"); for (int i = 0; i < q - r - y; i++) v.push_back(S + "c"); z -= q - r - y; y = 0; } q = r; } vector<string> v2; for (int i = 0; i < q; i++) v2.push_back(string(k, 'a')); int qc = z / q, rc = z % q; for (int i = 0; i < q; i++) v2[i] += string(qc, 'c'); if (rc) { for (int i = 0; i < rc; i++) { v2[q - 1 - i] += "c"; v.push_back(v2[q - 1 - i]); v2.pop_back(); q = q - rc; } } int qb = y / q, rb = y % q; for (int i = 0; i < q; i++) v2[i] += string(qb, 'b'); for (int i = 0; i < rb; i++) v2[i] += "b"; for (int i = 0; i < q; i++) v.push_back(v2[i]); if (rb) q = rb; sort(v.begin(), v.end()); int sz = v.size(); vector<string> v3; for (int i = 0; i < q; i++) { v3.push_back(v[sz - 1 - i]); v.pop_back(); } sz = v.size(); for (int i = 0; i < sz; i++) { v3[i % q] += v[sz - 1 - i]; } for (int i = 0; i < q; i++) cout << v3[i]; } }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string res = ""; vector<string> v; void change(int z, int y, int x) { vector<string> s; for (int i = (int)v.size() - 1; i >= 0; i--) { string temp = v[i]; if (z > 0) { z--; temp += 'c'; } else if (y > 0) { y--; temp += 'b'; } else if (x > 0) { x--; temp += 'a'; } s.push_back(temp); } v = s; return; } void solve(int x, int y, int z, int tot) { if (tot == 0) { if (x > 0) { res += 'a'; for (int i = 0; i < x; i++) { v.push_back("a"); } solve(0, y, z, x); } else if (y > 0) { res += 'b'; for (int i = 0; i < y; i++) { v.push_back("b"); } solve(x, 0, z, y); } else { res += 'c'; for (int i = 0; i < z; i++) { v.push_back("c"); } solve(x, y, 0, z); } } else { if (tot <= z) { res += 'c'; solve(x, y, z - tot, tot); change(tot, 0, 0); } else if (tot <= y + z) { res += 'b'; int aux = tot; int used = y >= aux ? aux : y; aux -= used; int used2 = z >= aux ? aux : z; change(used2, used, 0); solve(x, y - used, z - used2, tot); } else if (tot <= x + y + z) { res += 'a'; int aux = tot; int used = x >= aux ? aux : x; aux -= used; int used2 = y >= aux ? aux : y; aux -= used2; int used3 = z >= aux ? aux : z; change(used3, used2, used); solve(x - used, y - used2, z - used3, tot); } else { for (int i = (int)v.size() - 1; i >= 0; i--) { if (z > 0) { v[i] += 'c'; z--; } else if (y > 0) { v[i] += 'b'; y--; } else if (x > 0) { v[i] += 'a'; x--; } } } } return; } int main(void) { int x, y, z; scanf(" %d %d %d", &x, &y, &z); solve(x, y, z, 0); for (int i = 0; i < (int)v.size(); i++) { cout << v[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; #define PB push_back #define MP make_pair #define LL long long #define int LL #define FOR(i,a,b) for(int i = (a); i <= (b); i++) #define RE(i,n) FOR(i,1,n) #define REP(i,n) FOR(i,0,(int)(n)-1) #define R(i,n) REP(i,n) #define VI vector<int> #define PII pair<int,int> #define LD long double #define FI first #define SE second #define st FI #define nd SE #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; } template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...); } template<class T> ostream &operator<<(ostream& os, vector<T> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; } template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) { return os << "(" << P.st << "," << P.nd << ")"; } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) (__VA_ARGS__) #define cerr if(0)cout #endif int a,b,c; int t[3]; vector<int> res; int nwd; void licz(int ak){ //debug(res,ak); if(SZ(res) == a + b + c){ R(i,nwd)for(int el:res)cout << char(el + 'a'); cout << "\n"; exit(0); } for(int i = 2; i >= res[ak]; i--){ if(t[i]){ t[i]--; res.PB(i); licz(i == res[ak] ? ak+1:0); res.pop_back(); t[i]++; } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(11); cerr << fixed << setprecision(6); cin >> a >> b >> c; nwd = __gcd(__gcd(a,b),c); a /= nwd; b /= nwd; c /= nwd; t[0] = a; t[1] = b; t[2] = c; for(int i = 0;i < 3;i++){ if(t[i]){ res.PB(i); t[i]--; break; } } licz(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 A[3], B[10]; int x[3], y[10]; string solve() { if (x[1] == 0 && x[2] == 0) { string ans = ""; for (int i = 1; i <= x[0]; i++) ans = ans + A[0]; return ans; } memset(y, 0x00, sizeof y); int num = x[2] / x[0]; for (int i = 1; i <= num; i++) A[0] = A[0] + A[2]; A[2] = A[0] + A[2]; int ne = x[2] % x[0]; x[0] -= ne; x[2] = ne; num = x[1] / x[0]; for (int i = 1; i <= num; i++) A[0] = A[0] + A[1]; A[1] = A[1] + A[2]; ne = x[1] % x[0]; x[0] -= ne; x[1] = ne; return solve(); } int main() { for (int i = 0; i < 3; i++) scanf("%d", &x[i]); A[0] = 'a'; A[1] = 'b'; A[2] = 'c'; cout << solve() << endl; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int p[55], size; const char c[3] = {'a', 'b', 'c'}; int main() { for (int i = 0, x; i < 3; ++i) { scanf("%d", &x); while (x--) p[++size] = i; } int head = 1, tail = size; while (head <= tail) { printf("%c", c[p[head++]]); if (head > tail) break; printf("%c", c[p[tail--]]); } 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; template <class C> void mini(C &a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); } template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "["; for (auto vv : V) os << vv << ","; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } long long a, b, c; long long t[3]; vector<long long> res; void licz(long long ak) { vector<long long> pom = res; long long ak2 = ak; long long t2[3]; for (long long i = (0); i <= ((long long)(3) - 1); i++) t2[i] = t[i]; while (((long long)(pom).size()) != a + b + c) { if (t2[pom[ak2]]) { pom.push_back(pom[ak2]); t2[pom[ak2]]--; ak2++; } else { for (long long i = pom[ak2]; i < 3; i++) { if (t2[i]) { pom.push_back(i); t2[i]--; goto ok; } } return; ok:; ak2 = 0; } } if (((long long)(res).size()) == a + b + c) { for (long long el : res) cout << char(el + 'a'); cout << "\n"; exit(0); } for (long long i = 2; i >= res[ak]; i--) { if (t[i]) { t[i]--; res.push_back(i); licz(i == res[ak] ? ak + 1 : 0); res.pop_back(); t[i]++; } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(11); if (0) cout << fixed << setprecision(6); cin >> a >> b >> c; t[0] = a; t[1] = b; t[2] = c; for (long long i = 0; i < 3; i++) { if (t[i]) { res.push_back(i); t[i]--; break; } } licz(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 A[3], B[10]; int x[3], y[10]; string solve() { if (x[1] == 0 && x[2] == 0) { string ans = ""; for (int i = 1; i <= x[0]; i++) ans = ans + A[0]; return ans; } memset(y, 0x00, sizeof y); int num = x[2] / x[0]; for (int i = 1; i <= num; i++) A[0] = A[0] + A[2]; A[2] = A[0] + A[2]; int ne = x[2] % x[0]; x[0] -= ne; x[2] = ne; num = x[1] / x[0]; for (int i = 1; i <= num; i++) A[0] = A[0] + A[1]; A[1] = A[1] + A[2]; ne = x[1] % x[0]; x[0] -= ne; x[1] = ne; return solve(); } int main() { for (int i = 0; i < 3; i++) scanf("%d", &x[i]); A[0] = 'a'; A[1] = 'b'; A[2] = 'c'; if (x[0] == 0) { x[0] = x[1]; x[1] = x[2]; A[0] = A[1]; A[1] = A[2]; x[2] = 0; } if (x[0] == 0) { x[0] = x[1]; x[1] = x[2]; A[0] = A[1]; A[1] = A[2]; x[2] = 0; } cout << solve() << endl; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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]; 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; string trans(string x, string a, string b, string c) { string ret; for (int i = 0; i <= (int)x.length() - 1; ++i) { 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) { cout << a << endl; return; } string s[55]; for (int i = 1; i <= x; ++i) s[i] = 'a'; for (; z;) { for (int i = x; i; --i) if (z) { s[i] = s[i] + 'c'; --z; } } int k = x; for (int i = 1; i <= x - 1; ++i) 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}; for (int i = 1; i <= x - 1; ++i) 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) { for (int i = 1; i <= z; ++i) printf("%c", 'c'); } else if (!x) { for (int i = 1; i <= y; ++i) s[i] = 'b'; for (; z;) { for (int i = y; i; --i) if (z) { s[i] = s[i] + 'c'; --z; } } for (int i = 1; i <= y; ++i) for (int j = 0; j <= (int)s[i].length() - 1; ++j) { printf("%c", s[i][j]); } } 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
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"; 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() { 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; 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 { 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('a'); if (c == 'a') { for (int o_to_ = (p), o = (0); o < o_to_; o++) ans.push_back('c'); for (int o_to_ = (q), o = (0); o < o_to_; o++) ans.push_back('b'); } else if (c == 'b') { for (int o_to_ = (p), o = (0); o < o_to_; o++) ans.push_back('c'); for (int o_to_ = (q + 1), o = (0); o < o_to_; o++) ans.push_back('b'); } else { for (int o_to_ = (p + 1), o = (0); o < o_to_; o++) ans.push_back('c'); } } } if (false) { cout << x << ' ' << y << ' ' << z << '\t'; for (char c : ans) cout << c; cout << '\n'; } return ans; } signed main() { if (!false) { 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 << '\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 main() { int X; int Y; int Z; string s; cin >> X; cin >> Y; cin >> Z; while (X > 0 || Y > 0 || Z > 0) { if (X > 0) { s += "a"; --X; } if (Z > 0) { s += "c"; --Z; } if (Y > 0) { s += "b"; --Y; } } 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; const int maxn = 55; string res; bool vis[maxn][maxn][maxn][maxn]; int failure[maxn]; void push() { memset(failure, 0, sizeof(failure)); for (int s = 2; s <= res.size(); s++) { failure[s] = failure[s - 1]; while (failure[s] > 0 && res[failure[s]] != res[s - 1]) failure[s] = failure[failure[s]]; if (res[failure[s]] == res[s - 1]) ++failure[s]; } } bool has_small_shift(string a, string b) { for (int e = 0; e < a.size(); e++) { for (int f = 0; f < b.size(); f++) if (a[f] < b[f]) return true; else if (a[f] > b[f]) break; a.push_back(a[0]); a.erase(a.begin()); } return false; } bool has_small_pref(string a, string b) { for (int e = 0; e < a.size(); e++) { for (int f = 0; f < b.size(); f++) { if (e + f == a.size()) break; if (a[e + f] < b[f]) return true; if (a[e + f] > b[f]) break; } } return false; } bool solve(int qx, int qy, int qz, int pos) { if (qx + qy + qz == 0) { string pref; for (int e = 0; e < pos; e++) pref.push_back(res[e]); pref += res; for (int e = 0; e < res.size(); e++) { if (pref[e] < res[e]) return false; if (pref[e] > res[e]) return true; } return true; } if (vis[qx][qy][qz][pos]) return false; vis[qx][qy][qz][pos] = 1; if (qz > 0) { int nxt = pos; bool go = true; if (nxt == res.size()) { string check = res; check.push_back('c'); if (has_small_shift(check, res)) go = false; } if (go) { if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'c' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'c') nxt++; if (solve(qx, qy, qz - 1, nxt)) return true; } } if (res[pos] != 'c' && qy > 0) { int nxt = pos; bool go = true; if (nxt == res.size()) { string check = res; check.push_back('b'); if (has_small_shift(check, res)) go = false; } if (go) { if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'b' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'b') nxt++; if (solve(qx, qy - 1, qz, nxt)) return true; } } if (res[pos] != 'c' && res[pos] != 'b' && qx > 0) { int nxt = pos; bool go = true; if (nxt == res.size()) { string check = res; check.push_back('a'); if (has_small_shift(check, res)) go = false; } if (go) { if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'a' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'a') nxt++; if (solve(qx - 1, qy, qz, nxt)) return true; } } return false; } int M() { int x, y, z; if (!(cin >> x >> y >> z)) return 0; int len = x + y + z; res.clear(); for (int e = 0; e < len; e++) { { if (z > 0) { res.push_back('c'); if (!has_small_pref(res, res)) { push(); memset(vis, false, sizeof(vis)); if (solve(x, y, z - 1, 0)) { z--; continue; } } res.pop_back(); } } { if (y > 0) { res.push_back('b'); push(); memset(vis, false, sizeof(vis)); if (!has_small_pref(res, res)) { if (solve(x, y - 1, z, 0)) { y--; continue; } } res.pop_back(); } } { if (x > 0) { res.push_back('a'); push(); if (!has_small_pref(res, res)) { memset(vis, false, sizeof(vis)); if (solve(x - 1, y, z, 0)) { x--; continue; } } res.pop_back(); } } assert(0); } cout << res << endl; return 1; } int main() { while (M()) ; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
java
import java.util.*; public class Main { public static void main(String[] args){ StringBuilder buff = new StringBuilder(); Scanner sc = new Scanner(System.in); // 整数の入力 int a = sc.nextInt(); // スペース区切りの整数の入力 int b = sc.nextInt(); int c = sc.nextInt(); 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
// eddy1021 #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef double D; typedef long double LD; typedef long long LL; typedef pair<int,int> PII; typedef pair<LL,LL> PLL; #define mod9 1000000009LL #define mod7 1000000007LL #define INF 1023456789LL #define INF16 10000000000000000LL #define eps 1e-9 #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(), (x).end() #define IOS ios_base::sync_with_stdio(0); cin.tie(0) #ifndef ONLINE_JUDGE #define debug(...) printf(__VA_ARGS__) #else #define debug(...) #endif inline LL getint(){ LL _x=0,_tmp=1; char _tc=getchar(); while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar(); if( _tc == '-' ) _tc=getchar() , _tmp = -1; while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar(); return _x*_tmp; } inline LL add( LL _x , LL _y , LL _mod = mod7 ){ _x += _y; return _x >= _mod ? _x - _mod : _x; } inline LL sub( LL _x , LL _y , LL _mod = mod7 ){ _x -= _y; return _x < 0 ? _x + _mod : _x; } inline LL mul( LL _x , LL _y , LL _mod = mod7 ){ _x *= _y; return _x >= _mod ? _x % _mod : _x; } LL mypow( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 1LL; LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = mul( _ret , _a , _mod ); return _ret; } LL mymul( LL _a , LL _x , LL _mod ){ if( _x == 0 ) return 0LL; LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod ); if( _x & 1 ) _ret = add( _ret , _a , _mod ); return _ret; } inline bool equal( D _x , D _y ){ return _x > _y - eps && _x < _y + eps; } #define Bye exit(0) int __ = 1 , _cs; /*********default*********/ void build(){ } string mcp(string s){ int n = s.length(); s += s; int i=0, j=1; while (i<n && j<n){ int k = 0; while (k < n && s[i+k] == s[j+k]) k++; if (s[i+k] <= s[j+k]) j += k+1; else i += k+1; if (i == j) j++; } int ans = i < n ? i : j; return s.substr(ans, n); } int a , b , c; void init(){ cin >> a >> b >> c; } int gcd( int x , int y ){ if( x == 0 or y == 0 ) return x + y; return __gcd( x , y ); } int mxa; inline string cal2( const vector<int>& v ){ int perc = c / (int)v.size(); int resc = c % (int)v.size(); int ress = (int)v.size() - resc; if( ress == 0 ) ress = (int)v.size(); int perb = b / ress; int resb = b % ress; //cout << perc << " " << resc << " " << perb << " " << resb << endl; vector<int> tmp; for( int i = 0 ; i < (int)v.size() ; i ++ ) if( i < resc ) tmp.push_back( 0 ); else tmp.push_back( 1 ); vector<int> tmp2; for( int i = 0 ; i < ress ; i ++ ) if( i < resb ) tmp2.push_back( 1 ); else tmp2.push_back( 0 ); string ret = "0"; do{ for( size_t i = 0 ; i < v.size() ; i ++ ){ string got = ""; for( size_t j = 0 ; j < v.size() ; j ++ ){ for( int k = 0 ; k < mxa - 1 ; k ++ ) got += "a"; if( v[ j ] == 0 ) got += "a"; for( int k = 0 ; k < perc ; k ++ ) got += "c"; if( tmp[ j ] == 0 ) got += "c"; if( i == j ){ for( int k = 0 ; k < b ; k ++ ) got += "b"; } } ret = max( ret , mcp( got ) ); } sort( tmp2.begin() , tmp2.end() ); do{ int ptr = 0; string got = ""; for( size_t j = 0 ; j < v.size() ; j ++ ){ for( int k = 0 ; k < mxa - 1 ; k ++ ) got += "a"; if( v[ j ] == 0 ) got += "a"; for( int k = 0 ; k < perc ; k ++ ) got += "c"; if( tmp[ j ] == 0 ) got += "c"; else{ for( int k = 0 ; k < perb ; k ++ ) got += "b"; if( tmp2[ ptr ++ ] ) got += "b"; } } ret = max( ret , mcp( got ) ); }while( next_permutation( tmp2.begin() , tmp2.end() ) ); }while( next_permutation( tmp.begin() , tmp.end() ) ); return ret; } inline string cal(){ mxa = 2; while( a / mxa > b + c ) mxa ++; int tot = a / (mxa - 1); int mr = a - tot * (mxa - 1); // mr with mxa, tot - mr with mxa - 1 vector<int> tmp; if( mr ) tmp.push_back( 0 ); for( int i = 0 ; i < tot - mr ; i ++ ) tmp.push_back( 1 ); for( int i = 1 ; i < mr ; i ++ ) tmp.push_back( 0 ); string bst = "0"; do{ bst = max( bst , cal2( tmp ) ); }while( next_permutation( tmp.begin() , tmp.end() ) ); return bst; } void real_solve(){ int gg = gcd( a , gcd( b , c ) ); a /= gg; b /= gg; c /= gg; string tmp = cal(); string ans = ""; while( gg -- ) ans += tmp; cout << ans << endl; Bye; } void solve(){ real_solve(); vector<char> v; 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' ); string bst = "0"; do{ string ret = ""; for( auto i : v ) ret += i; bst = max( bst , mcp( ret ) ); }while( next_permutation( v.begin() , v.end() ) ); cout << bst << endl; } int main(){ build(); //__ = getint(); while( __ -- ){ init(); 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": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int x, y, z; int main(void) { scanf("%d%d%d", &x, &y, &z); deque<string> ss; string ans = ""; if (x == 0 && y == 0) { for (int i = 0; i < z; i++) { ans += 'c'; } cout << ans << endl; return 0; } if (x == 0) { for (int i = 0; i < y; i++) { ss.push_back("b"); } int now = 0; for (int i = 0; i < z; i++) { ss[now] += 'c'; now = (now + 1) % y; } sort(ss.begin(), ss.end()); int fl = 0; for (int i = 0; i < y; i++) { if (fl == 0) { string st = ss[0]; ss.pop_front(); ans += st; } else { string st = ss[ss.size() - 1]; ss.pop_back(); ans += st; } fl = 1 - fl; } cout << ans << endl; return 0; } for (int i = 0; i < x; i++) { ss.push_back("a"); } int now = 0; for (int i = 0; i < z; i++) { ss[now] += 'c'; now = (now + 1) % x; } for (int i = 0; i < y; i++) { ss[now] += 'b'; now = (now + 1) % x; } sort(ss.begin(), ss.end()); int fl = 0; for (int i = 0; i < x; i++) { if (fl == 0) { string st = ss[0]; ss.pop_front(); ans += st; } else { string st = ss[ss.size() - 1]; ss.pop_back(); ans += st; } fl = 1 - fl; } 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
python2
def work(a,b,c,A,B,C): if A==0: return work(b,c,'',B,C,0) if B==0: if C==0: return a*A else: return work(a,c,'',A,C,0) if C==0: return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0) cmod = C%A if B <= A-cmod: return work(a+c*(C/A),a+c*(C/A)+b,a+c*(C/A+1),A-cmod-B,B,cmod) else: B = B - (A-cmod) bmod = B%A if bmod>=cmod: return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A)+b*(B/A+2),a+c*(C/A+1)+b*(B/A+1),A-bmod,bmod-cmod,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),A-cmod,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; int a, b, c, xa, xb, xc; string AA, BB, CC, ss[110]; void iter() { for (int i = 0; i < a; i++) ss[i] = AA; for (int i = 0; i < c; i++) { ss[i % a] += CC; } int ll = 0; if (c % a == 0) ll = 0; else ll = (c - 1) % a + 1; int now = ll; for (int i = 0; i < b; i++) { ss[now] += BB; now += 1; if (now >= a) now = ll; } sort(ss, ss + a); int cnt = 0; xa = xb = xc = 0; for (int i = 0; i < a; i++) { if (i == 0 || ss[i] != ss[i - 1]) { cnt += 1; if (cnt == 1) AA = ss[i]; else if (cnt == 2) BB = ss[i]; else CC = ss[i]; } if (cnt == 1) xa += 1; else if (cnt == 2) xb += 1; else xc += 1; } a = xa; b = xb; c = xc; } int main() { scanf("%d%d%d", &a, &b, &c); AA = "a"; BB = "b"; CC = "c"; if (a == 0) { a = b; b = c; AA = BB; BB = CC; } if (a == 0) { for (int i = 0; i < c; i++) printf("c"); printf("\n"); return 0; } while (b + c > 0) { iter(); } while (a--) { cout << AA; } cout << 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; 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; } 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 x, y, z; int main(void) { scanf("%d%d%d", &x, &y, &z); deque<string> ss; for (int i = 0; i < x; i++) { ss.push_back("a"); } int now = 0; for (int i = 0; i < z; i++) { ss[now] += 'c'; now = (now + 1) % x; } for (int i = 0; i < y; i++) { ss[now] += 'b'; now = (now + 1) % x; } sort(ss.begin(), ss.end()); string ans = ""; int fl = 0; for (int i = 0; i < x; i++) { if (fl == 0) { string st = ss[0]; ss.pop_front(); ans += st; } else { string st = ss[ss.size() - 1]; ss.pop_back(); ans += st; } fl = 1 - fl; } 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> #pragma comment(linker, "/STACK:336777216") using namespace std; const int MAXN = 50 + 2; int A, B, C, N; int L; char Fill[MAXN]; int Tmp[MAXN * 2]; int Check(int a, int b, int c, string S) { int Len = S.length(); for (int i = 0; i < N * 2; i++) Tmp[i] = 255; for (int i = 0; i < Len; i++) Tmp[i] = Tmp[i + N] = S[i]; for (int k = 1; k < Len; k++) for (int i = 0; i < N; i++) if (Tmp[i] != Tmp[k + i]) { if (Tmp[i] > Tmp[k + i]) return 0; break; } return 1; } void Update(string& To, string From) { if (To == "" || To > From) To = From; } string DP[MAXN][MAXN][MAXN]; int Test() { for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) DP[i][j][k] = ""; DP[0][0][0] = (string)Fill; for (int i = 0; i <= A; i++) for (int j = 0; j <= B; j++) for (int k = 0; k <= C; k++) { if (DP[i][j][k].length() != i + j + k + L) continue; string tmp; if (i < A) { tmp = DP[i][j][k] + 'a'; if (Check(A - i - 1, B - j, C - k, tmp)) Update(DP[i + 1][j][k], tmp); } if (j < B) { tmp = DP[i][j][k] + 'b'; if (Check(A - i, B - j - 1, C - k, tmp)) Update(DP[i][j + 1][k], tmp); } if (k < C) { tmp = DP[i][j][k] + 'c'; if (Check(A - i, B - j, C - k - 1, tmp)) Update(DP[i][j][k + 1], tmp); } } return (DP[A][B][C].length() == A + B + C + L); } void Work() { scanf("%d%d%d", &A, &B, &C); N = A + B + C; for (L = 1; L <= N; L++) { Fill[L] = 0; if (C > 0) { Fill[L - 1] = 'c'; C--; if (Test()) continue; C++; } if (B > 0) { B--; Fill[L - 1] = 'b'; if (Test()) continue; B++; } A--; Fill[L - 1] = 'a'; } printf("%s\n", Fill); } int main() { Work(); 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(vector<pair<string, int> > A) { if (A.size() == 1) { string ret = ""; for (int i = 0; i < A[0].second; i++) ret += A[0].first; return ret; } sort(A.begin(), A.end()); int sum = 0; for (pair<string, int> p : A) { sum += p.second; } vector<string> ret; if (A[0].second * 2 <= sum) { for (int i = 0; i < A[0].second; i++) ret.push_back(A[0].first); int cnt = A[0].second; A[0].second = 0; int id = A.size() - 1; while (0 < id) { for (int i = 0; i < cnt; i++) { while (0 < id && A[id].second == 0) id--; if (id == 0) break; else { A[id].second--; ret[i] += A[id].first; } } int ncnt = 0; for (int i = 0; i < cnt; i++) if (ret[0] == ret[i]) ncnt++; cnt = ncnt; } } else { int cnt = sum - A[0].second; for (int i = 0; i < cnt; i++) { ret.push_back(""); for (int j = 0; j < A[0].second / cnt + (i < A[0].second % cnt); j++) { ret.back() += A[0].first; } } int id = A.size() - 1; for (string& s : ret) { while (A[id].second == 0) id--; A[id].second--; s += A[id].first; } } sort(ret.begin(), ret.end()); vector<pair<string, int> > nxt; nxt.push_back(make_pair(ret[0], 1)); for (int i = 1; i < ret.size(); i++) { if (nxt.back().first == ret[i]) nxt.back().second += 1; else nxt.push_back(make_pair(ret[i], 1)); } return f(nxt); } int main() { int X, Y, Z; cin >> X >> Y >> Z; vector<pair<string, int> > A; if (X > 0) A.push_back(make_pair("a", X)); if (Y > 0) A.push_back(make_pair("b", Y)); if (Z > 0) A.push_back(make_pair("c", Z)); cout << f(A) << endl; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; vector<int> vec[55]; void put(int x) { if (x == 1) printf("a"); if (x == 2) printf("b"); if (x == 3) printf("c"); } int main() { int x, y, z; scanf("%d%d%d", &x, &y, &z); int now = x; for (int u = 1; u <= x; u++) vec[u].push_back(1); for (int u = 1; u <= z; u++) { vec[now].push_back(3); now--; if (now == 0) now = x; } for (int u = 1; u <= y; u++) { vec[now].push_back(2); now--; if (now == 0) now = x; } for (int u = 1; u <= x; u++) { int siz = vec[u].size(); for (int i = 0; i < siz; i++) put(vec[u][i]); } 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; char sa[55], sb[55], sc[55]; char ua[55], ub[55], uc[55]; int pa, pb, pc; void solve() { printf("%d %d %d\n", a, b, c); printf("%s %s %s\n", sa, sb, sc); if (a == 0 && b == 0) { for (int i = (1); i <= (c); i++) printf("%s", sc); printf("\n"); return; } else if (a == 0) { int good = c % b, bad = b - c % b; for (int i = (1); i <= (b); i++) { printf("%s", sb); if (i * bad / b != (i - 1) * bad / b) { for (int j = (1); j <= (c / b); j++) printf("%s", sc); } else { for (int j = (1); j <= (c / b + 1); j++) printf("%s", sc); } } printf("\n"); return; } else { if (b == 0) { strcpy(sb, sa); b = a, a = 0; solve(); return; } else if (c == 0) { strcpy(sc, sb); strcpy(sb, sa); c = b, b = a, a = 0; solve(); return; } pa = pb = pc = 0; strcpy(ua, sa); pa += strlen(sa); strcpy(ub, sa); pb += strlen(sa); strcpy(uc, sa); pc += strlen(sa); int na, nb, nc, nab; int iter = c / a + (c % a > 0); for (int i = (1); i <= (iter); i++) { if (i < iter || c % a == 0) { strcpy(ua + pa, sc); pa += strlen(sc); } if (i < iter || c % a == 0) { strcpy(ub + pb, sc); pb += strlen(sc); } strcpy(uc + pc, sc); pc += strlen(sc); } nc = c % a; nab = a - nc; iter = b / nab + (b % nab > 0); for (int i = (1); i <= (iter); i++) { if (i < iter || b % nab == 0) { strcpy(ua + pa, sb); pa += strlen(sb); } strcpy(ub + pb, sb); pb += strlen(sb); } nb = b % nab; na = nab - nb; strcpy(sa, ua); a = na; strcpy(sb, ub); b = nb; strcpy(sc, uc); c = nc; solve(); } } int main() { scanf("%d %d %d", &a, &b, &c); sa[0] = 'a'; sb[0] = 'b'; sc[0] = 'c'; 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; 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 < x; i++) { at[y + z - 1 - (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 a, b, c, xa, xb, xc; string AA, BB, CC, ss[110]; void iter() { for (int i = 0; i < a; i++) ss[i] = AA; for (int i = 0; i < c; i++) { ss[i % a] += CC; } int ll = 0; if (c % a == 0) ll = 0; else ll = (c - 1) % a + 1; int now = ll; for (int i = 0; i < b; i++) { ss[now] += BB; now += 1; if (now >= a) now = ll; } sort(ss, ss + a); int cnt = 0; xa = xb = xc = 0; for (int i = 0; i < a; i++) { if (i == 0 || ss[i] != ss[i - 1]) { cnt += 1; if (cnt == 1) AA = ss[i]; else if (cnt == 2) BB = ss[i]; else CC = ss[i]; } if (cnt == 1) xa += 1; else if (cnt == 2) xb += 1; else xc += 1; } a = xa; b = xb; c = xc; } int main() { scanf("%d%d%d", &a, &b, &c); AA = "a"; BB = "b"; CC = "c"; while (b + c > 0) { iter(); } while (a--) { cout << AA; } cout << 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; 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; } const int oo = 0x3f3f3f3f; const int maxn = 60; int a[3]; int main() { for (int i = (0), i_end_ = (3); i < i_end_; ++i) scanf("%d", a + i); int n = a[0] + a[1] + a[2]; static char ans[maxn + 5]; for (int i = (0), i_end_ = (n); i < i_end_; ++i) { static bool f[maxn + 5][maxn + 5][maxn + 5][maxn + 5]; for (int j = (0), j_end_ = (3); j < j_end_; ++j) if (a[j] > 0) { ans[i] = 'a' + j; --a[j]; memset(f, 0, sizeof f); f[a[0]][a[1]][a[2]][0] = 1; for (int first = a[0]; first >= 0; --first) for (int second = a[1]; second >= 0; --second) for (int z = a[2]; z >= 0; --z) for (int l = (0), l_end_ = (i + 1); l < l_end_; ++l) if (f[first][second][z][l]) { for (int k = (0), k_end_ = (3); k < k_end_; ++k) { int b[3] = {first, second, z}; if (b[k]) { --b[k]; if (ans[l] <= 'a' + k) { if (ans[l] == 'a' + k) l = (l + 1) % (i + 1); else l = 0; f[b[0]][b[1]][b[2]][l] = 1; } } } } if (f[0][0][0][0]) break; else ++a[j]; } } printf("%s\n", ans); 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 maxn = 55; string res; bool vis[maxn][maxn][maxn][maxn]; int failure[maxn]; void push() { memset(failure, 0, sizeof(failure)); for (int s = 2; s <= res.size(); s++) { failure[s] = failure[s - 1]; while (failure[s] > 0 && res[failure[s]] != res[s - 1]) failure[s] = failure[failure[s]]; if (res[failure[s]] == res[s - 1]) ++failure[s]; } } bool has_small_shift(string a, string b) { for (int e = 0; e < a.size(); e++) { for (int f = 0; f < b.size(); f++) if (a[f] < b[f]) return true; else if (a[f] > b[f]) break; a.push_back(a[0]); a.erase(a.begin()); } return false; } bool has_small_pref(string a, string b) { for (int e = 0; e < a.size(); e++) { for (int f = 0; f < b.size(); f++) { if (e + f == a.size()) break; if (a[e + f] < b[f]) return true; if (a[e + f] > b[f]) break; } } return false; } bool solve(int qx, int qy, int qz, int pos) { if (qx + qy + qz == 0) { string pref; for (int e = 0; e < pos; e++) pref.push_back(res[e]); pref += res; if (!has_small_pref(pref, res)) return true; return false; } if (vis[qx][qy][qz][pos]) return false; vis[qx][qy][qz][pos] = 1; if (qz > 0) { int nxt = pos; bool go = true; if (nxt == res.size()) { string check = res; check.push_back('c'); if (has_small_shift(check, res)) go = false; } if (go) { if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'c' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'c') nxt++; if (solve(qx, qy, qz - 1, nxt)) return true; } } if (res[pos] != 'c' && qy > 0) { int nxt = pos; bool go = true; if (nxt == res.size()) { string check = res; check.push_back('b'); if (has_small_shift(check, res)) go = false; } if (go) { if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'b' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'b') nxt++; if (solve(qx, qy - 1, qz, nxt)) return true; } } if (res[pos] != 'c' && res[pos] != 'b' && qx > 0) { int nxt = pos; bool go = true; if (nxt == res.size()) { string check = res; check.push_back('a'); if (has_small_shift(check, res)) go = false; } if (go) { if (nxt == res.size()) nxt = failure[nxt]; while (nxt > 0 && 'a' != res[nxt]) nxt = failure[nxt]; if (res[nxt] == 'a') nxt++; if (solve(qx - 1, qy, qz, nxt)) return true; } } return false; } int M() { int x, y, z; if (!(cin >> x >> y >> z)) return 0; int len = x + y + z; res.clear(); for (int e = 0; e < len; e++) { { if (z > 0) { res.push_back('c'); if (!has_small_pref(res, res)) { push(); memset(vis, false, sizeof(vis)); if (solve(x, y, z - 1, 0)) { z--; continue; } } res.pop_back(); } } { if (y > 0) { res.push_back('b'); push(); memset(vis, false, sizeof(vis)); if (!has_small_pref(res, res)) { if (solve(x, y - 1, z, 0)) { y--; continue; } } res.pop_back(); } } { if (x > 0) { res.push_back('a'); push(); if (!has_small_pref(res, res)) { memset(vis, false, sizeof(vis)); if (solve(x - 1, y, z, 0)) { x--; continue; } } res.pop_back(); } } assert(0); } cout << res << endl; return 1; } int main() { while (M()) ; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } const int INF = 1 << 30; const int MOD = 1e9 + 7; int main() { int x, y, z; cin >> x >> y >> z; multiset<string> A; for (int i = 0; i < x; ++i) A.insert("a"); for (int i = 0; i < y; ++i) A.insert("b"); for (int i = 0; i < z; ++i) A.insert("c"); for (int k = 1; k < x + y + z; ++k) { auto it1 = A.begin(); auto it2 = prev(A.end()); A.erase(it1); A.erase(it2); A.insert(*it1 + *it2); } cout << *A.begin() << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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 < x; i++) { at[y + z - 1 - (i % (y + z))].push_back('a'); } 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 + 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 > z && z > 0) { for (int i = (long long int)0; i < y; i++) { at[z - 1 - (i % z)].push_back('b'); } for (int i = (long long int)0; i < z; i++) { at[i].push_back('c'); } l = z; } else if (y > z) { for (int i = (long long int)0; i < y; i++) { at[0].push_back('b'); } 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; const int MAX_N = 100005; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> 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; 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'); int N = s.length(); string ma = f(s); for (int t = 0; t < 100000; 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
cpp
#include <bits/stdc++.h> using namespace std; int a, b, c; char model[55]; vector<char> ans[55]; int p; void solve() { for (int i = (1); i <= (a); i++) ans[i].push_back('a'); int id = 1; for (int i = (1); i <= (c); i++) { ans[id].push_back('c'); id = id % a + 1; } for (int i = (1); i <= (b); i++) { ans[id].push_back('b'); id = id % b + 1; } for (int i = (1); i <= (a); i++) { for (auto out : ans[i]) { printf("%c", out); } } } int main() { scanf("%d %d %d", &a, &b, &c); if (a == 0 && b == 0) { for (int i = (1); i <= (c); i++) printf("c"); } else if (a == 0) { int boc = c / b; model[++p] = 'b'; for (int i = (1); i <= (boc); i++) model[++p] = 'c'; c %= b; for (int i = (1); i <= (b); i++) { printf("%s", model + 1); if (c > 0) { printf("c"); c--; } } } else solve(); 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; 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": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int x, y, z; string s[100], S[100]; int main() { scanf("%d%d%d", &x, &y, &z); if (!x && !y) { for (int i = 1; i <= z; ++i) printf("%c", 'c'); } else if (!x) { for (int i = 1; i <= y; ++i) s[i] = 'b'; for (; z;) { for (int i = y; i; --i) if (z) { s[i] = s[i] + 'c'; --z; } } for (int i = 1; i <= y; ++i) for (int j = 0; j <= (int)s[i].length() - 1; ++j) { printf("%c", s[i][j]); } } else { for (int i = 1; i <= x; ++i) s[i] = 'a'; for (; z;) { for (int i = x; i; --i) if (z) { s[i] = s[i] + 'c'; --z; } } int k = x; for (int i = 1; i <= x - 1; ++i) 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}; for (int i = 1; i <= x - 1; ++i) 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]; for (int i = 1; i <= X; ++i) S[i] = 'a'; for (; Z;) { for (int i = X; i; --i) if (Z) { S[i] = S[i] + 'c'; --Z; } } k = X; for (int i = 1; i <= X - 1; ++i) 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; } } for (int i = 1; i <= X; ++i) for (int j = 0; j <= (int)S[i].length() - 1; ++j) { if (S[i][j] == 'a') cout << s[d[1]]; if (S[i][j] == 'b') cout << s[d[2]]; if (S[i][j] == 'c') cout << s[d[3]]; } } 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>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<=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"); } } 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; 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 (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; for (int i = 0; i < y / (x - z % x); i++) na += b; return f(x - z % x, z % x, y % (x - z % x), 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 namespace std; int x, y, z; void charput(int par) { cout << (char)('a' + par); if (par == 0) --x; else if (par == 1) --y; else --z; } int main() { cin >> x >> y >> z; if (x > 0) { charput(0); } else if (y > 0) { charput(1); } else { charput(2); } int end = x + y + z; for (int i = 0; i < end; i++) { if (x > 2) { charput(0); } else if (x == 1 && (y > 1 || z > 1)) { if (y > z) charput(1); else charput(2); } else if (x == 1) { charput(0); } else { if (y > z) charput(1); else charput(2); } } 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> #pragma GCC optimize "-O3" using namespace std; string solve(string sa, int a, string sb, int b, string sc, int c) { if (a == 0) { return solve(sb, b, sc, c, "", 0); } if (a <= b + c) { vector<string> vv(a, sa); int g = c / a; for (int i = 0; i < vv.size(); ++i) for (int j = 0; j < g; ++j) vv[i] += sc; g = a - c % a; for (int i = g; i < a; ++i) vv[i] += sc; for (int i = 0; i < b; ++i) vv[i % g] += sb; vector<pair<string, int> > go; int cur = 0; for (int i = 0; i < vv.size(); ++i) { ++cur; if (i == vv.size() - 1 || vv[i + 1] != vv[i]) { go.push_back(make_pair(vv[i], cur)); cur = 0; } } while (go.size() < 3) go.push_back(make_pair("", 0)); return solve(go[0].first, go[0].second, go[1].first, go[1].second, go[2].first, go[2].second); } else { if (b + c == 0) { string ans; for (int i = 0; i < a; ++i) ans += sa; return ans; } vector<string> vv(b + c); for (int i = 0; i < a; ++i) vv[i % (b + c)] += sa; for (int i = 0; i < c; ++i) vv[i] += sc; for (int i = 0; i < b; ++i) vv[c + i] += sb; sort(vv.begin(), vv.end()); vector<pair<string, int> > go; int cur = 0; for (int i = 0; i < vv.size(); ++i) { ++cur; if (i == vv.size() - 1 || vv[i + 1] != vv[i]) { go.push_back(make_pair(vv[i], cur)); cur = 0; } } while (go.size() < 3) go.push_back(make_pair("", 0)); return solve(go[0].first, go[0].second, go[1].first, go[1].second, go[2].first, go[2].second); } } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int a, b, c; cin >> a >> b >> c; cout << solve("a", a, "b", b, "c", c) << "\n"; return 0; }