#include <iostream> #include <set> #include <vector> #include <algorithm> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int,int>; using vpii = vector<pii>; using graph = vector<vi>; #define FOR(name__, upper__) for (int name__ = 0; name__ < (upper__); ++name__) #define all(x) begin(x), end(x) #define mp make_pair #define mt make_tuple void go() { int n; string s; cin >> n >> s; int ones = 0; for (char x : s) if (x == '1') ones++; int max_n = ones/3; int min_n = (ones + 5)/6; vector<pair<char, int>> chars { {'p', 3}, {'i', 4}, {'s', 5}, {'w', 6} }; if (ones < 3 || n < min_n || n > max_n) { cout << "NIE\n"; return; } else { FOR (cnt3, n) { int cnt6 = n - 1 - cnt3; for (auto p : chars) { if (cnt3 * 3 + cnt6 * 6 + p.second == ones) { cout << string(cnt3, chars[0].first) << string(cnt6, chars[3].first) << p.first << '\n'; return; } } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); go(); return 0; }
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 50 51 52 53 54 55 | #include <iostream> #include <set> #include <vector> #include <algorithm> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int,int>; using vpii = vector<pii>; using graph = vector<vi>; #define FOR(name__, upper__) for (int name__ = 0; name__ < (upper__); ++name__) #define all(x) begin(x), end(x) #define mp make_pair #define mt make_tuple void go() { int n; string s; cin >> n >> s; int ones = 0; for (char x : s) if (x == '1') ones++; int max_n = ones/3; int min_n = (ones + 5)/6; vector<pair<char, int>> chars { {'p', 3}, {'i', 4}, {'s', 5}, {'w', 6} }; if (ones < 3 || n < min_n || n > max_n) { cout << "NIE\n"; return; } else { FOR (cnt3, n) { int cnt6 = n - 1 - cnt3; for (auto p : chars) { if (cnt3 * 3 + cnt6 * 6 + p.second == ones) { cout << string(cnt3, chars[0].first) << string(cnt6, chars[3].first) << p.first << '\n'; return; } } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); go(); return 0; } |