Submission #919518

# Submission time Handle Problem Language Result Execution time Memory
919518 2024-02-01T04:10:35 Z Alihan_8 Carnival (CEOI14_carnival) C++17
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

struct Dsu{
    // 0 - indexed
    vector <int> fa, sz;
    Dsu(int m){
        fa.resize(m);
        sz.resize(m);
        for ( int i = 0; i < m; i++ ){
            fa[i] = i; sz[i] = 1;
        }
    }
    int get(int x){
        return (x == fa[x] ? x : fa[x] = get(fa[x]));
    }
    bool merge(int u, int v){
        u = get(u), v = get(v);
        if ( u == v ){
            return false;
        }
        fa[v] = u;
        sz[u] += sz[v];
        return true;
    }
    bool same(int u, int v){
        return get(u) == get(v);
    }
    int size(int u){ return sz[get(u)]; }
};

int query(auto a){
    for ( auto &x: a ){
        cout << x + 1 << " ";
    } cout << ln;
    int c; cin >> c;
    return c;
}

void answer(auto &a){
    cout << "0 ";
    for ( auto &x: a ){
        cout << x << " ";
    } exit(0);
}

signed main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);

    int n; cin >> n;
    Dsu ds(n);
    for ( int i = 0; i < n; i++ ){
        for ( int j = i + 1; j < n; j++ ){
            if ( query(vector<int>{i, j}) != 2 ){
                ds.merge(i, j);
            }
        }
    }
    vector <int> c(n);
    int ct = 0;
    for ( int i = 0; i < n; i++ ){
        if ( !c[ds.get(i)] ){
            c[ds.get(i)] = ++ct;
        } c[i] = c[ds.get(i)];
    }
    answer(c);

    cout << '\n';
}

Compilation message

carnival.cpp:59:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   59 | int query(auto a){
      |           ^~~~
carnival.cpp:67:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   67 | void answer(auto &a){
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -