#include <iostream>
#include <set>
#include <vector>
using namespace std;
#ifdef _HOME_
#define DEBUG(x) x
#else
#define DEBUG(x)
#endif
#define REP(x,n) for(int x=0;x<(n);++x)
#define FOREACH(x,n) for(__typeof(n.begin()) x = (n).begin(); x != (n).end(); ++x)
#define RESULT(x) {cout<<(x);return 0;}
const int MAX_N = 100001;
int n;
string str;
const char charMap[] = {0, 0, 0, 'a', 'c', 'g', 'o'};
// a - 3/5
// c - 4/4
// e - 5/3
// f - 6/2
#define ALIGN(ones) {\
c0 -= (8-ones); \
c1 -= ones;\
if (c0 < 0 || c1 < 0) {\
DEBUG(cerr<<"fail on "<<ones<<endl);\
RESULT("NIE");\
}\
str += charMap[ones];\
DEBUG(cerr<<"0="<<c0<<", 1="<< c1 <<", str="<<str<<endl);\
}
int solve(int c0, int c1) {
DEBUG(cerr<<"solve "<<c0<<", "<<c1<<endl);
str="";
while (c0 + 2 < c1)
ALIGN(6);
while(c0 < c1)
ALIGN(5);
while (c0 > c1)
ALIGN(3);
while(c0>0 || c1>0)
ALIGN(4);
RESULT(str);
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> str;
int c0=0, c1=0;
for(char& c : str)
if(c=='0')
++c0;
else
++c1;
//#ifdef _HOME_
// solve(c0, c1);
// main();
//#else
return solve(c0, c1);
//#endif
}
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 56 57 58 59 60 61 62 63 64 65 | #include <iostream> #include <set> #include <vector> using namespace std; #ifdef _HOME_ #define DEBUG(x) x #else #define DEBUG(x) #endif #define REP(x,n) for(int x=0;x<(n);++x) #define FOREACH(x,n) for(__typeof(n.begin()) x = (n).begin(); x != (n).end(); ++x) #define RESULT(x) {cout<<(x);return 0;} const int MAX_N = 100001; int n; string str; const char charMap[] = {0, 0, 0, 'a', 'c', 'g', 'o'}; // a - 3/5 // c - 4/4 // e - 5/3 // f - 6/2 #define ALIGN(ones) {\ c0 -= (8-ones); \ c1 -= ones;\ if (c0 < 0 || c1 < 0) {\ DEBUG(cerr<<"fail on "<<ones<<endl);\ RESULT("NIE");\ }\ str += charMap[ones];\ DEBUG(cerr<<"0="<<c0<<", 1="<< c1 <<", str="<<str<<endl);\ } int solve(int c0, int c1) { DEBUG(cerr<<"solve "<<c0<<", "<<c1<<endl); str=""; while (c0 + 2 < c1) ALIGN(6); while(c0 < c1) ALIGN(5); while (c0 > c1) ALIGN(3); while(c0>0 || c1>0) ALIGN(4); RESULT(str); } int main() { ios_base::sync_with_stdio(0); cin >> n >> str; int c0=0, c1=0; for(char& c : str) if(c=='0') ++c0; else ++c1; //#ifdef _HOME_ // solve(c0, c1); // main(); //#else return solve(c0, c1); //#endif } |
English