#include <vector> #include <iostream> #include <array> #include <cinttypes> #include <cstring> #include <climits> #include <string> using namespace std; namespace wzor { } string solve_wzor(int n, char* input) { using namespace wzor; int counters[2] = {0, 0}; for(int i = 0; i < 8 * n; ++i) { int index = input[i] - '0'; ++counters[index]; } counters[0] -= 2 * n; if(counters[0] < 0) { return "NIE"; } counters[1] -= 3 * n; if(counters[1] < 0) { return "NIE"; } string ans; for(int i = 0; i < n; ++i) { int char_num = min(counters[1], 3) + 1; ans += 'a' - 1 + (1 << char_num) - 1; //cout << 'a' - 1 + (1 << char_num) - 1 << ' ' << char_num << ' ' << n << ' ' << counters[1] << '\n'; counters[1] -= char_num - 1; } return ans; } #include <iostream> char input[800100]; int main() { int n; std::cin >> n >> input; std::cout << solve_wzor(n, input) << '\n'; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <vector> #include <iostream> #include <array> #include <cinttypes> #include <cstring> #include <climits> #include <string> using namespace std; namespace wzor { } string solve_wzor(int n, char* input) { using namespace wzor; int counters[2] = {0, 0}; for(int i = 0; i < 8 * n; ++i) { int index = input[i] - '0'; ++counters[index]; } counters[0] -= 2 * n; if(counters[0] < 0) { return "NIE"; } counters[1] -= 3 * n; if(counters[1] < 0) { return "NIE"; } string ans; for(int i = 0; i < n; ++i) { int char_num = min(counters[1], 3) + 1; ans += 'a' - 1 + (1 << char_num) - 1; //cout << 'a' - 1 + (1 << char_num) - 1 << ' ' << char_num << ' ' << n << ' ' << counters[1] << '\n'; counters[1] -= char_num - 1; } return ans; } #include <iostream> char input[800100]; int main() { int n; std::cin >> n >> input; std::cout << solve_wzor(n, input) << '\n'; } |