Submission #37039146
Source Code Expand
/* * File created on 12/05/2022 at 09:18:25. * Link to problem: * Description: * Time complexity: O() * Space complexity: O() * Status: --- * Copyright: Ⓒ 2022 Francois Vogel */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define pii pair<int, int> #define f first #define s second #define vi vector<int> #define all(x) x.begin(), x.end() #define sz(x) (int)((x).size()) #define pb push_back #define ins insert #define cls clear #define ll long long #define ld long double typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; vector<vi> graph; vector<pii> b; void dfs(vi& path, int x, int p = -1) { for (int y : graph[x]) if (y != p) { path.pb(b[x].f); dfs(path, y, x); } for (int i = 0; i < b[x].s+1-sz(graph[x])-(p == -1 ? 1 : 0); i++) { path.pb(b[x].f); } } void solve() { int n; cin >> n; map<int, int> m; for (int i = 0; i < n; i++) { int x; cin >> x; if (!m.count(x)) m[x] = 0; m[x]++; } b = vector<pii>(all(m)); sort(all(b), [](pii a, pii b) { return a.s > b.s; }); if (n >= 2*sz(b)-2) { graph = vector<vi>(sz(b)); int at = 0; for (int i = 1; i < sz(b); i++) { while (sz(graph[at]) == b[at].s) at++; assert(at < i); assert(sz(graph[at]) < b[at].s); graph[at].pb(i); graph[i].pb(at); } vi path; dfs(path, 0); assert(sz(path) == n); for (int x : path) cout << x << ' '; } else { for (auto i : b) { for (int j = 0; j < i.s; j++) { cout << i.f << " "; } } } cout << '\n'; } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; while (n--) solve(); cout.flush(); int d = 0; d++; }
Submission Info
Submission Time | |
---|---|
Task | B - Arrange Your Balls |
User | fvogel |
Language | C++ (GCC 9.2.1) |
Score | 700 |
Code Size | 2111 Byte |
Status | AC |
Exec Time | 154 ms |
Memory | 15552 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 01.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 8 ms | 3584 KiB |
02.txt | AC | 111 ms | 15544 KiB |
03.txt | AC | 104 ms | 15552 KiB |
04.txt | AC | 132 ms | 15192 KiB |
05.txt | AC | 126 ms | 15304 KiB |
06.txt | AC | 126 ms | 15144 KiB |
07.txt | AC | 109 ms | 15464 KiB |
08.txt | AC | 99 ms | 15504 KiB |
09.txt | AC | 129 ms | 15196 KiB |
10.txt | AC | 125 ms | 15184 KiB |
11.txt | AC | 77 ms | 7652 KiB |
12.txt | AC | 119 ms | 12264 KiB |
13.txt | AC | 120 ms | 12324 KiB |
14.txt | AC | 107 ms | 8484 KiB |
15.txt | AC | 99 ms | 9152 KiB |
16.txt | AC | 117 ms | 12496 KiB |
17.txt | AC | 154 ms | 13188 KiB |
18.txt | AC | 119 ms | 8620 KiB |
19.txt | AC | 110 ms | 9336 KiB |
20.txt | AC | 116 ms | 12840 KiB |
21.txt | AC | 99 ms | 8712 KiB |
22.txt | AC | 88 ms | 6744 KiB |
23.txt | AC | 116 ms | 11472 KiB |
24.txt | AC | 99 ms | 6212 KiB |
25.txt | AC | 97 ms | 9664 KiB |
26.txt | AC | 101 ms | 8536 KiB |
27.txt | AC | 102 ms | 7488 KiB |
28.txt | AC | 92 ms | 7344 KiB |
29.txt | AC | 113 ms | 8444 KiB |
30.txt | AC | 97 ms | 9352 KiB |
31.txt | AC | 107 ms | 7728 KiB |
32.txt | AC | 80 ms | 5276 KiB |
33.txt | AC | 90 ms | 5696 KiB |
34.txt | AC | 87 ms | 5156 KiB |
35.txt | AC | 86 ms | 4908 KiB |
36.txt | AC | 85 ms | 4876 KiB |
37.txt | AC | 75 ms | 4220 KiB |
38.txt | AC | 73 ms | 4176 KiB |
39.txt | AC | 73 ms | 4048 KiB |
40.txt | AC | 76 ms | 4308 KiB |
41.txt | AC | 75 ms | 4104 KiB |
42.txt | AC | 62 ms | 3572 KiB |
43.txt | AC | 62 ms | 3704 KiB |
44.txt | AC | 62 ms | 3656 KiB |
45.txt | AC | 64 ms | 3688 KiB |
46.txt | AC | 62 ms | 3628 KiB |
47.txt | AC | 52 ms | 3636 KiB |
48.txt | AC | 52 ms | 3588 KiB |
49.txt | AC | 51 ms | 3588 KiB |
50.txt | AC | 49 ms | 3584 KiB |
51.txt | AC | 52 ms | 3632 KiB |
52.txt | AC | 47 ms | 3544 KiB |