-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUNICA.cpp
70 lines (66 loc) · 1.22 KB
/
UNICA.cpp
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
#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
ll dp[4][4][100006];
ll n;
ll calc(ll a,ll b,ll len)
{
if(a>=4 || b>=4) return 0;
ll &ret=dp[a][b][len];
if(ret!=-1) return ret;
if(len==0) return 1;
ret=0;
if(a+1<4)
{
int x=a+1,y=b-1>0?b-1:0;
ret+=calc(x,y,len-1);
}
if(b+1<4)
{
int y=b+1,x=a-1>0?a-1:0;
ret+=calc(x,y,len-1);
}
return ret;
}
int main()
{
ll i,j,k,l;
while(cin>>n)
{
k=0,l=0;
memset(dp,-1,sizeof(dp));
while(k<n)
{
n-=k;
l++;
k=calc(0,0,l);
//cout<<k<<endl;
}
//cout<<l<<endl;
ll a=0,b=0;
while(l)
{
//cout<<a<<" "<<b<<" ";
int x=a+1,y=b-1>0?b-1:0;
k=calc(x,y,l-1);
if(k>=n)
{
a=x;
b=y;
cout<<'a';
}
else
{
n-=k;
int y=b+1,x=a-1>0?a-1:0;
a=x;
b=y;
cout<<'b';
}
l--;
//cout<<endl;
}
cout<<endl<<endl;
}
}