답안 #373348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373348 2021-03-04T08:25:56 Z arujbansal 사육제 (CEOI14_carnival) C++17
100 / 100
11 ms 508 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <numeric>
#include <functional>
#include <chrono>
#include <utility>
#include <iomanip>
#include <assert.h>

using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rng_seed(x) mt19937 rng(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
// #define int long long

const int MXN = 155, INF = 1e9 + 5;
vector<int> distinct;
vector<vector<int>> versions;
int col[MXN];

int query(const vector<int> &people) {
    cout << sz(people) << " ";
    for (const auto &x : people)
        cout << x << " ";
    cout << endl;

    int ans;
    cin >> ans;

    return ans;
}

bool check(int version, int person) {
    versions[version].push_back(person);
    bool ans = (query(versions[version]) <= sz(versions[version]) - 1);
    versions[version].pop_back();

    return ans;
}

void solve() {
    int N;
    cin >> N;

    distinct = {1};
    int last = 1;

    vector<int> to_assign;

    for (int i = 2; i <= N; i++) {
        distinct.push_back(i);

        int qry = query(distinct);

        if (qry <= last) {
            distinct.pop_back();
            to_assign.push_back(i);
        } else {
            last = qry;
        }
    }

    for (int i = 0; i < sz(distinct); i++)
        col[distinct[i]] = i + 1;

    versions.emplace_back();

    vector<int> cur;
    for (int i = 0; i < sz(distinct); i++) {
        cur.push_back(distinct[i]);
        versions.push_back(cur);
    }

    for (const auto &x : to_assign) {
        int lo = 1, hi = sz(versions) - 1, ans = sz(versions);

        while (lo <= hi) {
            int mid = (lo + hi) / 2;

            if (check(mid, x)) {
                ans = min(ans, mid);
                hi = mid - 1;
            } else lo = mid + 1;
        }

        col[x] = col[versions[ans].back()];
    }

    cout << "0 ";
    for (int i = 1; i <= N; i++)
        cout << col[i] << " ";

    cout << endl;
}

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

    int TC = 1;
    // cin >> TC;
    while (TC--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 364 KB Output is correct
2 Correct 6 ms 364 KB Output is correct
3 Correct 9 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 8 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 364 KB Output is correct
2 Correct 10 ms 364 KB Output is correct
3 Correct 4 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 8 ms 364 KB Output is correct
6 Correct 7 ms 364 KB Output is correct
7 Correct 7 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 364 KB Output is correct
2 Correct 6 ms 364 KB Output is correct
3 Correct 11 ms 364 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 9 ms 364 KB Output is correct
6 Correct 8 ms 364 KB Output is correct
7 Correct 11 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 364 KB Output is correct
2 Correct 7 ms 364 KB Output is correct
3 Correct 5 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 9 ms 364 KB Output is correct
6 Correct 7 ms 364 KB Output is correct
7 Correct 8 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 8 ms 364 KB Output is correct
3 Correct 8 ms 508 KB Output is correct
4 Correct 10 ms 492 KB Output is correct
5 Correct 10 ms 416 KB Output is correct
6 Correct 6 ms 364 KB Output is correct
7 Correct 4 ms 364 KB Output is correct