Submission #766844

# Submission time Handle Problem Language Result Execution time Memory
766844 2023-06-26T08:09:40 Z Dorost Library (JOI18_library) C++17
100 / 100
296 ms 460 KB
#include <cstdio>
#include <vector>
#include <iostream>
#include "library.h"
using namespace std;
const int MaxN = 1012;
vector <int> g[MaxN];
int n;
vector <int> res;

int sz (vector <int> v) {
    int ans = 0;
    for (int i : v)
        ans += i;
    return ans;
}

int get (int x, int l, int r) {
    vector <int> W(n);
    for (int i = 0; i < n; i++)
        W[i] = 0;
    for (int i = l - 1; i <= r - 1; i++)
        W[i] = 1;
    W[x - 1] = false;
    int a = (l == r ? 0 : sz(W) - Query(W));
    W[x - 1] = 1;
    int b = (l == 1 && r == n ? n - 1 : sz(W) - Query(W));
    int wef = 0;
    for (int u : g[x])
        wef += ((u >= l) && (u <= r));
    return b - a - wef;
}

void dfs (int v, int p = -1) {
    res.push_back(v);
    for (int u : g[v])
        if (u != p)
            dfs (u, v);
}

void Solve(int N)
{
    if (N <= 2) {
        vector <int> wef(N);
        for (int i = 0; i < N; i++)
            wef[i] = i + 1;
        Answer(wef);
        return;
    }
    n = N;
    for (int i = 1; i <= n; i++) {
        while ((int)g[i].size() < 2) {
            if (g[i].size() == 1 && get (i, 1, n) == 0) {
                break;
            } else {
                int l = 1, r = n;
                while (r != l) {
                    int mid = (l + r) >> 1;
                    if (get (i, l, mid))
                        r = mid;
                    else
                        l = mid + 1;
                }
                g[i].push_back(l);
                g[l].push_back(i);
            }
        }
    }

    int root = 0;
    for (int i = 1; i <= n; i++)
        if (g[i].size() == 1)
            root = i;

    dfs (root);

    Answer(res);
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 316 KB # of queries: 2921
2 Correct 33 ms 312 KB # of queries: 2911
3 Correct 33 ms 208 KB # of queries: 3054
4 Correct 36 ms 312 KB # of queries: 3070
5 Correct 35 ms 312 KB # of queries: 3059
6 Correct 28 ms 312 KB # of queries: 3062
7 Correct 25 ms 432 KB # of queries: 3059
8 Correct 32 ms 208 KB # of queries: 2951
9 Correct 19 ms 324 KB # of queries: 3040
10 Correct 21 ms 308 KB # of queries: 1746
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 0
13 Correct 1 ms 276 KB # of queries: 8
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 2 ms 208 KB # of queries: 106
16 Correct 3 ms 208 KB # of queries: 245
# Verdict Execution time Memory Grader output
1 Correct 29 ms 316 KB # of queries: 2921
2 Correct 33 ms 312 KB # of queries: 2911
3 Correct 33 ms 208 KB # of queries: 3054
4 Correct 36 ms 312 KB # of queries: 3070
5 Correct 35 ms 312 KB # of queries: 3059
6 Correct 28 ms 312 KB # of queries: 3062
7 Correct 25 ms 432 KB # of queries: 3059
8 Correct 32 ms 208 KB # of queries: 2951
9 Correct 19 ms 324 KB # of queries: 3040
10 Correct 21 ms 308 KB # of queries: 1746
11 Correct 0 ms 208 KB # of queries: 0
12 Correct 0 ms 208 KB # of queries: 0
13 Correct 1 ms 276 KB # of queries: 8
14 Correct 0 ms 208 KB # of queries: 12
15 Correct 2 ms 208 KB # of queries: 106
16 Correct 3 ms 208 KB # of queries: 245
17 Correct 269 ms 348 KB # of queries: 19628
18 Correct 268 ms 452 KB # of queries: 19392
19 Correct 263 ms 328 KB # of queries: 19611
20 Correct 225 ms 328 KB # of queries: 18412
21 Correct 184 ms 336 KB # of queries: 17404
22 Correct 212 ms 344 KB # of queries: 19610
23 Correct 296 ms 320 KB # of queries: 19604
24 Correct 108 ms 444 KB # of queries: 9049
25 Correct 239 ms 336 KB # of queries: 19187
26 Correct 159 ms 336 KB # of queries: 18021
27 Correct 112 ms 312 KB # of queries: 9000
28 Correct 252 ms 344 KB # of queries: 19957
29 Correct 258 ms 460 KB # of queries: 19936
30 Correct 244 ms 324 KB # of queries: 19957