Task: | Just do it |
Sender: | TyƤmiesklubi |
Submission time: | 2024-11-16 13:35:26 +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.00 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; const int N = 1000; int perm[N]; int assg[N]; int nc = 1; long totc = 0; void f(int lo, int hi) { if (hi-lo < 3) { for (int i = lo; i < hi; ++i) { if (!assg[perm[i]]) assg[perm[i]] = nc++; } return; } int mid = (lo+hi)/2; if (!assg[perm[lo]]) assg[perm[lo]] = nc++; if (!assg[perm[mid]]) assg[perm[mid]] = nc++; // if (!assg[perm[hi-1]]) assg[perm[hi-1]] = nc++; swap(perm[lo+1], perm[mid]); totc += hi-lo-1; f(lo+2, hi); } // long sim(vector<int> &v, int lo, int hi) { // long res = 0; // if (hi - lo > 1) { // vector<int> pv{v[lo], v[(lo+hi)/2], v[hi-1]}; // sort(pv.begin(), pv.end()); // int pivot = pv[1]; // int a = lo; // int b = hi-1; // while (true) { // while (++res && v[a] < pivot) a += 1; // while (++res && v[b] > pivot) b -= 1; // if (a >= b) break; // swap(v[a], v[b]); // a += 1; // b -= 1; // } // res += sim(v, lo, a); // res += sim(v, a, hi); // } // return res; // } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { perm[i] = i; } f(0, n); for (int i = 0; i < n; ++i) { cout << assg[i] << " "; } cout << endl; // { // cerr << totc << " " << long(n)*n/4 << endl; // vector<int> v; // for (int i = 0; i < n; ++i) { // v.push_back(assg[i]); // } // cout << sim(v, 0, n) << endl; // } }
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 3 2 4 |
Test 4
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
1 2 4 3 5 |
user output |
---|
1 3 2 4 5 |
Test 5
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
1 2 3 5 4 6 |
user output |
---|
1 5 3 2 4 6 |
Test 6
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
1 2 4 6 5 3 7 |
user output |
---|
1 5 3 2 4 6 7 |
Test 7
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
1 2 3 5 7 6 4 8 |
user output |
---|
1 5 3 7 2 4 6 8 |
Test 8
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
1 2 4 6 8 3 7 5 9 |
user output |
---|
1 5 3 7 2 4 6 8 9 |
Test 9
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
1 2 3 5 7 9 4 8 6 10 |
user output |
---|
1 9 3 7 5 2 4 6 8 10 |
Test 10
Verdict: ACCEPTED
input |
---|
99 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
1 95 3 51 5 75 7 53 9 87 11 55... |
Test 11
Verdict: ACCEPTED
input |
---|
100 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 51 3 97 5 53 7 77 9 55 11 89... |
Test 12
Verdict: ACCEPTED
input |
---|
101 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
1 51 3 97 5 53 7 77 9 55 11 89... |
Test 13
Verdict: ACCEPTED
input |
---|
300 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 151 3 263 5 153 7 227 9 155 ... |
Test 14
Verdict: ACCEPTED
input |
---|
500 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 251 3 469 5 253 7 377 9 255 ... |
Test 15
Verdict: ACCEPTED
input |
---|
998 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 749 3 501 5 967 7 503 9 751 ... |
Test 16
Verdict: ACCEPTED
input |
---|
999 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
1 749 3 501 5 967 7 503 9 751 ... |
Test 17
Verdict: ACCEPTED
input |
---|
1000 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1 501 3 751 5 503 7 969 9 505 ... |