# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647548 | 2022-10-03T06:06:45 Z | ghostwriter | Library (JOI18_library) | C++14 | 547 ms | 336 KB |
#include <cstdio> #include <vector> #include "library.h" using namespace std; #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #else #define debug(...) #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ void Solve(int N) { if (N == 1) { Answer(vi(1, 1)); return; } vi ans(N, 0), M(N, 0); int bpos = -1; FRN(i, N) { EACH(j, M) j = 0; FRN(z, N) if (z != i) M[z] = 1; int cur = Query(M); if (cur == 1) bpos = i + 1; } ans[0] = bpos; vi index; FOR(i, 1, N) if (i != bpos) index.pb(i); FOR(i, 1, N - 1) { int l = 0, r = sz(index) - 1, ans1 = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; EACH(j, M) j = 0; FRN(j, i) M[ans[j] - 1] = 1; FOR(j, 0, mid) M[index[j] - 1] = 1; int cur = Query(M); M[ans[i - 1] - 1] = 0; int cur1 = Query(M); if ((i > 1 && cur1 > cur) || (i == 1 && cur1 == cur)) { ans1 = mid; r = mid - 1; } else l = mid + 1; } ans[i] = index[ans1]; vi tmp; EACH(j, index) if (j != index[ans1]) tmp.pb(j); swap(index, tmp); } Answer(ans); } /* 5 4 2 5 3 1 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 208 KB | # of queries: 2586 |
2 | Correct | 36 ms | 208 KB | # of queries: 2555 |
3 | Correct | 45 ms | 208 KB | # of queries: 2716 |
4 | Correct | 41 ms | 208 KB | # of queries: 2728 |
5 | Correct | 48 ms | 208 KB | # of queries: 2714 |
6 | Correct | 40 ms | 208 KB | # of queries: 2712 |
7 | Correct | 40 ms | 300 KB | # of queries: 2718 |
8 | Correct | 36 ms | 300 KB | # of queries: 2611 |
9 | Correct | 43 ms | 208 KB | # of queries: 2713 |
10 | Correct | 21 ms | 208 KB | # of queries: 1597 |
11 | Correct | 0 ms | 208 KB | # of queries: 0 |
12 | Correct | 1 ms | 208 KB | # of queries: 4 |
13 | Correct | 1 ms | 208 KB | # of queries: 7 |
14 | Correct | 1 ms | 336 KB | # of queries: 14 |
15 | Correct | 2 ms | 208 KB | # of queries: 99 |
16 | Correct | 3 ms | 208 KB | # of queries: 205 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 208 KB | # of queries: 2586 |
2 | Correct | 36 ms | 208 KB | # of queries: 2555 |
3 | Correct | 45 ms | 208 KB | # of queries: 2716 |
4 | Correct | 41 ms | 208 KB | # of queries: 2728 |
5 | Correct | 48 ms | 208 KB | # of queries: 2714 |
6 | Correct | 40 ms | 208 KB | # of queries: 2712 |
7 | Correct | 40 ms | 300 KB | # of queries: 2718 |
8 | Correct | 36 ms | 300 KB | # of queries: 2611 |
9 | Correct | 43 ms | 208 KB | # of queries: 2713 |
10 | Correct | 21 ms | 208 KB | # of queries: 1597 |
11 | Correct | 0 ms | 208 KB | # of queries: 0 |
12 | Correct | 1 ms | 208 KB | # of queries: 4 |
13 | Correct | 1 ms | 208 KB | # of queries: 7 |
14 | Correct | 1 ms | 336 KB | # of queries: 14 |
15 | Correct | 2 ms | 208 KB | # of queries: 99 |
16 | Correct | 3 ms | 208 KB | # of queries: 205 |
17 | Correct | 476 ms | 292 KB | # of queries: 18160 |
18 | Correct | 440 ms | 292 KB | # of queries: 17933 |
19 | Correct | 517 ms | 292 KB | # of queries: 18178 |
20 | Correct | 444 ms | 292 KB | # of queries: 16960 |
21 | Correct | 357 ms | 292 KB | # of queries: 15937 |
22 | Correct | 517 ms | 288 KB | # of queries: 18168 |
23 | Correct | 479 ms | 208 KB | # of queries: 18157 |
24 | Correct | 191 ms | 208 KB | # of queries: 8321 |
25 | Correct | 459 ms | 208 KB | # of queries: 17675 |
26 | Correct | 406 ms | 208 KB | # of queries: 16597 |
27 | Correct | 147 ms | 208 KB | # of queries: 8287 |
28 | Correct | 547 ms | 208 KB | # of queries: 18954 |
29 | Correct | 507 ms | 208 KB | # of queries: 18933 |
30 | Correct | 520 ms | 208 KB | # of queries: 18954 |