답안 #484144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484144 2021-11-02T07:58:49 Z dxz05 사육제 (CEOI14_carnival) C++14
100 / 100
57 ms 436 KB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 222;

int p[N];

int find(int x){
    return (x == p[x] ? x : p[x] = find(p[x]));
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rng() & 1) swap(x, y);
    p[x] = y;
}

vector<int> mv(int l, int r){
    vector<int> res;
    while (l <= r) res.push_back(l++);
    return res;
}

int sz(vector<int> v){
    set<int> s;
    for (int i : v) s.insert(find(i));
    return s.size();
}

int ask(vector<int> v){
    cout << v.size() << ' ';
    for (int i : v) cout << i << ' ';
    cout << endl;

    int res;
    cin >> res;
    return res;
}

void solve(int TC) {
    int n;
    cin >> n;

    iota(p + 1, p + n + 1, 1);

    vector<bool> used(n + 1, false);
    for (int i = 1; i < n; i++){
        while (true) {
            int l = i + 1, r = n;
            int ind = i;
            while (l <= r) {
                int m = (l + r) >> 1;
                if (ask(mv(i, m)) == sz(mv(i, m))) {
                    ind = m;
                    l = m + 1;
                } else r = m - 1;
            }

            if (ind == n) break;
            if (used[ind]) continue;
            used[ind] = true;

            l = i, r = ind;
            ind++;
            int ind2 = i;
            while (l <= r) {
                int m = (l + r) >> 1;
                if (ask(mv(m, ind)) < sz(mv(m, ind))) {
                    ind2 = m;
                    l = m + 1;
                } else r = m - 1;
            }

            unite(ind2, ind);
//        debug(ind2, ind);
        }
    }

    map<int, int> mp;
    for (int i = 1; i <= n; i++){
        int x = find(i);
        if (mp.find(x) == mp.end()) mp[x] = mp.size() + 1;
    }

    cout << 0 << ' ';
    for (int i = 1; i <= n; i++) {
        cout << mp[find(i)] << ' ';
    }
    cout << endl;


}

int main() {
    startTime = clock();
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

#ifdef dddxxz
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
//    cin >> TC;

    for (int test = 1; test <= TC; test++) {
        //debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 200 KB Output is correct
2 Correct 31 ms 300 KB Output is correct
3 Correct 25 ms 328 KB Output is correct
4 Correct 17 ms 328 KB Output is correct
5 Correct 32 ms 308 KB Output is correct
6 Correct 38 ms 200 KB Output is correct
7 Correct 37 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 300 KB Output is correct
2 Correct 44 ms 200 KB Output is correct
3 Correct 18 ms 200 KB Output is correct
4 Correct 21 ms 200 KB Output is correct
5 Correct 42 ms 304 KB Output is correct
6 Correct 48 ms 316 KB Output is correct
7 Correct 32 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 308 KB Output is correct
2 Correct 39 ms 300 KB Output is correct
3 Correct 34 ms 200 KB Output is correct
4 Correct 20 ms 328 KB Output is correct
5 Correct 29 ms 300 KB Output is correct
6 Correct 35 ms 308 KB Output is correct
7 Correct 37 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 308 KB Output is correct
2 Correct 44 ms 432 KB Output is correct
3 Correct 35 ms 200 KB Output is correct
4 Correct 23 ms 328 KB Output is correct
5 Correct 38 ms 200 KB Output is correct
6 Correct 33 ms 304 KB Output is correct
7 Correct 57 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 436 KB Output is correct
2 Correct 49 ms 200 KB Output is correct
3 Correct 39 ms 320 KB Output is correct
4 Correct 33 ms 200 KB Output is correct
5 Correct 30 ms 308 KB Output is correct
6 Correct 29 ms 328 KB Output is correct
7 Correct 23 ms 200 KB Output is correct