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 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 < 50000; 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 ma; } int main() { int A, B, C; cin >> A >> B >> C; string ma = ""; for (int t = 0; t < 10; 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; string eval(string s) { int n = s.size(); s += s; string ans = "~"; for (int i = 0; i < n; ++i) { ans = min(ans, s.substr(i, n)); } return ans; } int main() { int X, Y, Z; cin >> X >> Y >> Z; int N = X + Y + Z; string ans = string(X, 'a') + string(Y, 'b') + string(Z, 'c'); string cur_ev = eval(ans); while (true) { bool found = false; for (int i = 0; i < N; ++i) { string nxt = ans; swap(nxt[i], nxt[(i + 1) % N]); string ev = eval(nxt); if (ev > cur_ev) { cur_ev = ev; ans = nxt; found = true; break; } } if (!found) break; } cout << 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; const long long mod = 1000000007; const long long inf = mod * mod; const long long d2 = 500000004; const double EPS = 1e-6; const double PI = acos(-1.0); int ABS(int a) { return max(a, -a); } long long ABS(long long a) { return max(a, -a); } int C[1100]; int B[1100]; int ad = 0; vector<string> str; void f(string aa, string bb, string cc, int a, int b, int c) { if (a == 0) { f(bb, cc, "", b, c, 0); return; } if (b + c == 0) { for (int i = 0; i < a; i++) printf("%s", aa.c_str()); printf("\n"); return; } ad = 0; for (int i = 0; i < 1100; i++) B[i] = C[i] = 0; while (a == 0) { a = b; b = c; c = 0; ad++; } for (int i = 0; i < c; i++) { C[i % a]++; } if (C[0] != C[a - 1]) { int f = 0; for (int i = 0; i < a; i++) if (C[a - 1] == C[i]) f++; for (int i = 0; i < b; i++) { B[a - f + i % f]++; } } else { for (int i = 0; i < b; i++) { B[i % a]++; } } str.clear(); for (int i = a - 1; i >= 0; i--) { string tmp = ""; tmp += aa; for (int j = 0; j < C[i]; j++) tmp += cc; for (int j = 0; j < B[i]; j++) tmp += bb; str.push_back(tmp); } string ta = "", tb = "", tc = ""; int va = 0; int vb = 0; int vc = 0; int fi = 0; int ph = 0; for (int i = 0; i < a; i++) { if (str[i] == str[fi]) { if (ph == 0) { va++; ta = str[i]; } if (ph == 1) { vb++; tb = str[i]; } if (ph == 2) { vc++; tc = str[i]; } } else { if (ph == 0) { ph++; vb++; tb = str[i]; fi = i; } if (ph == 1) { ph++; vc++; tc = str[i]; fi = i; } } } f(ta, tb, tc, va, vb, vc); } int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); f("a", "b", "c", a, b, c); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples 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) { assert(false); if (Y + Z > 0) { if (X >= Y + Z) { assert(false); vector<int> tmp(X + Y + Z); place(X, Y + Z, tmp); for (int i = 0; i < X + Y + Z; i++) { if (tmp[i] < 0) { s[i] = 'a'; } vector<int> smalls; vector<int> larges; for (int i = 0; i < tmp.size(); i++) { if (tmp[i] > 0 and tmp[i - 1] == -1) { larges.push_back(i); } else if (tmp[i] > 0 and tmp[i - 1] == -2) { smalls.push_back(i); } } reverse(smalls.begin(), smalls.end()); for (const int li : larges) { if (Y > 0) { s[li] = 'b'; Y--; } else { s[li] = 'c'; Z--; } } for (const int si : smalls) { if (Z > 0) { s[si] = 'c'; Z--; } else { s[si] = 'b'; Y--; } } } cout << s << endl; } else { vector<string> sv(X, "a"); const int slen = Z / X; const int llen = slen + 1; const int snum = llen * X - Z; for (int i = 0; i < snum; i++) { for (int j = 0; j < slen; j++) { sv[i].push_back('c'); } } for (int i = snum; i < X; i++) { for (int j = 0; j < llen; j++) { sv[i].push_back('c'); } } const int sslen = Y / snum; const int lllen = sslen + 1; const int ssnum = lllen * snum - Y; for (int i = 0; i < ssnum; i++) { for (int j = 0; j < sslen; j++) { sv[i].push_back('b'); } } for (int i = ssnum; i < snum; i++) { for (int j = 0; j < lllen; j++) { sv[i].push_back('b'); } } for (int i = 0; i < X; i++) { cout << sv[i]; } cout << endl; } } else { for (int i = 0; i < Y + Z; i++) { cout << 'a'; } cout << endl; return 0; } } else { if (Y > 0) { if (Z > 0) { vector<int> tmp(Y + Z); place(Y, Z, tmp); for (int i = 0; i < Y + Z; i++) { if (tmp[i] < 0) { s[i] = 'b'; } else { s[i] = 'c'; } } cout << s << endl; return 0; } else { for (int i = 0; i < Y; i++) { cout << 'b'; } cout << endl; return 0; } } else { for (int i = 0; i < Z; i++) { cout << 'c'; } cout << endl; return 0; } } return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; inline long long read() { long long x; char c; while ((c = getchar()) < '0' || c > '9') ; x = c - 48; while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - 48; return x; } const int maxn = 60; char s[maxn], ans[maxn], tmp[maxn * 2], res[maxn]; int main() { int a = read(), b = read(), c = read(); for (int i = 0; i < a; ++i) s[i] = 'a'; for (int i = 0; i < b; ++i) s[a + i] = 'b'; for (int i = 0; i < c; ++i) s[a + b + i] = 'c'; strcpy(ans, s); do { strcpy(res, s); memset(tmp, 0, sizeof(tmp)); strcpy(tmp, s); for (int i = 0; i < a + b + c; ++i) { tmp[i + a + b + c] = tmp[i]; if (strcmp(res, tmp + i + 1) > 0) strcpy(res, tmp + i + 1); } if (strcmp(ans, res) < 0) strcpy(ans, res); } while (next_permutation(s, s + a + b + c)); puts(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; string slow(int ca, int cb, int cc) { int n = ca + cb + cc; string s = ""; for (int i = 0; i < ca; i++) s += 'a'; for (int i = 0; i < cb; i++) s += 'b'; for (int i = 0; i < cc; i++) s += 'c'; string ans = s; do { string mn = s; for (int i = 0; i < n; i++) { string t = s; rotate(t.begin(), t.begin() + i, t.end()); mn = min(mn, t); } ans = max(ans, mn); } while (next_permutation(s.begin(), s.end())); return ans; } string fast(int ca, int cb, int cc) { bool f = 0; if (ca == 0) { f = 1; ca = cb; cb = cc; cc = 0; } if (ca == 0) { return string(cb, 'a'); } int n = ca + cb + cc; vector<string> a(ca, "a"); for (int i = 0; i < cc; i++) { a[i % ca] += "c"; } for (int i = 0; i < cb; i++) { a[(i + cc) % (ca - cc % ca) + cc % ca] += "b"; } sort(a.begin(), a.end()); string ans = "a"; do { string s = ""; for (string ss : a) s += ss; string mn = s; for (int i = 0; i < n; i++) { string t = s; rotate(t.begin(), t.begin() + i, t.end()); mn = min(mn, t); } ans = max(ans, mn); } while (next_permutation(a.begin(), a.end())); if (f) { for (char &c : ans) { if (c == 'a') c = 'b'; else c = 'c'; } } return ans; } int main() { int ca, cb, cc; while (cin >> ca >> cb >> cc) { cout << fast(ca, cb, cc) << endl; } return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; string solve(int X, int Y, int Z) { if (Y == 0 && Z == 0) { string ret = ""; for (int i = 0; i < X; i++) ret += "A"; return ret; } if (X == 0) { string ret = solve(Y, Z, 0); for (int i = 0; i < ret.size(); i++) { if (ret[i] == 'A') ret[i] = 'B'; else ret[i] = 'C'; } return ret; } else if (Y == 0) { string ret = solve(X, Z, 0); for (int i = 0; i < ret.size(); i++) if (ret[i] == 'B') ret[i] = 'C'; return ret; } if (Z == 0) { if (X % Y == 0) { string ret = ""; for (int i = 0; i < Y; i++) { for (int j = 0; j < X / Y; j++) ret += "A"; ret += "B"; } return ret; } string ret = solve(X % Y, X - (X % Y), 0); string ans = ""; for (int i = 0; i < ret.size(); i++) { if (ret[i] == 'A') { for (int j = 0; j <= X / Y; j++) ans += "A"; ans += "B"; } else { for (int j = 0; j < X / Y; j++) ans += "A"; ans += "B"; } } return ans; } int z = X % (Y + Z), k = (X + Y + Z - 1) / (Y + Z); if (z == 0) z = Y + Z; if (z <= Z) { string ret = solve(z, Y, Z - z); string ans = ""; for (int i = 0; i < ret.size(); i++) { if (ret[i] == 'A') { for (int j = 0; j < k; j++) ans += "A"; ans += "C"; } else { for (int j = 0; j < k - 1; j++) ans += "A"; ans += ret[i]; } } return ans; } else { string ret = solve(z - Z, Z, Y - (z - Z)); string ans = ""; for (int i = 0; i < ret.size(); i++) { if (ret[i] == 'C') { for (int j = 0; j < k - 1; j++) ans += "A"; ans += "B"; } else { for (int j = 0; j < k; j++) ans += "A"; if (ret[i] == 'A') ans += "B"; else ans += "C"; } } return ans; } return ""; } int main() { int X, Y, Z; scanf("%d %d %d", &X, &Y, &Z); string ret = solve(X, Y, Z); for (int i = 0; i < ret.size(); i++) { if (ret[i] == 'A') ret[i] = 'a'; if (ret[i] == 'B') ret[i] = 'b'; if (ret[i] == 'C') ret[i] = 'c'; } printf("%s\n", ret.c_str()); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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 = c % a; i < a && b > 0; ++i) { ans[i] += "b"; b--; } for (int i = 0; i < b; ++i) ans[i % 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> int main() { int X, Y, Z; scanf("%d %d %d", &X, &Y, &Z); if (X == 0 && Y == 0) { printf("%s\n", std::string(Z, 'c').c_str()); return 0; } else if (Y == 0 && Z == 0) { printf("%s\n", std::string(X, 'a').c_str()); return 0; } else if (Z == 0 && X == 0) { printf("%s\n", std::string(Y, 'b').c_str()); return 0; } if (X == 0 || Y == 0 || Z == 0) { char c, d; if (X == 0) { c = 'b', d = 'c'; X = Y, Y = Z; } else if (Y == 0) { c = 'a', d = 'c'; Y = Z; } else { c = 'a', d = 'b'; } std::string unit(1, c); unit += std::string(Y / X, d); std::vector<std::string> ss(X, unit); if (Y %= X) { int st = Y; for (int i = ss.size(); Y;) { ss[i - 1] += d; i -= i / Y; --Y; } } for (const std::string &s : ss) printf("%s", s.c_str()); printf("\n"); return 0; } return 1; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MX = 1000; char ans[MX][MX]; void solve2(int x, int y, int p) { if (x == 0) { for (int i = 0; i < y; i++) ans[p][i] = 'b'; } else if (y == 0) { for (int i = 0; i < x; i++) ans[p][i] = 'a'; } else if (x >= y) { int g = (x + y - 1) / y; int f = x % y; if (f == 0) f = y; solve2(f, y - f, p + 1); for (int i = 0, j = 0; i < y; i++) { for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a'; if (ans[p + 1][i] == 'a') ans[p][j++] = 'a'; ans[p][j++] = 'b'; } } else { int g = (x + y - 1) / x; int f = y % x; if (f == 0) f = x; solve2(x - f, f, p + 1); for (int i = 0, j = 0; i < x; i++) { ans[p][j++] = 'a'; for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'b'; if (ans[p + 1][i] == 'b') ans[p][j++] = 'b'; } } } void solve(int x, int y, int z, int p = 0) { if (x == 0) { solve2(y, z, p); for (int i = 0; i < y + z; i++) ans[p][i]++; } else if (y == 0) { solve2(x, z, p); for (int i = 0; i < y + z; i++) if (ans[p][i] == 'b') ans[p][i] = 'c'; } else if (z == 0) { solve2(x, y, p); } else if (x >= y + z) { int g = (x + y + z - 1) / (y + z); int f = x % (y + z); if (f == 0) f = y + z; if (z >= f) { solve(f, y, z - f, p + 1); for (int i = 0, j = 0; i < y + z; i++) { for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a'; if (ans[p + 1][i] == 'a') { ans[p][j++] = 'a'; ans[p][j++] = 'c'; } else { ans[p][j++] = ans[p + 1][i]; } } } else { solve(f - z, z, y + z - f, p + 1); for (int i = 0, j = 0; i < y + z; i++) { for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a'; if (ans[p + 1][i] == 'c') { ans[p][j++] = 'b'; } else { ans[p][j++] = 'a'; ans[p][j++] = ans[p + 1][i] + 1; } } } } else { static string S[MX]; for (int i = 0; i < x; i++) S[i] = "a"; for (int i = 0; i < z; i++) S[i % x] += "c"; for (int i = 0; i < y; i++) S[x - 1 - i % x] += "b"; set<string> strs; for (int i = 0; i < x; i++) strs.insert(S[i]); string SS[3]; int cnt[3] = {0, 0, 0}, iter = 0; for (auto& s : strs) { SS[iter] = s; cnt[iter] = 0; for (int i = 0; i < x; i++) if (S[i] == s) cnt[iter]++; iter++; } solve(cnt[0], cnt[1], cnt[2], p + 1); for (int i = 0, j = 0; i < y + z; i++) for (char c : SS[ans[p + 1][i] - 'a']) ans[p][j++] = c; } } int main() { int x, y, z; ignore = scanf("%d %d %d", &x, &y, &z); solve(x, y, z); ans[0][x + y + z] = 0; printf("%s\n", ans[0]); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; signed main() { int x, y, z; cin >> x >> y >> z; vector<int> cs, bs; if (x == 0) { if (y == 0) { cout << string(z, 'c') << '\n'; } else { for (int i = 0; i < y; ++i) { cs.push_back((z + i) / y); } for (int i = 0; i < y; ++i) { cout << 'b'; for (int j = 0; j < cs[i]; ++j) { cout << 'c'; } } cout << '\n'; } } else { for (int i = 0; i < x; ++i) { cs.push_back((z + i) / x); } int rem = z % x ? z % x : x; for (int i = 0; i < rem; ++i) { bs.push_back((y + i) / rem); } for (int i = 0; i < x; ++i) { cout << 'a'; for (int j = 0; j < cs[i]; ++j) { cout << 'c'; } for (int j = 0; j < bs[i]; ++j) { cout << 'b'; } } cout << '\n'; } }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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 = 2; j >= 0; --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) { int nxtl = l; if (ans[l] == 'a' + k) nxtl = (nxtl + 1) % (i + 1); else nxtl = 0; f[b[0]][b[1]][b[2]][nxtl] = 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; template <typename... As> struct tpl : public std::tuple<As...> { using std::tuple<As...>::tuple; tpl() {} tpl(std::tuple<As...> const& b) { std::tuple<As...>::operator=(b); } template <typename T = tuple<As...>> typename tuple_element<0, T>::type const& x() const { return get<0>(*this); } template <typename T = tuple<As...>> typename tuple_element<0, T>::type& x() { return get<0>(*this); } template <typename T = tuple<As...>> typename tuple_element<1, T>::type const& y() const { return get<1>(*this); } template <typename T = tuple<As...>> typename tuple_element<1, T>::type& y() { return get<1>(*this); } template <typename T = tuple<As...>> typename tuple_element<2, T>::type const& z() const { return get<2>(*this); } template <typename T = tuple<As...>> typename tuple_element<2, T>::type& z() { return get<2>(*this); } template <typename T = tuple<As...>> typename tuple_element<3, T>::type const& w() const { return get<3>(*this); } template <typename T = tuple<As...>> typename tuple_element<3, T>::type& w() { return get<3>(*this); } }; using lli = long long int; using llu = long long unsigned; using pii = tpl<lli, lli>; using piii = tpl<lli, lli, lli>; using piiii = tpl<lli, lli, lli, lli>; using vi = vector<lli>; using vii = vector<pii>; using viii = vector<piii>; using vvi = vector<vi>; using vvii = vector<vii>; using vviii = vector<viii>; template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>; template <class T> using max_queue = priority_queue<T>; template <size_t... I> struct my_index_sequence { using type = my_index_sequence; static constexpr array<size_t, sizeof...(I)> value = {{I...}}; }; namespace my_index_sequence_detail { template <typename I, typename J> struct concat; template <size_t... I, size_t... J> struct concat<my_index_sequence<I...>, my_index_sequence<J...>> : my_index_sequence<I..., (sizeof...(I) + J)...> {}; template <size_t N> struct make_index_sequence : concat<typename make_index_sequence<N / 2>::type, typename make_index_sequence<N - N / 2>::type>::type {}; template <> struct make_index_sequence<0> : my_index_sequence<> {}; template <> struct make_index_sequence<1> : my_index_sequence<0> {}; } // namespace my_index_sequence_detail template <class... A> using my_index_sequence_for = typename my_index_sequence_detail::make_index_sequence<sizeof...(A)>::type; template <class T, size_t... I> void print_tuple(ostream& s, T const& a, my_index_sequence<I...>) { using swallow = int[]; (void)swallow{0, (void(s << (I == 0 ? "" : ", ") << get<I>(a)), 0)...}; } template <class T> ostream& print_collection(ostream& s, T const& a); template <class... A> ostream& operator<<(ostream& s, tpl<A...> const& a); template <class... A> ostream& operator<<(ostream& s, tuple<A...> const& a); template <class A, class B> ostream& operator<<(ostream& s, pair<A, B> const& a); template <class T, size_t I> ostream& operator<<(ostream& s, array<T, I> const& a) { return print_collection(s, a); } template <class T> ostream& operator<<(ostream& s, vector<T> const& a) { return print_collection(s, a); } template <class T, class U> ostream& operator<<(ostream& s, multimap<T, U> const& a) { return print_collection(s, a); } template <class T> ostream& operator<<(ostream& s, multiset<T> const& a) { return print_collection(s, a); } template <class T, class U> ostream& operator<<(ostream& s, map<T, U> const& a) { return print_collection(s, a); } template <class T> ostream& operator<<(ostream& s, set<T> const& a) { return print_collection(s, a); } template <class T> ostream& print_collection(ostream& s, T const& a) { s << '['; for (auto it = begin(a); it != end(a); ++it) { s << *it; if (it != prev(end(a))) s << " "; } return s << ']'; } template <class... A> ostream& operator<<(ostream& s, tpl<A...> const& a) { s << '('; print_tuple(s, a, my_index_sequence_for<A...>{}); return s << ')'; } template <class... A> ostream& operator<<(ostream& s, tuple<A...> const& a) { s << '('; print_tuple(s, a, my_index_sequence_for<A...>{}); return s << ')'; } template <class A, class B> ostream& operator<<(ostream& s, pair<A, B> const& a) { return s << "(" << get<0>(a) << ", " << get<1>(a) << ")"; } vi redcnt(vi cnt) { vi cnt2; for (int i : cnt) if (i) cnt2.push_back(i); return cnt2; } vi solve(vi cnt) { cnt = redcnt(cnt); if (cnt.size() == 1) { vi r; for (lli i = 0; i < (lli)(cnt[0]); ++i) r.push_back(0); return r; } int k = 1; while (1) { int nx = (cnt[0] + k - 1) / k; int x1 = cnt[0] % nx; if (x1 == 0) x1 = nx; int x2 = nx - x1; map<vi, lli> make_pair; for (lli j = (cnt.size() - 1); j >= (lli)(1); --j) { vi base1; for (lli k_ = 0; k_ < (lli)(k); ++k_) base1.push_back(0); base1.push_back(j); vi base2; for (lli k_ = 0; k_ < (lli)(k - 1); ++k_) base2.push_back(0); base2.push_back(j); lli cc = cnt[j]; while (cc && x1) { cc--; x1--; make_pair[base1]++; } while (cc && x2) { cc--; x2--; make_pair[base2]++; } while (cc) { cc--; make_pair[{j}]++; } } if (x1 == 0 && x2 == 0) { vector<tpl<vi, lli>> mp_; for (auto p : make_pair) mp_.push_back(make_tuple(p.first, p.second)); vi cnt2; for (auto p : mp_) cnt2.push_back(p.y()); vi r = solve(cnt2); vi ans; for (int i : r) ans.insert(end(ans), begin(mp_[i].x()), end(mp_[i].x())); return ans; } k += 1; } }; int main() { ios::sync_with_stdio(0); cin.tie(0); lli x, y, z; cin >> x >> y >> z; vi r = solve({x, y, z}); string s; for (int i : r) s += 'a' + i; cout << s << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
// 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(){ 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; 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; } if (i + 2 < a + b + c) { if (x[i] == x[i + 1] - 1 && x[i + 1] == x[i + 2] - 1) swap(x[i + 1], x[i + 2]); } } 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
// 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=0;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=0;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
UNKNOWN
($X,$Y,$Z)=glob<>; $s='a'x$X.'B'x$Y.'C'x$Z; while($p=$s,$s=~s/^(a*)a?\K(\1.*)([BC])/\l$3$2/){ $t=$s; for(1..length$s){ $t=~s/(.)(.*)/$2$1/; if(lc$t lt lc$s){ $s=$t } } if(lc$p ge lc$s){ $s=$p; last } } print lc$s
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; 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 (y == 0) { string res; res.resize(x + z, 'a'); int d = (x + z) / z; int r = (x + z) % z; int cur = 0; for (int i = 0; i < z; i++) { cur += d; if (i < r) cur++; res[cur - 1] = 'c'; } 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> 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); cerr << "tmp" << " = " << tmp << endl; 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--; } } } } 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; 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) { if (C == 1 && B != 1) { return solve(A, B, 0) + 'c'; } if (C != 1 && B == 1) { return solve(A, 0, C) + 'b'; } 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; const int MX = 300500; string solve(int x, int y, int z) { vector<int> a_pos; int pos = 0; int n = x + y + z; string s; for (int i = 0; i < n; i++) { s += "b"; } while (x--) { a_pos.push_back(pos); s[pos] = 'a'; int space_left = n - 1 - pos; space_left -= x; space_left /= x + 1; pos += space_left + 1; } for (int j = 0; j < 100; j++) { for (int i = 0; i < a_pos.size(); i++) { if (z == 0) break; if (s[a_pos[i] + j + 1] == 'a') continue; s[a_pos[i] + j + 1] = 'c'; z--; } } return s; }; string sosolve(int x, int y, int z) { if (x) return solve(x, y, z); if (y == 0) { string s; while (z--) { s += "c"; } return s; } string s = solve(y, x, z); for (int i = 0; i < s.size(); i++) { if (s[i] == 'a') s[i] = 'b'; } return s; } int main(int argc, char** argv) { ios_base::sync_with_stdio(false); cin.tie(0); int x, y, z; cin >> x >> y >> z; cout << sosolve(x, y, z) << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int rem[55][55][55][55], nxt[55][10], fail[55], T; bool val[55][55][55][55]; char s[55]; int x, y, z; bool dfs2(int u, int v, int w, int p) { if (rem[u][v][w][p] == T) return val[u][v][w][p]; rem[u][v][w][p] = T; bool &r = val[u][v][w][p]; r = 0; if (u == 0 && v == 0 && w == 0) { for (int i = 0; i < x + y + z; i++) { if (s[i] == 0) break; if (s[p] > s[i]) return r = 0; else p = nxt[p][s[i] - 'a']; } return r = 1; } if (u > 0 && s[p] <= 'a') r |= dfs2(u - 1, v, w, nxt[p][0]); if (r) return 1; if (v > 0 && s[p] <= 'b') r |= dfs2(u, v - 1, w, nxt[p][1]); if (r) return 1; if (w > 0 && s[p] <= 'c') r |= dfs2(u, v, w - 1, nxt[p][2]); if (r) return 1; return r = 0; } bool checkp(int u, int v, int w, int d) { s[d] = 0; for (int i = 0; i < d; i++) { bool cmp = 0; for (int j = 0; j < d - i; j++) if (s[j] != s[i + j]) { if (s[j] > s[i + j]) cmp = 1; break; } if (cmp) return 0; } if (d == 0) return 1; for (int i = 0; i < 3; i++) nxt[0][i] = 0; if (d > 1) nxt[0][s[0] - 'a'] = 1; for (int i = 1; i < d; i++) { if (i == 1) fail[i] = 0; else fail[i] = nxt[fail[i - 1]][s[i] - 'a']; for (int j = 0; j < 3; j++) nxt[i][j] = nxt[fail[i]][j]; if (i + 1 != d) nxt[i][s[i] - 'a'] = i + 1; } fail[d] = nxt[fail[d - 1]][s[d] - 'a']; T++; return dfs2(u, v, w, fail[d]); } bool check(int d) { for (int i = 0; i < d; i++) { bool cmp = 0; for (int j = 0; j < d; j++) if (s[j] != s[(i + j) % d]) { if (s[j] > s[(i + j) % d]) cmp = 1; break; } if (cmp) return 0; } return 1; } void dfs(int u, int v, int w, int d) { if (!checkp(u, v, w, d)) return; if (u == 0 && v == 0 && w == 0) { if (check(d)) { puts(s); exit(0); } } else { if (w > 0) s[d] = 'c', dfs(u, v, w - 1, d + 1); if (v > 0) s[d] = 'b', dfs(u, v - 1, w, d + 1); if (u > 0) s[d] = 'a', dfs(u - 1, v, w, d + 1); } } int main() { scanf("%d%d%d", &x, &y, &z); dfs(x, y, z, 0); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> #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 i = 0; i < N; i++) Tmp[i + N] = Tmp[i]; for (int k = 1; k < N; 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 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++) { 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; 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 = 55, 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(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(0); for (int j = 0; j < now.size(); j++) if (now[j] < m && a[now[j] + 1] == mx) tn.push_back(now[j] + 1); if (mx == 1) tn.push_back(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; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int rem[55][55][55][55], nxt[55][10], fail[55], T; bool val[55][55][55][55]; char s[55]; int x, y, z; bool dfs2(int u, int v, int w, int p) { if (rem[u][v][w][p] == T) return val[u][v][w][p]; rem[u][v][w][p] = T; bool &r = val[u][v][w][p]; r = 0; if (u == 0 && v == 0 && w == 0) { for (int i = 0; i < x + y + z; i++) { if (s[i] == 0) break; if (s[p] > s[i]) return r = 0; else p = nxt[p][s[i] - 'a']; } return r = 1; } if (u > 0 && s[p] <= 'a') r |= dfs2(u - 1, v, w, nxt[p][0]); if (r) return 1; if (v > 0 && s[p] <= 'b') r |= dfs2(u, v - 1, w, nxt[p][1]); if (r) return 1; if (w > 0 && s[p] <= 'c') r |= dfs2(u, v, w - 1, nxt[p][2]); if (r) return 1; return r = 0; } bool checkp(int u, int v, int w, int d) { s[d] = 0; for (int i = 0; i < d; i++) { bool cmp = 0; for (int j = 0; j < d - i; j++) if (s[j] != s[i + j]) { if (s[j] > s[i + j]) cmp = 1; break; } if (cmp) return 0; } if (d == 0) return 1; if (d > 1) nxt[0][s[0] - 'a'] = 1; for (int i = 1; i < d; i++) { if (i == 1) fail[i] = 0; else fail[i] = nxt[fail[i - 1]][s[i] - 'a']; for (int j = 0; j < 3; j++) nxt[i][j] = nxt[fail[i]][j]; if (i + 1 != d) nxt[i][s[i] - 'a'] = i + 1; } fail[d] = nxt[fail[d - 1]][s[d] - 'a']; T++; return dfs2(u, v, w, fail[d]); } bool check(int d) { for (int i = 0; i < d; i++) { bool cmp = 0; for (int j = 0; j < d; j++) if (s[j] != s[(i + j) % d]) { if (s[j] > s[(i + j) % d]) cmp = 1; break; } if (cmp) return 0; } return 1; } void dfs(int u, int v, int w, int d) { if (!checkp(u, v, w, d)) return; if (u == 0 && v == 0 && w == 0) { if (check(d)) { puts(s); exit(0); } } else { if (w > 0) s[d] = 'c', dfs(u, v, w - 1, d + 1); if (v > 0) s[d] = 'b', dfs(u, v - 1, w, d + 1); if (u > 0) s[d] = 'a', dfs(u - 1, v, w, d + 1); } } int main() { scanf("%d%d%d", &x, &y, &z); dfs(x, y, z, 0); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; 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 (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 (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; string ans; void dfs(int a, int b, int c, string aa, string bb, string cc) { string nowa, nowb, nowc; if (a == 0) { dfs(b, c, 0, bb, cc, ""); } if ((b == 0) && (c == 0)) { int i; for (i = 0; i < a; i++) { ans += aa; } return; } nowa = aa; int j; for (j = 0; j < c / a; j++) { nowa += cc; } int newc = c % a; nowc = nowa + cc; a -= newc; for (j = 0; j < b / a; j++) { nowa += bb; } int newb = b % a; nowb = nowa + bb; a -= newb; dfs(a, newb, newc, nowa, nowb, nowc); } int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); dfs(a, b, c, "a", "b", "c"); cout << ans << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f2f1f0f; const long long LINF = 1ll * INF * INF; const int MAX_N = 1e2; int N, Ns[3], Now[MAX_N], Ans[MAX_N], AnsN[3]; int main() { cin >> Ns[0] >> Ns[1] >> Ns[2]; for (int k = 0; k < 3; k++) N += Ns[k]; for (int k = 0; k < 3; k++) AnsN[k] = Ns[k]; for (int s = 0; s < N; s++) { bool isFinish = false; for (int o = 2; o >= 0; o--) if (isFinish == false && AnsN[o] > 0) { bool isCan = true; Ans[s] = o; int cnt[3]; for (int k = 0; k < 3; k++) cnt[k] = Ns[k]; int en = N / (s + 1) * (s + 1); for (int i = 0; i < N; i++) { int is = i % (s + 1); bool findWell = false; for (int k = Ans[is]; k < 3; k++) { if (cnt[k] > 0) { cnt[k]--, Now[i] = k; findWell = true; break; } } if (findWell == false) isCan = false; } if (isCan) { for (int i = en; i < N; i++) { for (int j = 0; j < s + 1; j++) { if (Now[j] < Now[(i + j) % N]) { break; } else if (Now[j] > Now[(i + j) % N]) { isCan = false; break; } else continue; } } } if (isCan) isFinish = true, AnsN[o]--; } } for (int i = 0; i < N; i++) printf("%c", Ans[i] + 'a'); puts(""); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
$/=$";@_=sort(@_,(a)x<>,(b)x<>,(c)x<>)while$#_&&!($_[0].=pop@_);print@_
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples 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> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; } const int N = 100000; const int oo = 0x3f3f3f3f; template <typename T> T read() { T n(0), f(1); char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; return n * f; } int A, B, C; string solve(int len) { string str[55]; for (int i = 1; i <= len; ++i) { for (int j = 1; j <= A / len + (A % len >= i); ++j) str[i] += "a"; } int _len = A % len; if (_len == 0) _len = len; for (int i = 1; i <= _len; ++i) { for (int j = 1; j <= C / _len + (C % _len >= i); ++j) str[i] += "c"; } int __len = C % _len; if (__len == 0) __len = _len; for (int i = 1; i <= __len; ++i) { for (int j = 1; j <= B / __len + (B % __len >= i); ++j) str[i] += "b"; } string res; for (int i = 1; i <= len; ++i) res = res + str[i]; return res; } int main() { cin >> A >> B >> C; string res; for (int i = 1; i <= A + B + C; ++i) res = res + "0"; for (int i = 1; i <= A; ++i) { chkmax(res, solve(i)); } cout << res << 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; deque<string> ss2; 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()); sort(ss2.begin(), ss2.end()); int fl = 0; while (ss.size()) { 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; } fl = 1; while (ss2.size()) { if (fl == 0) { string st = ss2[0]; ss2.pop_front(); ans += st; } else { string st = ss2[ss2.size() - 1]; ss2.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; } for (int i = 0; i < now; i++) { ss2.push_back(ss[0]); ss.pop_front(); } sort(ss.begin(), ss.end()); sort(ss2.begin(), ss2.end()); int fl = 0; while (ss.size()) { 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; } fl = 1; while (ss2.size()) { if (fl == 0) { string st = ss2[0]; ss2.pop_front(); ans += st; } else { string st = ss2[ss2.size() - 1]; ss2.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> 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; } 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
cpp
#include <bits/stdc++.h> using namespace std; int X, Y, Z; string make(int X, int Y, int Z) { if (X == 0 && Y == 0 && Z == 0) return ""; string s = make(X / 2, Y / 2, Z / 2); vector<string> v; v.push_back(s); v.push_back(s); if (X % 2 == 1) { v.push_back("a"); } if (Y % 2 == 1) { v.push_back("b"); } if (Z % 2 == 1) { v.push_back("c"); } sort(v.begin(), v.end()); while (v.size() != 1) { vector<string> vv; for (int i = 0; i < (v.size() - 1); i++) { if (i == 0) { vv.push_back(v[0] + v[v.size() - 1]); } else { vv.push_back(v[i]); } } sort(vv.begin(), vv.end()); swap(v, vv); } return v[0]; } int main() { cin >> X >> Y >> Z; cout << make(X, Y, Z) << endl; return (0); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; } const int N = 100000; const int oo = 0x3f3f3f3f; template <typename T> T read() { T n(0), f(1); char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; return n * f; } int A, B, C; string solve(int len) { string str[55]; for (int i = 1; i <= len; ++i) { for (int j = 1; j <= A / len + (A % len >= i); ++j) str[i] += "a"; } int _len = A % len; if (_len == 0) _len = len; for (int i = 1; i <= _len; ++i) { for (int j = 1; j <= C / _len + (C % _len >= i); ++j) str[i] += "c"; } int __len = C % _len; if (__len == 0) __len = _len; for (int i = 1; i <= __len; ++i) { for (int j = 1; j <= B / __len + (B % __len >= i); ++j) str[i] += "b"; } string res; for (int i = 1; i <= len; ++i) res = res + str[i]; return res; } int main() { cin >> A >> B >> C; string res; for (int i = 1; i <= A + B + C; ++i) res = res + "0"; for (int i = 1; i <= A + B + C; ++i) { chkmax(res, solve(i)); } cout << res << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const int oo = 0x3f3f3f3f; const int maxn = 60; int a, b, c; int main() { scanf("%d%d%d", &a, &b, &c); 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> int main() { int X, Y, Z; scanf("%d %d %d", &X, &Y, &Z); if (X == 0 && Y == 0) { printf("%s\n", std::string(Z, 'c').c_str()); return 0; } else if (Y == 0 && Z == 0) { printf("%s\n", std::string(X, 'a').c_str()); return 0; } else if (Z == 0 && X == 0) { printf("%s\n", std::string(Y, 'b').c_str()); return 0; } if (X == 0 || Y == 0 || Z == 0) { char c, d; if (X == 0) { c = 'b', d = 'c'; X = Y, Y = Z; } else if (Y == 0) { c = 'a', d = 'c'; Y = Z; } else { c = 'a', d = 'b'; } std::string unit(1, c); unit += std::string(Y / X, d); std::vector<std::string> ss(X, unit); if (Y % X) { int s = (Y %= X); for (int i = ss.size() - 1; Y; i -= X / s) { ss[i] += d; --Y; } } for (const std::string &s : ss) printf("%s", s.c_str()); printf("\n"); return 0; } return 1; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
include<set> #include<cstdio> #include<cctype> #include<string> inline int getint() { register char ch; while(!isdigit(ch=getchar())); register int x=ch^'0'; while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0'); return x; } int main() { std::multiset<std::string> set; for(register int i=getint();i;i--) set.insert("a"); for(register int i=getint();i;i--) set.insert("b"); for(register int i=getint();i;i--) set.insert("c"); while(set.size()>1) { std::string s=*set.begin(),t=*set.rbegin(); set.erase(set.lower_bound(s)); set.erase(set.lower_bound(t)); set.insert(s+t); } printf("%s\n",(*set.begin()).c_str()); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; multiset<string> set; int a, b, c; int main() { cin >> a >> b >> c; for(int i = 1; i <= a; i--) { set.insert("a"); } for(int i = 1; i <= b; i--) { set.insert("b"); } for(int i = 1; i <= c; i--) { set.insert("c"); } while((set.size()) - 1 && set.size()) { string s = *set.begin(), t = *set.rbegin(); set.erase(set.lower_bound(s)); set.erase(set.lower_bound(t)); set.insert(s + t); } printf("%s\n",(*set.begin()).c_str()); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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; a -= (c % a); c = c % a; for (int i = 1; i <= b / a; i++) ra += y; rb = ra + y; a -= (b % a); b = b % a; dfs(a, b, c, 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
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; } 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; string solve(int x, int y, int z) { if (y == 0 && z == 0) { string ans; for (int u = 1; u <= x; u++) ans += 'a'; return ans; } if (x == 0) { string ans = solve(y, z, 0); for (int u = 0; u < ans.size(); u++) ans[u]++; return ans; } if (z == 0) { string ans = solve(x, 0, y); for (int u = 0; u < ans.size(); u++) if (ans[u] == 'c') ans[u] = 'b'; return ans; } if (z >= x) { string str = solve(x, y, z - x), ans; for (int u = 0; u < str.size(); u++) { ans += str[u]; if (str[u] == 'a') ans += 'c'; } return ans; } else { string str = solve(x - z, z, y), ans; for (int u = 0; u < str.size(); u++) { if (str[u] == 'a') ans += 'a'; else if (str[u] == 'b') { ans += 'a'; ans += 'c'; } else ans += 'c'; } return ans; } } int main() { int x, y, z; scanf("%d%d%d", &x, &y, &z); cout << solve(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<cstdio> int main(){ int x,y,z; scanf("%d%d%d",&x,&y,&z); int b[x]={}; int c[x]={}; if(x!=0){ if(x>y+z){ for(int i=x-1;i>=x-y;i--){ b[i]++; } for(int i=x-y-1;i>=x-y-z;i--){ c[i]++; } }else if(x==y+z){ for(int i=x-1;i>=x-z;i--){ c[i]++; } for(int i=x-z-1;i>=0;i--){ b[i]++; } }else{ if(x<=z){ if(z%x==0){ for(int i=0;i<x;i++){ c[i]+=z/x; } for(int i=0;i<x;i++){ b[i]+=y/x; } for(int i=x-1;i>=x-y%x;i--){ b[i]++; } }else{ for(int i=0;i<x;i++){ c[i]+=z/x; } for(int i=x-1;i>=x-z%x;i--){ c[i]++; } int k=x-z%x; for(int i=0;i<k;i++){ b[i]+=y/k; } for(int i=0;i<y%k;i--){ b[i]++; } } }else{ for(int i=x-1;i>=x-z;i--){ c[i]++; } int k=x-z; for(int i=0;i<k;i++){ b[i]+=x/k; } for(int i=k-1;i>=k-x%k;i--){ b[i]++; } } } for(int i=0;i<x;i++){ printf("a"); for(int j=0;j<c[i];j++){ printf("c"); } for(int j=0;j<b[i];j++){ printf("b"); } } }else if(y!=0){ if(z==0){ for(int i=0;i<y;i++){ printf("b"); } } if(y>z){ for(int i=0;i<z;i++){ printf("c"); for(int j=0;j<y/z;j++){ printf("b"); } if(i<y%z)printf("c"); } }else{ for(int i=0;i<z;i++){ printf("c"); if(i<y)printf("b"); } } }else{ for(int i=0;i<z;i++){ printf("c"); } } if(x<y && z==0 && x!=0){ for(int i=0;i<y-x;i++){ 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; 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 + B + C == max(A, max(B, C))) { 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; } if (A == 1 || B == 1 || C == 1) { if (C == 1 && A >= 2) { return solve(A - 1, B, 0) + "ac"; } if (C == 1 && B != 1) { return solve(A, B, 0) + 'c'; } if (C != 1 && B == 1) { return solve(A, 0, C) + 'b'; } 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 wut = 0; int wutc = 0; if (A % 2) wut = 1, wutc = 1; if (A == 0) wut = 1; int ka = (A + 1) / 2; int kb = (B + wut) / 2; int kc = (C + wutc) / 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; const long long mod = 1000000007; const long long inf = mod * mod; const long long d2 = 500000004; const double EPS = 1e-6; const double PI = acos(-1.0); int ABS(int a) { return max(a, -a); } long long ABS(long long a) { return max(a, -a); } int C[1100]; int B[1100]; int ad = 0; int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); while (a == 0) { a = b; b = c; ad++; } for (int i = 0; i < c; i++) { C[i % a]++; } if (C[0] != C[a - 1]) { int f = 0; for (int i = 0; i < a; i++) if (C[a - 1] == C[i]) f++; for (int i = 0; i < b; i++) { B[a - f + i % f]++; } } else { for (int i = 0; i < b; i++) { B[i % a]++; } } for (int i = a - 1; i >= 0; i--) { printf("%c", 'a' + ad); for (int j = 0; j < C[i]; j++) printf("%c", 'c' + ad); for (int j = 0; j < B[i]; j++) printf("%c", 'b' + ad); } printf("\n"); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int duval(string s) { int n = s.length(); s += s; int i = 0, ans = 0; while (i < n) { ans = i; int j = i + 1, k = i; while (j < n + n && s[k] <= s[j]) { if (s[k] < s[j]) { k = i; } else { k++; } j++; } while (i <= k) { i += j - k; } } return ans; } string res; void solve(vector<pair<string, int> > &v, const string &cur) { bool any = false; for (auto &p : v) { if (p.second == 0) { continue; } any = true; p.second--; solve(v, cur + p.first); p.second++; } if (!any) { int pos = duval(cur); string shift = cur.substr(pos) + cur.substr(0, pos); res = max(res, shift); } } int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); bool flag = false; if (a == 0) { flag = true; a = b; b = c; c = 0; } res = ""; if (a == 0) { res = string(b, 'b'); } else { vector<string> put(a, "a"); for (int i = 0; i < c; i++) { put[i % a] += 'c'; } int ptr = c % a; for (int i = 0; i < b; i++) { put[ptr] += 'b'; ptr++; if (ptr == a) { ptr = c % a; } } map<string, int> mp; for (auto &s : put) { mp[s]++; } vector<pair<string, int> > v; for (auto &p : mp) { v.push_back(p); } res = ""; solve(v, ""); } if (flag) { for (char &c : res) { c++; } } cout << res << 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> vec[10010]; int main() { int x, y, z, p; scanf("%d%d%d", &x, &y, &z); if (x == 0) { if (y == 0) { for (int i = 1; i <= z; i++) printf("c"); printf("\n"); return 0; } else { p = 1; for (int i = 1; i <= z; i++) { vec[p].push_back('c'); if (p == y) p = 1; else p++; } for (int i = 1; i <= y; i++) { printf("b"); for (int j = 0; j < (int)vec[i].size(); j++) printf("c"); } } return 0; } p = x; for (int i = 1; i <= z; i++) { vec[p].push_back('c'); p--; if (p == 0) p = x; } if (p == x) { for (int i = 1; i <= y; i++) { vec[p].push_back('b'); p--; if (p == 0) p = x; } for (int i = 1; i <= x; i++) { printf("a"); for (int j = 0; j < (int)vec[i].size(); j++) printf("%c", vec[i][j]); } return 0; } else { int zt = p; for (int i = 1; i <= y; i++) { vec[p].push_back('b'); p--; if (p == 0) p = zt; } for (int i = 1; i <= x; i++) { printf("a"); for (int j = 0; j < (int)vec[i].size(); j++) printf("%c", vec[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
python3
X, Y, Z = map(int, input().split()) d = [] if X > 0: if (Y+Z) > 0: j = max(X//(Y+Z), 1) else: j = 1 for _ in range(X//j): d.append("a"*j) for i in range(X-j*(X//j)): d[i] = d[i] + "a" for i in range(len(d)): d[i] = d[i] + "c"*(Z//X) for i in range(Z-(Z//X)*X): d[len(d)-i-1] = d[len(d)-i-1] + "c" for i in range(len(d)): d[i] = d[i] + "b"*(Y//X) for i in range(Y-(Y//X)*X): d[len(d)-i-1] = d[len(d)-i-1] + "b" elif Y > 0: if (Z) > 0: j = max(Y//Z, 1) else: j = 1 for _ in range(Y//j): d.append("b"*j) for i in range(Y-j*(Y//j)): d[i] = d[i] + "b" for i in range(len(d)): d[i] = d[i] + "c"*(Z//Y) for i in range(Z-(Z//Y)*Y): d[len(d)-i-1] = d[len(d)-i-1] + "c" else: for _ in range(Z): d.append("c") print("".join(d))
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples 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
$/=$";@_=sort(@_,(a)x<>,(b)x<>,(c)x<>),$_[0].=pop@_ while$#_;print@_
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples 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 i = 0; i < N; i++) Tmp[i + N] = Tmp[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 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; } 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); if (c % a == 0) { for (int i = (1); i <= (iter); i++) { strcpy(ua + pa, sc); pa += strlen(sc); strcpy(ub + pb, sc); pb += strlen(sc); strcpy(uc + pc, sc); pc += strlen(sc); } } else { for (int i = (1); i <= (iter); i++) { if (i < iter) { strcpy(ua + pa, sc); pa += strlen(sc); } if (i < iter) { 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); if (b % nab == 0) { for (int i = (1); i <= (iter); i++) { strcpy(ua + pa, sb); pa += strlen(sb); strcpy(ub + pb, sb); pb += strlen(sb); } } else { for (int i = (1); i <= (iter); i++) { if (i < iter) { 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; using ll = long long; template <int n, class... T> typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &, tuple<T...> const &) {} template <int n, class... T> typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os, tuple<T...> const &t) { os << (n == 0 ? "" : ", ") << get<n>(t); _ot<n + 1>(os, t); } template <class... T> ostream &operator<<(ostream &o, tuple<T...> const &t) { o << "("; _ot<0>(o, t); o << ")"; return o; } template <class T, class U> ostream &operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; } template <class T> ostream &operator<<(ostream &o, const stack<T> &a) { o << "{"; for (auto tmp = a; tmp.size(); tmp.pop()) o << (a.size() == tmp.size() ? "" : ", ") << tmp.top(); o << "}"; return o; } template <class T, class = typename iterator_traits<typename T::iterator>::value_type, class = typename enable_if<!is_same<T, string>::value>::type> ostream &operator<<(ostream &o, const T &a) { for (auto ite = a.begin(); ite != a.end(); ++ite) o << (ite == a.begin() ? "" : " ") << *ite; return o; } string dp[51][51][51]; using P = pair<string, int>; void sol(int x, int y, int z); string ch(vector<P> &v) { string res; sort((v).begin(), (v).end()); sol(v[0].second, v[1].second, v[2].second); string &str = dp[v[0].second][v[1].second][v[2].second]; for (auto &el : str) res += v[el - 'a'].first; return res; } void sol(int x, int y, int z) { if (dp[x][y][z] != "") return; if (x == 0 && y == 0) { dp[x][y][z] = string(z, 'c'); return; } if (y == 0 && z == 0) { dp[x][y][z] = string(x, 'a'); return; } if (z == 0 && x == 0) { dp[x][y][z] = string(y, 'b'); return; } string res; vector<P> xs{ {"a", x}, {"b", y}, {"c", z}, }; if (y != 0 && z != 0) { vector<P> v(3); v[0] = P("a", x); v[1] = P(y > z ? "b" : "c", abs(y - z)); v[2] = P("bc", min(y, z)); string it = ch(v); res = max(res, it); } { vector<P> v(3); if (x > y + z) { v[0] = P("ab", y); v[1] = P("ac", z); v[2] = P("a", x - y - z); res = max(res, ch(v)); } else if (x > 0) { v[0] = P("ac", z); v[1] = P("ab", max(0, x - z)); int restb = y - max(0, x - z); assert(restb >= 0); assert(z + max(0, x - z) >= 1); v[2] = P("b", restb); res = max(res, ch(v)); } } dp[x][y][z] = res; } int main() { std::ios::sync_with_stdio(false), std::cin.tie(0); int x, y, z; cin >> x >> y >> z; sol(2, 1, 1); (42); sol(x, y, z); cout << dp[x][y][z] << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
python2
def work(a,b,c,A,B,C): if A==0: return work(b,c,'',B,C,0) if B==0: if C==0: return a*A else: return work(a,c,'',A,C,0) if C==0: return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0) cmod = C%A bmod = B%(A-cmod) return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1),A-cmod-bmod,bmod,cmod) if __name__ == '__main__': s = raw_input() a,b,c = [int(i) for i in s.split()] print(work('a','b','c',a,b,c))
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
UNKNOWN
$/=$";$@[0].=pop@@while$#@and@@=sort@@,(a)x<>,(b)x<>,(c)x<>;print@@
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int X, Y, Z; cin >> X >> Y >> Z; string res = ""; while (X > 0 || Y > 0 || Z > 0) { if (X > 0) { if (Y > 0 || Z > 0) { res += 'a'; } else { res = 'a' + res; } X--; } if (Z > 0) { res += 'c'; Z--; } if (Y > 0) { res += 'b'; Y--; } } cout << res << 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; 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 + B + C == max(A, max(B, C))) { 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; } if (A == 1 || B == 1 || C == 1) { if (C == 1 && B != 1) { return solve(A, B, 0) + 'c'; } if (C != 1 && B == 1) { return solve(A, 0, C) + 'b'; } 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 wut = 0; if (A == 0) wut = 1; int ka = (A + 1) / 2; int kb = (B + wut) / 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; vector<char> v[100010]; int main() { int n, a, b, c; while (cin >> a >> b >> c) { if (c == 0) { int tmp = min(b, a); for (int i = 1; i <= tmp; ++i) { cout << "ab"; } for (int i = tmp + 1; i <= a; ++i) { cout << "a"; } for (int i = tmp + 1; i <= b; ++i) { cout << "b"; } cout << endl; } else if (b == 0) { int tmp = min(a, c); for (int i = 1; i <= tmp; ++i) { cout << "ac"; } for (int i = tmp + 1; i <= a; ++i) { cout << "a"; } for (int i = tmp + 1; i <= c; ++i) { cout << "c"; } cout << endl; } else if (a == 0) { int tmp = min(b, c); for (int i = 1; i <= tmp; ++i) { cout << "bc"; } for (int i = tmp + 1; i <= b; ++i) { cout << "b"; } for (int i = tmp + 1; i <= c; ++i) { cout << "c"; } cout << endl; } else { for (int i = 1; i <= a; ++i) v[i].clear(); int nm = 0; if (c >= a) { nm = a; int tmp = a; while (c--) { v[tmp].push_back('c'); --tmp; if (tmp == 0) tmp = a; } } else { nm = c; int tmp = nm; while (c--) { v[tmp].push_back('c'); --tmp; if (tmp == 0) tmp = nm; } } int tmp = nm; while (b--) { if (tmp == 0) tmp = nm; v[tmp].push_back('b'); --tmp; } if (a % nm == 0) { for (int i = 1; i <= nm; ++i) { for (int j = 0; j < a / nm; ++j) cout << "a"; for (int j = 0; j < v[i].size(); ++j) { cout << v[i][j]; } } } else { for (int i = 1; i < nm; ++i) { for (int j = 0; j < a / nm; ++j) cout << "a"; for (int j = 0; j < v[i].size(); ++j) { cout << v[i][j]; } } for (int j = 0; j < a % nm; ++j) cout << "a"; for (int j = 0; j < v[nm].size(); ++j) { cout << v[nm][j]; } } cout << endl; } } return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int A, B, C; std::string smallestRotateString(std::string s) { std::string result = ""; std::vector<int> indexList; { char smallestChar = 'z'; for (int i = 0; i < s.length(); i++) { if (s[i] < smallestChar) smallestChar = s[i]; } for (int i = 0; i < s.length(); i++) { if (s[i] == smallestChar) indexList.push_back(i); } result += smallestChar; } for (int p = 1; p < s.length(); p++) { for (int i = 0; i < indexList.size(); i++) { indexList[i] = (indexList[i] + 1) % s.length(); } char smallestChar = 'z'; for (int k = 0; k < indexList.size(); k++) { int idx = indexList[k]; if (s[idx] < smallestChar) smallestChar = s[idx]; } result += smallestChar; std::vector<int>::iterator it = indexList.begin(); while (it != indexList.end()) { if (s[*it] != smallestChar) { it = indexList.erase(it); } else ++it; } } return result; } int main(int argc, char* argv[]) { std::string best = ""; std::cin >> A >> B >> C; for (int i = 0; i < A; i++) best += 'a'; for (int i = 0; i < B; i++) best += 'b'; for (int i = 0; i < C; i++) best += 'c'; for (int p = 1; p < best.length() - 1; p++) { std::string tmp = best; char from = tmp[p]; if (from <= 'a') { char to = 'b'; for (int i = p + 1; i < tmp.length(); i++) { if (tmp[i] == to) { tmp[p] = to; tmp[i] = from; std::string ret = smallestRotateString(tmp); tmp[p] = from; tmp[i] = to; if (best.compare(ret) < 0) { best = ret; } } } } if (from <= 'b') { char to = 'c'; for (int i = p + 1; i < tmp.length(); i++) { if (tmp[i] == to) { tmp[p] = to; tmp[i] = from; std::string ret = smallestRotateString(tmp); tmp[p] = from; tmp[i] = to; if (best.compare(ret) < 0) { best = ret; } } } } } std::cout << best << std::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 n; int x, y, z; string ans; bool check(string s) { int rem[3] = {x, y, z}; int p = 0; string t = s; for (int i = 0; i < n; i++) { int c = t[p] - 'a', f = -1; for (int j = c; j < 3; j++) { if (rem[j]) { rem[j]--; f = j; break; } } if (f == -1) return false; if (f > c) { t[p] = (char)('a' + f); t.erase(t.begin() + p + 1, t.end()); } p++; if (p >= t.size()) p = 0; } if (p != 0) return t.substr(p) <= s; else return true; } int main(void) { cin >> x >> y >> z; n = x + y + z; for (int i = 0; i < n; i++) { for (int j = 2; j >= 0; j--) { string s = ans + ((char)('a' + j)); if (check(s)) { ans = s; break; } } } cout << ans << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using 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) { for (int i = 1; i <= x; ++i) cout << a; 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; 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; int ty = y, tz = z; if (q > 1) { ty -= (y + z - r); if (ty < 0) tz += ty, ty = 0; } for (int i = 0; i < q; i++) ret.push_back('a'); for (int i = 0; i < tz / r; i++) ret.push_back('c'); for (int i = 0; i < ty / (r - tz % r); i++) ret.push_back('b'); return ret += f(x - q, y - ty / (r - tz % r), z - tz / 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> 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 < 1000; 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 ma; } int main() { int A, B, C; cin >> A >> B >> C; string ma = ""; for (int t = 0; t < 500; 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; 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; } 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<cstdio> int main(){ int x,y,z; scanf("%d%d%d",&x,&y,&z); int b[x]={}; int c[x]={}; if(x!=0){ if(x>y+z){ for(int i=x-1;i>=x-y;i--){ b[i]++; } for(int i=x-y-1;i>=x-y-z;i--){ c[i]++; } }else if(x==y+z){ for(int i=x-1;i>=x-z;i--){ c[i]++; } for(int i=x-z-1;i>=0;i--){ b[i]++; } }else{ if(x<=z){ if(z%x==0){ for(int i=0;i<x;i++){ c[i]+=z/x; } for(int i=0;i<x;i++){ b[i]+=y/x; } for(int i=x-1;i>=x-y%x;i--){ b[i]++; } }else{ for(int i=0;i<x;i++){ c[i]+=z/x; } for(int i=x-1;i>=x-z%x;i--){ c[i]++; } int k=x-z%x; for(int i=0;i<k;i++){ b[i]+=y/k; } for(int i=0;i<y%k;i--){ b[i]++; } } }else{ for(int i=x-1;i>=x-z;i--){ c[i]++; } int k=x-z; for(int i=0;i<k;i++){ b[i]+=x/k; } for(int i=k-1;i>=k-x%k;i--){ b[i]++; } } } for(int i=0;i<x;i++){ printf("a"); for(int j=0;j<c[i];j++){ printf("c"); } for(int j=0;j<b[i];j++){ printf("b"); } } }else if(y!=0){ if(z==0){ for(int i=0;i<y;i++){ printf("b"); } } if(y>z){ for(int i=0;i<z;i++){ printf("c"); for(int j=0;j<y/z;j++){ printf("b"); } if(i<y%z)printf("c"); } }else{ for(int i=0;i<z;i++){ printf("c"); if(i<y)printf("b"); } } }else{ for(int i=0;i<z;i++){ printf("c"); } } if(z==0){ for(int i=0;i<y-x;i++){ 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 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 (z > 0) { v[i] += 'a'; z--; } else if (y > 0) { v[i] += 'b'; y--; } else if (x > 0) { v[i] += 'c'; 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; using ll = long long; using ld = long double; signed main() { int x, y, z; cin >> x >> y >> z; vector<int> cs, bs; if (x == 0) { if (y == 0) { cout << string(z, 'c') << '\n'; } else { for (int i = 0; i < y; ++i) { cs.push_back((z + i) / y); } for (int i = 0; i < y; ++i) { cout << 'b'; for (int j = 0; j < cs[i]; ++j) { cout << 'c'; } } cout << '\n'; } } else { for (int i = 0; i < x; ++i) { cs.push_back((z + i) / x); } int rem = x - z % x; for (int i = 0; i < rem; ++i) { bs.push_back((y + i) / rem); } bs.resize(int(cs.size())); for (int i = 0; i < x; ++i) { cout << 'a'; for (int j = 0; j < cs[i]; ++j) { cout << 'c'; } for (int j = 0; j < bs[i]; ++j) { cout << 'b'; } } cout << '\n'; } }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; if (x == 0 && y == 0) { for (int i = 0; i < z; i++) { cout << "c"; } cout << endl; } else if (x == 0 && y <= z) { int t; t = z / y; for (int i = 0; i < y - 1; i++) { cout << "b"; for (int j = 0; j < t; j++) { cout << "c"; } } cout << "b"; for (int k = 0; k < z - t * (y - 1); k++) { cout << "c"; } cout << endl; } else if (x == 0) { int t; t = y / z; for (int i = 0; i < y - t * (z - 1); i++) { cout << "b"; } cout << "c"; for (int j = 0; j < z - 1; j++) { for (int k = 0; k < t; k++) { cout << "b"; } cout << "c"; } cout << endl; } else if (x <= z && x <= y) { int t, u; t = z / x; u = y / x; for (int i = 0; i < x - 1; i++) { cout << "a"; for (int j = 0; j < t; j++) { cout << "c"; } for (int k = 0; k < u; k++) { cout << "b"; } } cout << "a"; for (int l = 0; l < z - t * (x - 1); l++) { cout << "c"; } for (int m = 0; m < y - u * (x - 1); m++) { cout << "b"; } cout << endl; } else if (x <= z) { int t; t = z / x; for (int i = 0; i < x - y - 1; i++) { cout << "a"; for (int j = 0; j < t; j++) { cout << "c"; } } cout << "a"; for (int k = 0; k < z - t * (x - 1); k++) { cout << "c"; } for (int l = 0; l < y; l++) { cout << "a"; for (int m = 0; m < t; m++) { cout << "c"; } cout << "b"; } 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; 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 ma; } 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; 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; 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; } } if (ppp) { id = i; } } if (id != -1) { 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
python3
X, Y, Z = map(int, input().split()) d = [] if X > 0: for _ in range(X): d.append("a") for i in range(len(d)): d[i] = d[i] + "c"*(Z//X) for i in range(Z-(Z//X)*X): d[len(d)-i-1] = d[len(d)-i-1] + "c" for i in range(len(d)): d[i] = d[i] + "b"*(Y//X) for i in range(Y-(Y//X)*X): d[len(d)-i-1] = d[len(d)-i-1] + "b" elif Y > 0: for _ in range(Y): d.append("b") for i in range(len(d)): d[i] = d[i] + "c"*(Z//Y) for i in range(Z-(Z//Y)*Y): d[len(d)-i-1] = d[len(d)-i-1] + "c" else: for _ in range(Z): d.append("c") print("".join(d))
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples 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> int A, B, C; std::string smallestRotateString(std::string s) { std::string result = ""; std::vector<int> indexList; { char smallestChar = 'z'; for (int i = 0; i < s.length(); i++) { if (s[i] < smallestChar) smallestChar = s[i]; } for (int i = 0; i < s.length(); i++) { if (s[i] == smallestChar) indexList.push_back(i); } result += smallestChar; } for (int p = 1; p < s.length(); p++) { for (int i = 0; i < indexList.size(); i++) { indexList[i] = (indexList[i] + 1) % s.length(); } char smallestChar = 'z'; for (int k = 0; k < indexList.size(); k++) { int idx = indexList[k]; if (s[idx] < smallestChar) smallestChar = s[idx]; } result += smallestChar; std::vector<int>::iterator it = indexList.begin(); while (it != indexList.end()) { if (s[*it] != smallestChar) { it = indexList.erase(it); } else ++it; } } return result; } std::vector<char> perm; int main(int argc, char* argv[]) { std::cin >> A >> B >> C; for (int i = 0; i < A; i++) perm.push_back('a'); for (int i = 0; i < B; i++) perm.push_back('b'); for (int i = 0; i < C; i++) perm.push_back('c'); std::string best(perm.begin(), perm.end()); best = smallestRotateString(best); do { std::string tmp(perm.begin(), perm.end()); std::string ret = smallestRotateString(tmp); if (best.compare(ret) < 0) { best = ret; } if (best.compare(tmp) < 0) break; } while (next_permutation(perm.begin(), perm.end())); std::cout << best << std::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<cstdio> int main(){ int x,y,z; scanf("%d%d%d",&x,&y,&z); int b[x]={}; int c[x]={}; if(x!=0){ if(x>y+z){ for(int i=x-1;i>=x-y;i--){ b[i]++; } for(int i=x-y-1;i>=x-y-z;i--){ c[i]++; } }else if(x==y+z){ for(int i=x-1;i>=x-z;i--){ c[i]++; } for(int i=x-z-1;i>=0;i--){ b[i]++; } }else{ if(x<=z){ if(z%x==0){ for(int i=0;i<x;i++){ c[i]+=z/x; } for(int i=0;i<x;i++){ b[i]+=y/x; } for(int i=x-1;i>=x-y%x;i--){ b[i]++; } }else{ for(int i=0;i<x;i++){ c[i]+=z/x; } for(int i=x-1;i>=x-z%x;i--){ c[i]++; } int k=x-z%x; for(int i=0;i<k;i++){ b[i]+=y/k; } for(int i=0;i<y%k;i--){ b[i]++; } } }else{ for(int i=x-1;i>=x-z;i--){ c[i]++; } int k=x-z; for(int i=0;i<k;i++){ b[i]+=x/k; } for(int i=k-1;i>=k-x%k;i--){ b[i]++; } } } for(int i=0;i<x;i++){ printf("a"); for(int j=0;j<c[i];j++){ printf("c"); } for(int j=0;j<b[i];j++){ printf("b"); } } }else if(y!=0){ if(z==0){ for(int i=0;i<y;i++){ printf("b"); } } if(y>z){ for(int i=0;i<z;i++){ printf("c"); for(int j=0;j<y/z;j++){ printf("b"); } if(i<y%z)printf("c"); } }else{ for(int i=0;i<z;i++){ printf("c"); if(i<y)printf("b"); } } }else{ for(int i=0;i<z;i++){ printf("c"); } } if(x<y && z==0){ for(int i=0;i<y-x;i++){ 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; inline int read(register int ans = 0, register int sgn = ' ', register int ch = getchar()) { for (; ch < '0' || ch > '9'; sgn = ch, ch = getchar()) ; for (; ch >= '0' && ch <= '9'; (ans *= 10) += ch - '0', ch = getchar()) ; return sgn - '-' ? ans : -ans; } multiset<string> s; int X, Y, Z; string L, T = "\0"; int main() { X = read(), Y = read(), Z = read(); for (register int i = 1; i <= X; s.insert("a"), i++) ; for (register int i = 1; i <= Y; s.insert("b"), i++) ; for (register int i = 1; i <= Z; s.insert("c"), i++) ; for (; s.size() >= 2; L = *s.begin() + *--s.end(), s.erase(s.begin()), s.erase(--s.end()), s.insert(L)) ; if (s.size()) T = *s.begin(); cerr << T; 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; struct hash { unsigned long long pow(unsigned long long a, unsigned long long b) { unsigned long long res = 1; while (b) { if (b & 1) res = (res * a); a = (a * a); b >>= 1; } return res; } static const unsigned long long base = 31; static const unsigned long long in_base = 17256631552825064415ull; static const int maxn = 1e5 + 7; unsigned long long p[maxn], inv[maxn], n, h[maxn]; bool is_cal = 0; string s; void init(string str) { s = str; n = s.size(); s = "#" + str; if (!is_cal) { is_cal = 1; p[0] = 1; inv[0] = 1; for (int i = 1; i < maxn; i++) { p[i] = (p[i - 1] * base); inv[i] = (inv[i - 1] * in_base); } } h[0] = 0; unsigned long long c = 1; for (int i = 1; i <= n; i++, c = (c * base)) { h[i] = (h[i - 1] + c * s[i]); } } unsigned long long get(int l, int r) { if (l <= r) { return (h[r] - h[l - 1]) * inv[l - 1]; } else { unsigned long long a = get(l, n); unsigned long long b = get(1, r); return (b * p[n - l + 1] + a); } } } h; bool comp(int i, int j) { int n = h.n; int l = 0, r = n - 1, an = -1; while (l <= r) { int m = l + r >> 1; if (h.get(i, (i + m <= n ? i + m : i + m - n)) == h.get(j, (j + m <= n ? j + m : j + m - n))) { an = m; l = m + 1; } else { r = m - 1; } } if (an == n - 1) return i < j; an++; return h.s[(i + an <= n ? i + an : i + an - n)] <= h.s[(j + an <= n ? j + an : j + an - n)]; } int main() { int a, b, c; cin >> a >> b >> c; string s; while (a > 0 || b > 0 || c > 0) { if (a) s += "a", a--; if (c) s += "c", c--; if (b) s += "b", b--; } vector<int> v; for (int i = 0; i < s.size(); i++) v.push_back(i + 1); h.init(s); sort(v.begin(), v.end(), comp); a = v[0] - 1; cout << s.substr(a, h.n - a) + s.substr(0, 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; const long long mod = 1000000007; const long long inf = mod * mod; const long long d2 = 500000004; const double EPS = 1e-6; const double PI = acos(-1.0); int ABS(int a) { return max(a, -a); } long long ABS(long long a) { return max(a, -a); } int C[1100]; int B[1100]; int ad = 0; void f(int a, int b, int c) { ad = 0; for (int i = 0; i < 1100; i++) B[i] = C[i] = 0; while (a == 0) { a = b; b = c; c = 0; ad++; } for (int i = 0; i < c; i++) { C[i % a]++; } if (C[0] != C[a - 1]) { int f = 0; for (int i = 0; i < a; i++) if (C[a - 1] == C[i]) f++; for (int i = 0; i < b; i++) { B[a - f + i % f]++; } } else { for (int i = 0; i < b; i++) { B[i % a]++; } } for (int i = a - 1; i >= 0; i--) { printf("%c", 'a' + ad); for (int j = 0; j < C[i]; j++) printf("%c", 'c' + ad); for (int j = 0; j < B[i]; j++) printf("%c", 'b' + ad); } printf("\n"); } int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); f(a, b, c); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int MX = 1000; char ans[MX][MX]; void solve2(int x, int y, int p) { if (x == 0) { for (int i = 0; i < y; i++) ans[p][i] = 'b'; } else if (y == 0) { for (int i = 0; i < x; i++) ans[p][i] = 'a'; } else if (x >= y) { int g = (x + y - 1) / y; int f = x % y; if (f == 0) f = y; solve2(f, y - f, p + 1); for (int i = 0, j = 0; i < y; i++) { for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a'; if (ans[p + 1][i] == 'a') ans[p][j++] = 'a'; ans[p][j++] = 'b'; } } else { int g = (x + y - 1) / x; int f = y % x; if (f == 0) f = x; solve2(x - f, f, p + 1); for (int i = 0, j = 0; i < x; i++) { ans[p][j++] = 'a'; for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'b'; if (ans[p + 1][i] == 'b') ans[p][j++] = 'b'; } } } void solve(int x, int y, int z, int p = 0) { if (x == 0) { solve2(y, z, p); for (int i = 0; i < y + z; i++) ans[p][i]++; } else if (y == 0) { solve2(x, z, p); for (int i = 0; i < x + z; i++) if (ans[p][i] == 'b') ans[p][i] = 'c'; } else if (z == 0) { solve2(x, y, p); } else if (x >= y + z) { int g = (x + y + z - 1) / (y + z); int f = x % (y + z); if (f == 0) f = y + z; if (z >= f) { solve(f, y, z - f, p + 1); for (int i = 0, j = 0; i < y + z; i++) { for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a'; if (ans[p + 1][i] == 'a') { ans[p][j++] = 'a'; ans[p][j++] = 'c'; } else { ans[p][j++] = ans[p + 1][i]; } } } else { solve(f - z, z, y + z - f, p + 1); for (int i = 0, j = 0; i < y + z; i++) { for (int k = 0; k < g - 1; k++, j++) ans[p][j] = 'a'; if (ans[p + 1][i] == 'c') { ans[p][j++] = 'b'; } else { ans[p][j++] = 'a'; ans[p][j++] = ans[p + 1][i] + 1; } } } } else { static string S[MX]; for (int i = 0; i < x; i++) S[i] = "a"; for (int i = 0; i < z; i++) S[i % x] += "c"; for (int i = 0; i < y; i++) S[x - 1 - i % x] += "b"; set<string> strs; for (int i = 0; i < x; i++) strs.insert(S[i]); string SS[3]; int cnt[3] = {0, 0, 0}, iter = 0; for (auto& s : strs) { SS[iter] = s; cnt[iter] = 0; for (int i = 0; i < x; i++) if (S[i] == s) cnt[iter]++; iter++; } solve(cnt[0], cnt[1], cnt[2], p + 1); for (int i = 0, j = 0; i < x; i++) for (char c : SS[ans[p + 1][i] - 'a']) ans[p][j++] = c; } } int main() { int x, y, z; ignore = scanf("%d %d %d", &x, &y, &z); solve(x, y, z); ans[0][x + y + z] = 0; printf("%s\n", ans[0]); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int A, B, C; vector<string> vec; string maxn = ""; void dfs(vector<string> V, string S) { if (V.size() == 0) { string G = S; for (int i = 0; i < S.size(); i++) { string I = ""; for (int j = 0; j < S.size(); j++) I += S[(i + j) % S.size()]; G = min(G, I); } maxn = max(maxn, G); return; } for (int i = 0; i < V.size(); i++) { if (i >= 1 && V[i] == V[i - 1]) continue; vector<string> Z; for (int j = 0; j < V.size(); j++) { if (i != j) Z.push_back(V[j]); } string ZZ = S + V[i]; dfs(Z, ZZ); } } int main() { cin >> A >> B >> C; while (A == 0) { A = B; B = C; C = 0; } for (int i = 0; i < A; i++) vec.push_back("a"); for (int i = 0; i < C; i++) vec[i % A] += "c"; sort(vec.begin(), vec.end()); int Z = 0; for (int i = 0; i < vec.size() - 1; i++) { if (vec[i] == vec[i + 1]) Z = i + 2; } for (int i = 0; i < B; i++) vec[i % Z] += "b"; sort(vec.begin(), vec.end()); dfs(vec, ""); cout << maxn << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = mod * mod; const long long d2 = 500000004; const double EPS = 1e-6; const double PI = acos(-1.0); int ABS(int a) { return max(a, -a); } long long ABS(long long a) { return max(a, -a); } int C[1100]; int B[1100]; int ad = 0; int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); while (a == 0) { a = b; b = c; c = 0; ad++; } for (int i = 0; i < c; i++) { C[i % a]++; } if (C[0] != C[a - 1]) { int f = 0; for (int i = 0; i < a; i++) if (C[a - 1] == C[i]) f++; for (int i = 0; i < b; i++) { B[a - f + i % f]++; } } else { for (int i = 0; i < b; i++) { B[i % a]++; } } for (int i = a - 1; i >= 0; i--) { printf("%c", 'a' + ad); for (int j = 0; j < C[i]; j++) printf("%c", 'c' + ad); for (int j = 0; j < B[i]; j++) printf("%c", 'b' + ad); } printf("\n"); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int duval(string s) { int n = s.length(); s += s; int i = 0, ans = 0; while (i < n) { ans = i; int j = i + 1, k = i; while (j < n + n && s[k] <= s[j]) { if (s[k] < s[j]) { k = i; } else { k++; } j++; } while (i <= k) { i += j - k; } } return ans; } string res; void solve(vector<pair<string, int> > &v, const string &cur) { bool any = false; for (auto &p : v) { if (p.second == 0) { continue; } any = true; p.second--; solve(v, cur + p.first); p.second++; } if (!any) { int pos = duval(cur); string shift = cur.substr(pos) + cur.substr(0, pos); res = min(res, shift); } } int main() { int a, b, c; scanf("%d %d %d", &a, &b, &c); bool flag = false; if (a == 0) { flag = true; a = b; b = c; c = 0; } res = ""; if (a == 0) { res = string(b, 'b'); } else { vector<string> put(a, "a"); for (int i = 0; i < c; i++) { put[i % a] += 'c'; } int ptr = c % a; for (int i = 0; i < b; i++) { put[ptr] += 'b'; ptr++; if (ptr == a) { ptr = c % a; } } map<string, int> mp; for (auto &s : put) { mp[s]++; } vector<pair<string, int> > v; for (auto &p : mp) { v.push_back(p); } res = "d"; solve(v, ""); } if (flag) { for (char &c : res) { c++; } } cout << res << 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
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author Gosu_Hiroo */ #include <iostream> #include <fstream> #include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef int #define V2(v,size_1, size_2, value) vector<vector<long long>>v(size_1, vector<long long>(size_2, value)) #define V3(v,size_1,size_2,size_3,value) vector<vector<vector<long long>>>v(size_1,vector<vector<long long>>(size_2,vector<long long>(size_3, value))) #define VI vector<long long> #define G(g,size_1) vector<vector<long long>>g(size_1, vector<long long>()) #define VVI vector<vector<long long>> #define VVVI vector<vector<vector<long long>>> #define SZ(x) ((long long)(x).size()) #define READ ({long long t;cin >> t;t;}) #define PII pair<long long, long long> #else #define V2(v,size_1, size_2, value) vector<vector<int>>v(size_1, vector<int>(size_2, value)) #define V3(v,size_1,size_2,size_3,value) vector<vector<vector<int>>>v(size_1,vector<vector<int>>(size_2,vector<int>(size_3, value))) #define VI vector<int> #define G(g,size_1) vector<vector<int>>g(size_1, vector<int>()) #define SZ(x) ((int)(x).size()) #define VVI vector<vector<int>> #define VVVI vector<vector<vector<int>>> #define READ ({int t;cin >> t;t;}) #define PII pair<int, int> #endif #define VM2(v,size_1, size_2, value) vector<vector<mint>>v(size_1, vector<mint>(size_2, value)) #define VM3(v,size_1,size_2,size_3,value) vector<vector<vector<mint>>>v(size_1,vector<vector<mint>>(size_2,vector<mint>(size_3, value))) #define VM vector<mint> #define VVM vector<vector<mint>> #define VVVM vector<vector<vector<mint>>> #define TR(container, it) \ for (auto it = container.begin(); it != container.end(); it++) #define IN(c, x) ((c).find(x) != (c).end()) //O(log n) #define IN_L(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n) #define FOR(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin, i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define REP(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1) #define ALL(x) (x).begin(),(x).end() #define F first #define S second #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define MOD(x, m) ((((x) % (m)) + (m)) % (m)) #define BIT(n) (1LL<<(n)) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); #define EB emplace_back #define PB push_back #define fcout cout << fixed << setprecision(12) #define fcerr cerr << fixed << setprecision(12) #define print(x) cout << (x) << endl # define BYE(a) do { cout << (a) << endl; return ; } while (false) #ifdef DEBUG #define ERR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); _err(cerr,_it, args); } #define DBG(x) cerr << #x << " is " << x << endl; #else #define DBG(x) {}; #define ERR(args...) {}; #endif void _err(std::ostream& cerr,istream_iterator<string> it) {cerr << endl;} template<typename T, typename... Args> void _err(std::ostream& cerr, istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; _err(cerr,++it, args...); } const double pi = 2 * acos(.0); const int inf = 0x3f3f3f3f; const ll mod = (ll) (1e9) + 7; //const ll mod = (ll) 998244353 ; const double eps = 1e-10; 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 <typename T> ostream& operator << (ostream& os, const vector<T> V) { os << "["; int cnt = 0; T curr; if(!V.empty()){ for (int i = 0; i < V.size() - 1; ++i) { if(V[i] == curr)cnt ++; else cnt = 0; if(cnt == 4)os << "... "; if(cnt < 4) os << V[i] << " "; curr = V[i]; } os << V.back(); } os << "]"; return os; } template <typename T, typename U> ostream& operator << (ostream& os, const pair<T,U> P) { os << "("; os << P.first << "," << P.second; os << ")"; return os; } template <typename T, typename U> ostream& operator << (ostream& os, const set<T,U> V) { os << "{"; if(!V.empty()){ auto it = V.begin(); for (int i = 0; i < V.size() -1; ++i) { os << *it << " "; it++; } os << *it; } os << "}"; return os; } template <typename K, typename H, typename P> ostream& operator << (ostream& os, const unordered_set<K, H, P> V) { os << "{"; if(!V.empty()){ auto it = V.begin(); for (int i = 0; i < V.size() -1; ++i) { os << *it << " "; it++; } os << *it; } os << "}"; return os; } template <typename K, typename C> ostream& operator << (ostream& os, const multiset<K, C> V) { os << "{"; if(!V.empty()){ auto it = V.begin(); for (int i = 0; i < V.size() -1; ++i) { os << *it << " "; it++; } os << *it; } os << "}"; return os; } template <typename K, typename T, typename C> ostream& operator << (ostream& os, const map<K,T,C> V) { os << "{"; if(!V.empty()){ auto it = V.begin(); for (int i = 0; i < V.size() -1; ++i) { os << "("; os << it->first << "," << it->second; os << ") "; it++; } os << "("; os << it->first << "," << it->second; os << ")"; } os << "}"; return os; } template <typename K, typename T, typename C> ostream& operator << (ostream& os, const unordered_map<K,T,C> V) { os << "{"; if(!V.empty()){ auto it = V.begin(); for (int i = 0; i < V.size() -1; ++i) { os << "("; os << it->first << "," << it->second; os << ") "; it++; } os << "("; os << it->first << "," << it->second; os << ")"; } os << "}"; return os; } template <typename T> ostream& operator << (ostream& os, const deque<T> V) { os << "["; if (!V.empty()) { for (int i = 0; i < V.size() - 1; ++i) { os << V[i] << "->"; } if (!V.empty())os << V.back(); } os << "]"; return os; }; template <typename T, typename Cont, typename Comp> ostream& operator << (ostream& os, const priority_queue<T, Cont, Comp> V) { priority_queue<T, Cont, Comp> _V = V; os << "["; if(!_V.empty()){ while(_V.size() > 1){ os << _V.top() << "->"; _V.pop(); } os << _V.top(); } os << "]"; return os; }; template <class F> struct y_combinator { F f; // the lambda will be stored here // a forwarding operator(): template <class... Args> decltype(auto) operator()(Args&&... args) const { // we pass ourselves to f, then the arguments. // the lambda should take the first argument as `auto&& recurse` or similar. return f(*this, std::forward<Args>(args)...); } }; // helper function that deduces the type of the lambda: template <class F> y_combinator<std::decay_t<F>> recursive(F&& f){ return {std::forward<F>(f)}; } struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; /* struct X{ int x,y,id; bool operator < (const X R)const{ return id < R.id; } friend ostream& operator << (ostream& os, X R){ os << "(" << R.x << "," << R.y << "," << R.id << ")"; } friend bool operator == (const X L, const X R){ return L.id == R.id; } */ template<class T>void Chmod(T &a, const T &m) {a = MOD(a, m);} template<class T>bool Chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool Chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } //256MB = 2^29(~5.3*10^8)*sizeof(int) //#define int ll //2^31=2.15*10^9, 2^63=9.22*10^18 class FLargestSmallestCyclicShift { public: void solve(std::istream& cin, std::ostream& cout, std::ostream& cerr) { int X, Y, Z; cin >> X >> Y >> Z; string dp[X+5][Y+5][Z+5] = {}; dp[0][0][0] = ""; auto mi_str = [&](string& _s, string c){ string mx = ""; REP(i,SZ(_s)){ string s = _s.substr(0,i) + c + _s.substr(i); string mi = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; REP(j,SZ(s))Chmin(mi, s.substr(j) + s.substr(0,j)); Chmax(mx, mi); } if(SZ(_s) == 0)return (c); ERR(_s, c, mx) return mx; }; REP(x,X+1)REP(y,Y+1)REP(z,Z+1){ Chmax(dp[x+1][y][z], mi_str(dp[x][y][z], "a")); Chmax(dp[x][y+1][z], mi_str(dp[x][y][z], "b")); Chmax(dp[x][y][z+1], mi_str(dp[x][y][z], "c")); } print(dp[X][Y][Z]); } }; #undef int int main() { FLargestSmallestCyclicShift solver; std::istream& in(std::cin); std::ostream& out(std::cout); std::ostringstream err; in.tie(0); ios::sync_with_stdio(0); // solver.solve(in, out); solver.solve(in, out,err); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = mod * mod; const long long d2 = 500000004; const double EPS = 1e-6; const double PI = acos(-1.0); int ABS(int a) { return max(a, -a); } long long ABS(long long a) { return max(a, -a); } int C[1100]; int B[1100]; int ad = 0; vector<string> str; void f(string aa, string bb, string cc, int a, int b, int c) { if (a == 0) { f(bb, cc, "", b, c, 0); return; } if (b + c == 0) { for (int i = 0; i < a; i++) printf("%s", aa.c_str()); printf("\n"); return; } ad = 0; for (int i = 0; i < 1100; i++) B[i] = C[i] = 0; while (a == 0) { a = b; b = c; c = 0; ad++; } for (int i = 0; i < c; i++) { C[i % a]++; } if (C[0] != C[a - 1]) { int f = 0; for (int i = 0; i < a; i++) if (C[a - 1] == C[i]) f++; for (int i = 0; i < b; i++) { B[a - f + i % f]++; } } else { for (int i = 0; i < b; i++) { B[i % a]++; } } str.clear(); for (int i = a - 1; i >= 0; i--) { string tmp = ""; tmp += 'a' + ad; for (int j = 0; j < C[i]; j++) tmp += 'c' + ad; for (int j = 0; j < B[i]; j++) tmp += 'b' + ad; str.push_back(tmp); } string ta = "", tb = "", tc = ""; int va = 0; int vb = 0; int vc = 0; int fi = 0; int ph = 0; for (int i = 0; i < a; i++) { if (str[i] == str[fi]) { if (ph == 0) { va++; ta = str[i]; } if (ph == 1) { vb++; tb = str[i]; } if (ph == 2) { vc++; tc = str[i]; } } else { if (ph == 0) { ph++; vb++; tb = str[i]; fi = i; } if (ph == 1) { ph++; vc++; tc = str[i]; fi = i; } } } f(ta, tb, tc, va, vb, vc); } int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); f("a", "b", "c", a, b, c); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples 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; } int main() { cin >> A >> B >> C; int P = 0; while (A == 0) { A = B; B = C; C = 0; P++; } 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] += P; 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
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+1),a+b*(B/A),'',B%A,A-B%A,0) cmod = C%A bmod = B%A if cmod+bmod<=A: return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),A-cmod-bmod,bmod,cmod) else: return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),bmod,cmod,bmod+cmod-A) if __name__ == '__main__': s = raw_input() a,b,c = [int(i) for i in s.split()] print(work('a','b','c',a,b,c))
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = mod * mod; const long long d2 = 500000004; const double EPS = 1e-6; const double PI = acos(-1.0); int ABS(int a) { return max(a, -a); } long long ABS(long long a) { return max(a, -a); } int C[1100]; int B[1100]; int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); for (int i = 0; i < c; i++) { C[i % a]++; } if (C[0] != C[a - 1]) { int f = 0; for (int i = 0; i < a; i++) if (C[a - 1] == C[i]) f++; for (int i = 0; i < b; i++) { B[a - f + i % f]++; } } else { for (int i = 0; i < b; i++) { B[i % a]++; } } for (int i = a - 1; i >= 0; 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"); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples 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 + 1; 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; string ans; int x, y, z; void dfs(int a, int b, int c, string x, string y, string z) { if (a == 0) dfs(b, c, 0, y, z, ""); else if (c == 0 && b == 0) { for (int i = 1; i <= a; i++) ans += x; } else { string ra = x, rb, rc; for (int i = 0; i < c / a; i++) ra += z; rc = ra + z; int rrc = c % a; a -= (c % a); for (int i = 0; i < b / a; i++) ra += y; rb = ra + y; int rrb = b % 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
cpp
#include <bits/stdc++.h> using namespace std; template <class BidirectionalIterator> bool next_combination(BidirectionalIterator first1, BidirectionalIterator last1, BidirectionalIterator first2, BidirectionalIterator last2) { if ((first1 == last1) || (first2 == last2)) return false; BidirectionalIterator m1 = last1; BidirectionalIterator m2 = last2; --m2; while (--m1 != first1 && !(*m1 < *m2)) ; bool result = (m1 == first1) && !(*first1 < *m2); if (!result) { while (first2 != m2 && !(*m1 < *first2)) ++first2; first1 = m1; std::iter_swap(first1, first2); ++first1; ++first2; } if ((first1 != last1) && (first2 != last2)) { m1 = last1; m2 = first2; while ((m1 != first1) && (m2 != last2)) { std::iter_swap(--m1, m2); ++m2; } std::reverse(first1, m1); std::reverse(first1, last1); std::reverse(m2, last2); std::reverse(first2, last2); } return !result; } template <class BidirectionalIterator> bool next_combination(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last) { return next_combination(first, middle, middle, last); } template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { os << "["; for (int i = 0; i < vec.size(); i++) { os << vec[i] << ","; } os << "]"; return os; } template <typename T> T input() { T t; cin >> t; return t; } template <typename T> vector<T> input(const int N) { vector<T> v(N); for (int i = 0; i < static_cast<int>(N); i++) cin >> v[i]; return v; } long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } int main() { int X, Y, Z; cin >> X >> Y >> Z; string str; for (int i = 0; i < static_cast<int>(X); i++) { str += 'a'; } for (int i = 0; i < static_cast<int>(Y); i++) { str += 'b'; } for (int i = 0; i < static_cast<int>(Z); i++) { str += 'c'; } string best = str; string temp; string temp_small; map<string, string> result; do { if (result.find(str) != result.end()) { continue; } temp = str; temp_small = str; int size = str.size(); for (int i = 0; i < static_cast<int>(size - 1); i++) { temp = temp.substr(1, temp.size()) + temp[0]; if (result.find(temp) != result.end()) { break; } if (temp < temp_small) { temp_small = temp; } } if (result.find(temp) != result.end()) { continue; } result[str] = str; if (best < temp_small) { best = temp_small; } } while (next_permutation(str.begin(), str.end())); cout << best << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
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); } } 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> inline int getint() { register char ch; while(!isdigit(ch=getchar())); register int x=ch^'0'; while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0'); return x; } int main() { for(register int i=getint();i;i--) set.insert("a"); for(register int i=getint();i;i--) set.insert("b"); for(register int i=getint();i;i--) set.insert("c"); while(set.size()>1) { std::string s=*set.begin(),t=*set.rbegin(); set.erase(set.lower_bound(s)); set.erase(set.lower_bound(t)); set.insert(s+t); } printf("%s\n",(*set.begin()).c_str()); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int X, Y, Z; cin >> X >> Y >> Z; string res = ""; while (X > 0 || Y > 0 || Z > 0) { if (X > 0) { res = 'a' + res; X--; } if (Z > 0) { res += 'c'; Z--; } if (Y > 0) { res += 'b'; Y--; } } cout << res << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f2f1f0f; const long long LINF = 1ll * INF * INF; const int MAX_N = 1e2; int N, Ns[3], Now[MAX_N], Ans[MAX_N], AnsN[3]; int main() { cin >> Ns[0] >> Ns[1] >> Ns[2]; for (int k = 0; k < 3; k++) N += Ns[k]; for (int k = 0; k < 3; k++) AnsN[k] = Ns[k]; for (int s = 0; s < N; s++) { bool isFinish = false; for (int o = 2; o >= 0; o--) if (isFinish == false && AnsN[o] > 0) { bool isCan = true; Ans[s] = o; int cnt[3]; for (int k = 0; k < 3; k++) cnt[k] = Ns[k]; int en = N / (s + 1) * (s + 1); for (int p = 0; p < N;) { bool mustUp = true; int np = p + (s + 1); for (int is = 0; is < (s + 1) && p + is < N; is++) { bool findWell = false; int start = Ans[is]; for (int k = start; k < 3; k++) { if (cnt[k] > 0) { cnt[k]--, Now[p + is] = k; if (k != Ans[is]) mustUp = false; findWell = true; break; } } if (mustUp == false) { np = p + is + 1; break; } if (findWell == false) isCan = false; } if (isCan == false) break; p = np; } if (isCan) { for (int i = 0; i < N; i++) { for (int j = 0; j < s + 1; j++) { if (Now[j] < Now[(i + j) % N]) { break; } else if (Now[j] > Now[(i + j) % N]) { isCan = false; break; } else continue; } } } if (isCan) isFinish = true, AnsN[o]--; } } for (int i = 0; i < N; i++) printf("%c", Ans[i] + 'a'); puts(""); return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; using ll = long long; string operator*(string a, int t) { string r; while (t) { if (t & 1) r += a; a += a; t >>= 1; } return r; } string sol(int x, int y, int z, string a, string b, string c) { if (y + z == 0) return a * x; if (x == 0) return sol(y, z, 0, b, c, ""); int p = x / (y + z); int q = x % (y + z); string t = a * p; if (q < z) { return sol(q, y, z - q, t + a + c, t + b, t + c); } else { return sol(z, q - z, y - (q - z), t + a + c, t + a + b, t + b); } } int main() { std::ios::sync_with_stdio(false), std::cin.tie(0); int x, y, z; cin >> x >> y >> z; cout << sol(x, y, z, "a", "b", "c") << endl; return 0; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> int A, B, C; std::string smallestRotateString(std::string s) { std::string result = ""; std::vector<int> indexList; { char smallestChar = 'z'; for (int i = 0; i < s.length(); i++) { if (s[i] < smallestChar) smallestChar = s[i]; } for (int i = 0; i < s.length(); i++) { if (s[i] == smallestChar) indexList.push_back(i); } result += smallestChar; } for (int p = 1; p < s.length(); p++) { for (int i = 0; i < indexList.size(); i++) { indexList[i] = (indexList[i] + 1) % s.length(); } char smallestChar = 'z'; for (int k = 0; k < indexList.size(); k++) { int idx = indexList[k]; if (s[idx] < smallestChar) smallestChar = s[idx]; } result += smallestChar; std::vector<int>::iterator it = indexList.begin(); while (it != indexList.end()) { if (s[*it] != smallestChar) { it = indexList.erase(it); } else ++it; } } return result; } std::vector<char> perm; int main(int argc, char* argv[]) { std::cin >> A >> B >> C; for (int i = 0; i < A; i++) perm.push_back('a'); for (int i = 0; i < B; i++) perm.push_back('b'); for (int i = 0; i < C; i++) perm.push_back('c'); std::string best(perm.begin(), perm.end()); best = smallestRotateString(best); do { std::string tmp(perm.begin(), perm.end()); std::cout << "t:" << tmp << std::endl; std::string ret = smallestRotateString(tmp); if (best.compare(ret) < 0) { best = ret; std::cout << "b:" << best << std::endl; } if (best.compare(tmp) < 0) break; } while (next_permutation(perm.begin(), perm.end())); std::cout << best << std::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
python2
def work(a,b,c,A,B,C): if A==0: return work(b,c,'',B,C,0) if B==0: if C==0: return a*A else: return work(a,c,'',A,C,0) if C==0: return work(a+b*(B/A),a+b*(B/A+1),'',A-B%A,B%A,0) cmod = C%A bmod = B%A if cmod+bmod<=A: return work(a+c*(C/A)+b*(B/A),a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),A-cmod-bmod,bmod,cmod) else: return work(a+c*(C/A)+b*(B/A+1),a+c*(C/A+1)+b*(B/A),a+c*(C/A+1)+b*(B/A+1),A-cmod,A-bmod,bmod+cmod-A) if __name__ == '__main__': s = raw_input() a,b,c = [int(i) for i in s.split()] print(work('a','b','c',a,b,c))
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using namespace std; __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } int main() { int x, y, z; cin >> x >> y >> z; multiset<string> ms; for (int i = (0); i < (x); i++) ms.insert("a"); for (int i = (0); i < (y); i++) ms.insert("b"); for (int i = (0); i < (z); i++) ms.insert("c"); while (ms.size() > 1) { auto itr1 = ms.begin(); auto itr2 = ms.end(); itr2--; ms.erase(itr1); ms.erase(itr2); ms.insert(*itr1 + *itr2); } cout << *ms.begin() << endl; }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
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); 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; if(!XX) return g1(BB,YY); 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); string AA=A; string BB=A; string CC=A; for(int i=0;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=0;i*qq<Y;i++) BB+=B, CC+=B; BB+=B; int YY=Y%qq; int ZZ=qq-YY; assert(XX+YY+ZZ == X); if(!XX) return g2(CC,BB,ZZ,YY); if(!YY) return g2(CC,AA,ZZ,XX); 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
cpp
#include <bits/stdc++.h> using namespace std; string f(int x, int y, int z, string a, string b, string c) { if (y == 0 && z == 0) { string ret; for (int i = 0; i < x; i++) ret += a; return ret; } if (x == 0) return f(y, z, 0, b, c, a); if (y == 0 && z) return f(x, z, y, a, c, b); if (z == 0) { if (x <= y) { string na = a; for (int i = 0; i < y / x; i++) na += b; return f(y - y % x, y % x, 0, na, b, c); } else { string na = a, nb = a + b; return f(x - y, y, 0, na, nb, c); } } else if (x <= y + z) { string na = a, nb = a; for (int i = 0; i < z / x; i++) { na += c; nb += c; } for (int i = 0; i < z % x; i++) nb += c; return f(x - z % x, z % x, y, na, nb, b); } else { string na = a, nb = a + b, nc = a + c; return f(x - y - z, y, z, na, nb, nc); } } int X, Y, Z; int main() { cin >> X >> Y >> Z; cout << f(X, Y, Z, "a", "b", "c"); }
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exactly X `a`s, exactly Y `b`s, and exactly Z `c`s. If there are multiple such strings, you want to choose one that maximizes f(T) lexicographically. Compute the lexicographically largest possible value of f(T). Constraints * 1 \leq X + Y + Z \leq 50 * X, Y, Z are non-negative integers. Input Input is given from Standard Input in the following format: X Y Z Output Print the answer. Examples Input 2 2 0 Output abab Input 1 1 1 Output acb
{ "input": [ "2 2 0", "1 1 1" ], "output": [ "abab", "acb" ] }
{ "input": [], "output": [] }
IN-CORRECT
cpp
#include <bits/stdc++.h> using 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 << 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 main(void) { int X, Y, Z; cin >> X >> Y >> Z; vector<string> v; if (X == 0 && Y == 0) { for (int i = 0; i < Z; ++i) { cout << 'c'; } cout << '\n'; return 0; } if (X == 0) { for (int i = 0; i < Y; ++i) { v.push_back("b"); } for (int i = 0; i < Y * (Z / Y); ++i) { v[i % Y] += "c"; } int c = -1; for (int i = 0; i < Z % Y; ++i) { if (i < Y % (Z % Y)) ++c; c += Y / (Z % Y); v[c] += "c"; } for (int i = 0; i < v.size(); ++i) { cout << v[i]; } cout << '\n'; return 0; } for (int i = 0; i < X; ++i) { v.push_back("a"); } for (int i = 0; i < X * (Z / X); ++i) { v[i % X] += "c"; } int c = -1; for (int i = 0; i < Z % X; ++i) { if (i < X % (Z % X)) ++c; c += X / (Z % X); v[c] += "c"; } vector<int> ind; for (int i = 0; i < v.size(); ++i) { if (v[i].length() <= 1 + Z / X) { ind.push_back(i); } } for (int i = 0; i < ind.size() * (Y / ind.size()); ++i) { v[ind[i % ind.size()]] += "b"; } c = -1; for (int i = 0; i < Y % ind.size(); ++i) { if (i < ind.size() % (Y % ind.size())) ++c; c += ind.size() / (Y % ind.size()); v[ind[c]] += "b"; } for (int i = 0; i < 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 std::abs; using std::array; using std::cerr; using std::cin; using std::cout; using std::generate; using std::make_pair; using std::map; using std::max; using std::max_element; using std::min; using std::min_element; using std::pair; using std::reverse; using std::set; using std::sort; using std::string; using std::unique; using std::vector; template <typename T> T input() { T res; cin >> res; {}; return res; } template <typename IT> void input_seq(IT b, IT e) { std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>); } string solve(int a, int b, int c) { string base = "a"; while (c >= a) base += 'c', c -= a; while (b >= a) base += 'b', b -= a; if (b == 0 and c == 0) { string res = ""; for (int t = 0; t != a; ++t) res += base; return res; } int num = (a + (b + c - 1)) / (b + c); int free = num * (b + c) - a; string tmp = ""; for (int i = 0; i != num - 1; ++i) tmp += base; vector<string> parts; for (int i = 0; i != (b + c - free); ++i) parts.push_back(tmp + base); for (int i = 0; i != free; ++i) parts.push_back(tmp); for (int i = 0; i != c; ++i) parts[i] += 'c'; for (int i = 0; i != b; ++i) parts[c + i] += 'b'; std::sort(parts.begin(), parts.end()); vector<string> cparts = parts; cparts.resize(std::unique(cparts.begin(), cparts.end()) - cparts.begin()); while (cparts.size() < 3) cparts.push_back(""); assert(int((cparts).size()) == 3); string zzans = solve(std::count(parts.begin(), parts.end(), cparts[0]), std::count(parts.begin(), parts.end(), cparts[1]), std::count(parts.begin(), parts.end(), cparts[2])); string ans = ""; for (char ch : zzans) ans += cparts[ch - 'a']; return ans; } int main() { std::iostream::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int a = input<int>(); int b = input<int>(); int c = input<int>(); std::map<char, char> back; if (a == 0 and b == 0) { back['a'] = 'c'; a = c; b = 0; c = 0; } else if (a == 0) { back['a'] = 'b'; back['b'] = 'c'; a = b; b = c; c = 0; } else { back['a'] = 'a'; back['b'] = 'b'; back['c'] = 'c'; } string ans = solve(a, b, c); for (int i = 0; i != int((ans).size()); ++i) cout << back[ans[i]]; cout << "\n"; return 0; }