-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathF.cpp
58 lines (51 loc) · 1.05 KB
/
F.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n;
vector<int> ans;
void mel(int l, int r, bool maju) {
if (maju) {
for (int i = l; i <= r; i++) {
ans.push_back(i%n);
}
} else {
for (int i = r; i >= l; i--) {
ans.push_back(i%n);
}
}
}
void young(int l, int r) {
int L = l, R = r - 1;
bool maju = false;
while (L <= R) {
mel(L, R, maju);
if (maju) R--;
else L++;
maju ^= 1;
}
int len = l + (r - l >> 1);
for (int i = l; i < len; i++) {
ans.push_back(i%n);
}
}
void solve() {
cin >> n;
young(0, n - 1);
young(n + 1 >> 1, (n + 1 >> 1) + n - 1 - (1 & n));
young(0, n - 1);
cout << (int) ans.size() << '\n';
for (auto i : ans) {
cout << i << ' ';
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tc = 1;
//cin >> tc;
while (tc--) {
solve();
}
return 0;
}