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 66 67 68 69 70 71 72 73 74 75
| #include<bits/stdc++.h>
#define mmst0(x) memset(x,0,sizeof(x)) #define mmst3f(x) memset(x,0x3f,sizeof(x)) #define pb(x) emplace_back(x) #define mkp(x, y) make_pair(x, y) #define fi first #define se second using namespace std;
typedef long long ll; typedef long double rld; typedef unsigned long long ull;
const rld eps = 1e-6; const int INF=0x3f3f3f3f; const int MAXN=(int)3e5+3;
inline char nc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;} inline int read(){int s=0,w=1;char ch=nc();while(!isdigit(ch)){if(ch=='-')w=-1;ch=nc();}while(isdigit(ch)){s=(s<<3)+(s<<1)+(ch^48);ch=nc();} return s*w;}
int n,cnt; char s[MAXN];
void dfs(int now, int ji, int ou, bool flag) { if(cnt==100) exit(0); if(n%2) { if(ji+(n-ji-ou) < (n>>1) || ou + (n-ji-ou) < (n>>1) || ji > (n>>1)+1 || ou > (n>>1)+1) return; } else { if(ji+(n-ji-ou) < (n>>1) || ou + (n-ji-ou) < (n>>1) || ji > (n>>1) || ou > (n>>1)) return; } if(now == n) { for(int i=1;i<=n-1;i++) printf("%c",s[i]); printf("\n"); cnt++; return; } s[now]='b'; if(flag) dfs(now+1,ji+1,ou,flag); else dfs(now+1,ji,ou+1,flag); s[now]='r'; if(!flag) dfs(now+1,ji+1,ou,!flag); else dfs(now+1,ji,ou+1,!flag); }
inline void work() { n=read()+1; ll ans=((ll)n/2) * ((ll)n-(ll)n/2); printf("%lld\n",ans); dfs(1,0,1,false); return; }
signed main() { signed T=1; for(signed Case=1; Case<=T; Case++) { work(); } return 0; }
|