#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; #define st first #define nd second typedef pair<int,int> pun; typedef long long ll; char str[N]; char out[N]; int main() { int n; scanf("%d", &n); scanf("%s", str); int x = 0; map<int, char> mapa; for (char i = 'a'; i <= 'z'; i ++) { mapa[__builtin_popcount(i)] = i; } int ile = 0; for (int i = 0; i < 8 * n; i ++) { ile += str[i] - '0'; } for (int i = 0; i < n; i++) { // cerr << ile << " " << 3 * (n-i) << " "<< 6 * (n-i) << "\n"; if (ile < 3 * (n-i) || ile > 6 * (n-i)) { printf("NIE\n"); return 0; } else { out[i] = mapa[ile/(n-i)]; ile -= ile / (n-i); } } printf("%s\n", out); }
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 | #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; #define st first #define nd second typedef pair<int,int> pun; typedef long long ll; char str[N]; char out[N]; int main() { int n; scanf("%d", &n); scanf("%s", str); int x = 0; map<int, char> mapa; for (char i = 'a'; i <= 'z'; i ++) { mapa[__builtin_popcount(i)] = i; } int ile = 0; for (int i = 0; i < 8 * n; i ++) { ile += str[i] - '0'; } for (int i = 0; i < n; i++) { // cerr << ile << " " << 3 * (n-i) << " "<< 6 * (n-i) << "\n"; if (ile < 3 * (n-i) || ile > 6 * (n-i)) { printf("NIE\n"); return 0; } else { out[i] = mapa[ile/(n-i)]; ile -= ile / (n-i); } } printf("%s\n", out); } |