Submission #1352097

#TimeUsernameProblemLanguageResultExecution timeMemory
1352097darkdevilvaqifCarnival (CEOI14_carnival)C++20
100 / 100
3 ms452 KiB
/*
  _      __        __         __        ____                    ___    _                   __
 | | /| / / ___ _ / /_ ____  / /       / __ \  ___  ___        / _ \  (_) ___  ____ ___   / /
 | |/ |/ / / _ `// __// __/ / _ \     / /_/ / / _ \/ -_)      / ___/ / / / -_)/ __// -_) /_/ 
 |__/|__/  \_,_/ \__/ \__/ /_//_/     \____/ /_//_/\__/      /_/    /_/  \__/ \__/ \__/ (_)  
                                                                                             
*/

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define all(v) v.begin(), v.end()
#define allr(v, l, r) v.begin() + l, v.begin() + r + 1
#define rall(v) v.rbegin(), v.rend()
#define rallr(v, l, r) v.rbegin() + ((int)v.size() - 1 - r), v.rbegin() + ((int)v.size() - l)
// #define endl "\n"
#define newline cout << endl;
using namespace std;
 
// constants
const int INF = 1e9;

// functions

// structs

// globals

// notes
/*
 -stuff you should look for-
* int overflow, array bounds
* special cases (n=1?)
* do something instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH

continue - skip the rest in the loop
*/
 
void solve()
{
    auto ask = [&](vector <int> vec)
    {
        cout << (int)vec.size();
        for (auto x : vec)
        {
            cout << ' ' << x;
        }
        newline
        
        int x;
        cin >> x;
        return x;
    };
    
    int n;
    cin >> n;
    
    vector <int> res(n + 1), dp(n + 1);
    res[1] = dp[1] = 1;
    int lst = 1;
    
    auto check = [&](int L, int R, int k) -> bool
    {
        vector <int> forq;
        set <int> s;
        for (int i = L; i <= R; i++)
        {
            s.insert(res[i]);
            forq.push_back(i);
        }
        forq.push_back(k);
        
        int x = ask(forq);
        return !((int)s.size() + 1 == x);
    };
    
    for (int i = 2; i <= n; i++)
    {
        vector <int> forq;
        for (int j = 1; j <= i; j++)
        {
            forq.push_back(j);
        }
        
        int x = ask(forq);
        dp[i] = x;
        if (x == dp[i - 1] + 1)
        {
            res[i] = ++lst;
            continue;
        }
        
        int l = 1, r = i - 1;
        while (r - l > 1)
        {
            int mid = (l + r) / 2;
            
            if (check(l, mid, i))
            {
                r = mid;
            }
            else
            {
                l = mid;
            }
        }
        
        if (l == r)
        {
            res[i] = res[l];
        }
        else
        {
            vector <int> forq;
            forq.push_back(l);
            forq.push_back(i);
            if (ask(forq) == 1)
            {
                res[i] = res[l];
            }
            else
            {
                res[i] = res[r];
            }
        }
    }
    
    cout << 0;
    for (int i = 1; i <= n; i++)
    {
        cout << ' ' << res[i];
    }
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int testcount = 1;
    // cin >> testcount;
    while (testcount--)
    {
        solve();
        newline
    }
}

/*
$$$$$$$$\ $$$$$$$$\ 
$$  _____|\____$$  |
$$ |          $$  / 
$$$$$\       $$  /  
$$  __|     $$  /   
$$ |       $$  /    
$$$$$$$$\ $$$$$$$$\ 
\________|\________|
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...