Task: | Just do it |
Sender: | Sold days |
Submission time: | 2024-11-16 14:28:56 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.01 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n = 0; cin >> n; vector<int> initial(n); iota(initial.begin(), initial.end(), 0); vector<int> ans(n); iota(ans.begin(), ans.end(), n + 1); int l = 0, r = n; int cnt = 0; bool reversed = false; while (l + 1 < r) { int m = (l + r) / 2; if (!reversed) { if (ans[initial[l]] > n) { ans[initial[l]] = ++cnt; } if (ans[initial[m]] > n) { ans[initial[m]] = ++cnt; } if (ans[initial[r - 1]] > n) { ans[initial[r - 1]] = ++cnt; } swap(initial[l + 1], initial[m]); l = l + 2; reversed = !reversed; } else { if (ans[initial[r - 1]] > n) { ans[initial[r - 1]] = ++cnt; } if (ans[initial[m]] > n) { ans[initial[m]] = ++cnt; } if (ans[initial[l]] > n) { ans[initial[l]] = ++cnt; } swap(initial[l], initial[r - 1]); swap(initial[l + 1], initial[m]); l = l + 2; } } auto ans1 = ans; sort(ans1.begin(), ans1.end()); for (int i = 0; i < n; ++i) ans[i] = lower_bound(ans1.begin(), ans1.end(), ans[i]) - ans1.begin() + 1; for (auto x : ans) cout << x << " "; cout << endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
1 2 |
user output |
---|
1 2 |
Test 2
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
1 2 3 |
user output |
---|
1 2 3 |
Test 3
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
1 2 3 4 |
user output |
---|
1 4 2 3 |
Test 4
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
1 2 4 3 5 |
user output |
---|
1 5 2 4 3 |
Test 5
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
1 2 3 5 4 6 |
user output |
---|
1 6 5 2 4 3 |
Test 6
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
1 2 4 6 5 3 7 |
user output |
---|
1 7 5 2 4 6 3 |
Test 7
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
1 2 3 5 7 6 4 8 |
user output |
---|
1 7 5 8 2 4 6 3 |
Test 8
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
1 2 4 6 8 3 7 5 9 |
user output |
---|
1 7 5 9 2 4 6 8 3 |
Test 9
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
1 2 3 5 7 9 4 8 6 10 |
user output |
---|
1 10 5 9 7 2 4 6 8 3 |
Test 10
Verdict: ACCEPTED
input |
---|
99 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
1 97 5 53 7 77 9 55 11 89 13 5... |
Test 11
Verdict: ACCEPTED
input |
---|
100 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 53 5 99 7 55 9 79 11 57 13 9... |
Test 12
Verdict: ACCEPTED
input |
---|
101 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
1 53 5 99 7 55 9 79 11 57 13 9... |
Test 13
Verdict: ACCEPTED
input |
---|
300 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 153 5 265 7 155 9 229 11 157... |
Test 14
Verdict: ACCEPTED
input |
---|
500 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 253 5 471 7 255 9 379 11 257... |
Test 15
Verdict: ACCEPTED
input |
---|
998 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 751 5 503 7 969 9 505 11 753... |
Test 16
Verdict: ACCEPTED
input |
---|
999 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
1 751 5 503 7 969 9 505 11 753... |
Test 17
Verdict: ACCEPTED
input |
---|
1000 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 503 5 753 7 505 9 971 11 507... |