-
Notifications
You must be signed in to change notification settings - Fork 0
/
388b.cpp
109 lines (94 loc) · 1.75 KB
/
388b.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int k;
cin >> k;
vector<int> v;
vector<int> u;
int n = 0;
int m = 2;
while (k > 1) {
if (k%2 == 1) {
m += 1;
u.push_back(1);
}
else {
u.push_back(0);
}
v.push_back(m);
k /= 2;
n += m;
}
if (v.size() == 0) {
cout << "2\nNY\nYN" << endl;
return 0;
}
n += 2;
cout << n << endl;
string s;
// 1
s = string(n, 'N');
for (int j = 0; j < v[0]; j++)
s[2+j] = 'Y';
cout << s << endl;
// 2
s = string(n, 'N');
for (int j = 0; j < v.back(); j++)
s[n-1-j] = 'Y';
cout << s << endl;
//3 -- n+2
m = 2;
for (size_t i = 0; i < v.size(); i++) {
s = string(n, 'N');
if (i == 0)
s[0] = 'Y';
else
s[m-v[i-1]] = s[m-v[i-1]+1] = 'Y';
if (i == v.size()-1)
s[1] = 'Y';
else {
s[m+v[i]] = s[m+v[i]+1] = 'Y';
if (u[i+1] == 1)
s[m+v[i]+v[i+1]-1] = 'Y';
}
cout << s << endl << s << endl;
if (v[i] == 2) {
m += v[i];
continue;
}
for (int j = 2; j < v[i]-1; j++) {
s = string(n, 'N');
s[m+j-v[i-1]] = 'Y';
if (i == v.size()-1)
s[1] = 'Y';
else
s[m+j+v[i]] = 'Y';
cout << s << endl;
}
if (u[i] == 1) {
s = string(n, 'N');
if (i == 0)
s[0] = 'Y';
else
s[m-v[i-1]] = s[m-v[i-1]+1] = 'Y';
if (i == v.size()-1)
s[1] = 'Y';
else
s[m+v[i]-1+v[i]] = 'Y';
cout << s << endl;
}
else {
s = string(n, 'N');
s[m+v[i]-1-v[i-1]] = 'Y';
if (i == v.size()-1)
s[1] = 'Y';
else
s[m+v[i]-1+v[i]] = 'Y';
cout << s << endl;
}
m += v[i];
}
return 0;
}