Submission #815876

#TimeUsernameProblemLanguageResultExecution timeMemory
815876PikachuCarnival (CEOI14_carnival)C++17
100 / 100
26 ms356 KiB
#include <bits/stdc++.h>

using namespace std;

template<typename T>
inline bool maxi(T &x, const T &val)
{
    if (x < val) return x = val, true;
    return false;
}

template<typename T>
inline bool mini(T &x, const T &val)
{
    if (x > val) return x = val, true;
    return false;
}

const int maxn = 155;
int n;
int ans[maxn];
bool last[maxn];
set<int> rem;

int getint()
{
    int tmp;
    cin >> tmp;
    return tmp;
}

int askrange(int l, int r)
{
    cout << r - l + 1 << ' ';
    for (int i = l; i <= r; i++) {
        cout << i << ' ';
    }
    cout << endl;
    return getint();
}

int askpair(int u, int v)
{
    cout << 2 << ' ' << u << ' ' << v << endl;
    return getint();
}

void erase(vector<int> &tmp)
{
    for (int x : tmp) {
        rem.erase(x);
    }
    tmp.clear();
}

void solve()
{
    cin >> n;
    int cur = askrange(1, n);
    last[n] = true;
    for (int i = 1; i < n; i++) {
        if (askrange(i + 1, n) != cur) {
            last[i] = true;
            cur--;
        }
        else rem.insert(i);
    }
    int cnt = 0;
    vector<int> tmp;
    for (int i = 1; i <= n; i++) {
        if (last[i]) {
            ans[i] = ++cnt;
            for (int x : rem) {
                if (x > i) break;
                if (askpair(x, i) == 1) {
                    ans[x] = cnt;
                    tmp.push_back(x);
                }
            }
            erase(tmp);
        }
    }
    cout << "0 ";
    for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
    cout << endl;
}

signed main()
{
#ifdef LOCAL
    clock_t st = clock();
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

#define Task ""
#ifdef LOCAL
    if (!fopen("D:\\.inp", "r")) {
        freopen("D:\\.inp", "w", stdout);
        freopen("D:\\.out", "w", stdout);
        cerr << "get input from file\n";
        return 0;
    }
    freopen("D:\\.inp", "r", stdin);
    freopen("D:\\.out", "w", stdout);
#else
    if (fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
#endif

    solve();

#ifdef LOCAL
    cerr << clock() - st << endl;
#endif
}   

Compilation message (stderr)

carnival.cpp: In function 'int main()':
carnival.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen(Task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
carnival.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen(Task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...