Submission #1079914

# Submission time Handle Problem Language Result Execution time Memory
1079914 2024-08-29T03:28:28 Z Thanhs Library (JOI18_library) C++14
19 / 100
521 ms 40660 KB
#include<library.h>
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// #define double long double
 
// #define endl '\n'
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))
#define fi first
#define se second
#define aint(x) x.begin(), x.end()
 
// mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
// int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}

const int NM = 1e3 + 5;

int N;
vector<int> g[NM];
set<int> s;
map<vector<int>, int> mp;

// int Query(vector<int>& v)
// {
//     cout << "? ";
//     for (int i = 0; i < N; i++)
//         if (v[i])
//             cout << i + 1 << ' ';
//     cout << endl;
//     int res;
//     cin >> res;
//     return res;
// }

// void Answer(vector<int>& v)
// {
//     cout << "! ";
//     for (int t : v)
//         cout << t << ' ';
//     cout << endl;
// }

vector<int> t;

int ask(int x, int y)
{
    fill(t.begin(), t.end(), 0);
    if (y)
        t[y - 1] = 1;
    auto it = s.begin();
    for (int i = 1; i <= x; i++, it = next(it))
        t[*it - 1] = 1;
    if (t.size() == 1)
        return 1;
    if (mp.find(t) != mp.end())
        return mp[t];
    int res = Query(t);
    mp[t] = res;
    return Query(t);
}

int get(int x)
{
    assert(x <= s.size());
    auto it = s.begin();
    x--;
    while (x--)
        it = next(it);
    return *it;
}

void Solve(int n)
{
    N = n;
    t.resize(N, 0);
    if (n == 1)
    {
        vector<int> res(1, 1);
        Answer(res);
        return;
    }
    for (int i = 1; i <= n; i++)
        s.insert(i);
    for (int i = 1; i <= n; i++)
    {
        vector<int> tmp;
        s.erase(i);
        // cout << "LMAO " << i << ' ' << s.size() << endl;
        while (g[i].size() < 2)
        {
            if (s.empty())
                break;
            if (ask(s.size(), i) > ask(s.size(), 0))
                break;
            int l = 0, r = s.size();
            while (l < r - 1)
            {
                int m = l + r >> 1;
                if (ask(m, i) <= ask(m, 0))
                    r = m;
                else 
                    l = m;
            }
            int t = get(r);
            g[i].push_back(t);
            g[t].push_back(i);
            // cout << "EDGE " << i << ' ' << t << endl;
            tmp.push_back(t);
            s.erase(t);
        }
        for (int t : tmp)
            s.insert(t);
    }
    for (int i = 1; i <= n; i++)
        if (g[i].size() == 1)
        {
            vector<int> res;
            s.insert(i);
            int u = i;
            while (1)
            {
                res.push_back(u);
                bool b = 0;
                for (auto v : g[u])
                    if (s.find(v) == s.end())
                    {
                        b = 1;
                        u = v;
                        break;
                    }
                s.insert(u);
                if (!b)
                    break;
            }
            Answer(res);
            return;
        }
}

// int main()
// {
//     int n;
//     cin >> n;
//     Solve(n);
// }

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from library.cpp:2:
library.cpp: In function 'int get(int)':
library.cpp:67:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     assert(x <= s.size());
      |            ~~^~~~~~~~~~~
library.cpp: In function 'void Solve(int)':
library.cpp:101:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  101 |                 int m = l + r >> 1;
      |                         ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 63 ms 2640 KB # of queries: 5646
2 Correct 76 ms 3424 KB # of queries: 5522
3 Correct 63 ms 3036 KB # of queries: 5832
4 Correct 69 ms 3120 KB # of queries: 5834
5 Correct 68 ms 3172 KB # of queries: 5868
6 Correct 80 ms 2816 KB # of queries: 5788
7 Correct 98 ms 3004 KB # of queries: 5820
8 Correct 72 ms 2836 KB # of queries: 5568
9 Correct 71 ms 2936 KB # of queries: 5868
10 Correct 39 ms 1360 KB # of queries: 3464
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 1 ms 344 KB # of queries: 4
13 Correct 1 ms 344 KB # of queries: 12
14 Correct 0 ms 344 KB # of queries: 22
15 Correct 1 ms 344 KB # of queries: 182
16 Correct 4 ms 488 KB # of queries: 436
# Verdict Execution time Memory Grader output
1 Correct 63 ms 2640 KB # of queries: 5646
2 Correct 76 ms 3424 KB # of queries: 5522
3 Correct 63 ms 3036 KB # of queries: 5832
4 Correct 69 ms 3120 KB # of queries: 5834
5 Correct 68 ms 3172 KB # of queries: 5868
6 Correct 80 ms 2816 KB # of queries: 5788
7 Correct 98 ms 3004 KB # of queries: 5820
8 Correct 72 ms 2836 KB # of queries: 5568
9 Correct 71 ms 2936 KB # of queries: 5868
10 Correct 39 ms 1360 KB # of queries: 3464
11 Correct 0 ms 344 KB # of queries: 0
12 Correct 1 ms 344 KB # of queries: 4
13 Correct 1 ms 344 KB # of queries: 12
14 Correct 0 ms 344 KB # of queries: 22
15 Correct 1 ms 344 KB # of queries: 182
16 Correct 4 ms 488 KB # of queries: 436
17 Runtime error 521 ms 40660 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -