Submission #129729

# Submission time Handle Problem Language Result Execution time Memory
129729 2019-07-13T05:58:51 Z BThero Library (JOI18_library) C++17
19 / 100
650 ms 512 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include "library.h"

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;   
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)1e3 + 5;

vector<int> V[MAXN], S;

int par[MAXN];

int getPar(int x) {
    if (x == par[x]) {
        return x;
    }
    else {
        return par[x] = getPar(par[x]);
    }
}

void uni(int a, int b) {
    a = getPar(a);
    b = getPar(b);

    if (a == b) {
        return;
    }

    par[b] = a;

    for (int x : V[b]) {
        V[a].pb(x);
    }

    V[b].clear();
    int p = 0;

    while (S[p] != b) {
        ++p;
    }

    S.erase(S.begin() + p);
}

void Solve(int n) {
    vector<int> ask, p(n);

    for (int i = 0; i < n; ++i) {
        p[i] = i;
    }

    for (int step = 0; step < 10; ++step) {
        random_shuffle(all(p));
    }

    for (int i = 0; i < n; ++i) {
        par[i] = i;
        V[i].pb(i);
    }

    S.pb(p[0]);
    int prev = 1;

    for (int i = 1; i < n; ++i) {
        ask = vector<int>(n, 0);

        for (int j = 0; j <= i; ++j) {
            ask[p[j]] = 1;
        }

        int cur = Query(ask);
        S.pb(p[i]);
        
        if (cur == prev) {
            vector<int> T;

            for (int x : S) {
                if (x != p[i]) {
                    T.pb(x);
                }
            }

            while (T.size() > 1) {
                vector<int> tmp;

                for (int j = 0; j < T.size() / 2; ++j) {
                    tmp.pb(T[j]);
                }

                ask = vector<int>(n, 0);
                ask[p[i]] = 1;
                int need = 0;

                for (int x : tmp) {
                    if (V[x].size() <= 2) {
                        ++need;
                    }
                    else {
                        need += 2;
                    }

                    ask[V[x].front()] = 1;
                    ask[V[x].back()] = 1;
                }

                if (Query(ask) != need) {
                    tmp.clear();

                    for (int j = T.size() / 2; j < T.size(); ++j) {
                        tmp.pb(T[j]);
                    }
                }
                
                T = tmp;
            }

            ask = vector<int>(n, 0);
            ask[p[i]] = 1;
            ask[V[T[0]].front()] = 1;

            if (Query(ask) == 1) {
                uni(p[i], T[0]);
            }
            else {
                uni(T[0], p[i]);
            }
        }
        else if (cur == prev - 1) {
            int a = -1, b = -1;

            for (int id : S) {
                if (id == p[i]) {
                    continue;
                }

                ask = vector<int>(n, 0);
                ask[p[i]] = 1;
                ask[V[id].front()] = 1;

                if (Query(ask) == 1) {
                    if (b != -1) {
                        reverse(all(V[id]));
                        a = id;
                    }
                    else {
                        b = id;
                    }
                }
                else {
                    ask = vector<int>(n, 0);
                    ask[p[i]] = 1;
                    ask[V[id].back()] = 1;

                    if (Query(ask) == 1) {
                        if (a != -1) {
                            reverse(all(V[id]));
                            b = id;
                        }
                        else {
                            a = id;
                        }
                    }
                }
            }

            uni(a, p[i]);
            uni(a, b);
        }

        prev = cur;
    }

    int v = 0;

    while (getPar(v) != v) {
        ++v;
    }

    for (int &x : V[v]) {
        ++x;
    }

	Answer(V[v]);
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:106:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int j = 0; j < T.size() / 2; ++j) {
                                 ~~^~~~~~~~~~~~~~
library.cpp:129:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int j = T.size() / 2; j < T.size(); ++j) {
                                                ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 77 ms 248 KB # of queries: 4437
2 Correct 80 ms 376 KB # of queries: 4427
3 Correct 75 ms 424 KB # of queries: 4328
4 Correct 78 ms 352 KB # of queries: 4951
5 Correct 54 ms 376 KB # of queries: 3905
6 Correct 87 ms 484 KB # of queries: 4701
7 Correct 59 ms 348 KB # of queries: 4693
8 Correct 80 ms 424 KB # of queries: 4455
9 Correct 81 ms 348 KB # of queries: 4597
10 Correct 37 ms 404 KB # of queries: 2048
11 Correct 2 ms 376 KB # of queries: 0
12 Correct 2 ms 376 KB # of queries: 2
13 Correct 2 ms 248 KB # of queries: 4
14 Correct 2 ms 248 KB # of queries: 6
15 Correct 3 ms 248 KB # of queries: 47
16 Correct 3 ms 344 KB # of queries: 119
# Verdict Execution time Memory Grader output
1 Correct 77 ms 248 KB # of queries: 4437
2 Correct 80 ms 376 KB # of queries: 4427
3 Correct 75 ms 424 KB # of queries: 4328
4 Correct 78 ms 352 KB # of queries: 4951
5 Correct 54 ms 376 KB # of queries: 3905
6 Correct 87 ms 484 KB # of queries: 4701
7 Correct 59 ms 348 KB # of queries: 4693
8 Correct 80 ms 424 KB # of queries: 4455
9 Correct 81 ms 348 KB # of queries: 4597
10 Correct 37 ms 404 KB # of queries: 2048
11 Correct 2 ms 376 KB # of queries: 0
12 Correct 2 ms 376 KB # of queries: 2
13 Correct 2 ms 248 KB # of queries: 4
14 Correct 2 ms 248 KB # of queries: 6
15 Correct 3 ms 248 KB # of queries: 47
16 Correct 3 ms 344 KB # of queries: 119
17 Incorrect 650 ms 388 KB Wrong Answer [3]
18 Incorrect 617 ms 376 KB Wrong Answer [3]
19 Incorrect 599 ms 504 KB Wrong Answer [3]
20 Incorrect 597 ms 460 KB Wrong Answer [3]
21 Incorrect 563 ms 424 KB Wrong Answer [3]
22 Incorrect 595 ms 504 KB Wrong Answer [3]
23 Incorrect 592 ms 512 KB Wrong Answer [3]
24 Incorrect 429 ms 248 KB Wrong Answer [3]
25 Incorrect 636 ms 504 KB Wrong Answer [3]
26 Incorrect 582 ms 504 KB Wrong Answer [3]
27 Incorrect 324 ms 364 KB Wrong Answer [3]
28 Incorrect 630 ms 424 KB Wrong Answer [3]
29 Incorrect 599 ms 396 KB Wrong Answer [3]
30 Incorrect 610 ms 396 KB Wrong Answer [3]