Submission #531823

#TimeUsernameProblemLanguageResultExecution timeMemory
531823christinelynn사육제 (CEOI14_carnival)C++17
100 / 100
19 ms320 KiB
#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>>segments;
int color[152];

int ask(int x, int y){
    cout << (y - x + 1) << " ";
    for(int i = x; i <= y; i++) cout << i << " ";
    cout << endl;
    int ret; cin >> ret;
    return ret;
}

int getSegment(int l, int r){
    vector<bool>mark(152);
    int cnt = 0;
    for(int i = l; i <= r; i++){
        if(!mark[color[i]]){
            mark[color[i]] = true;
            cnt++;
        }
    }

    return cnt;
}

int main(){ 
    int n; cin >> n;
    int L = 1, R = 1;

    for(int i = 1; i <= n; i++){
        int tmp = 0;
        if(i != n) tmp = ask(i, i + 1);

        if(tmp == 1) R = i + 1;
        else{
            segments.emplace_back(L, R);
            L = R = i + 1;
        }
    }

    color[0] = 1;
    color[1] = 2;
    int lc = 2;

    for(int i = 2; i < segments.size(); i++){
        int l = 0, r = i - 1;
        int col = lc + 1;

        while(l <= r){
            int m = (l + r)/2;

            int cursegment = getSegment(m, i - 1) + 1;
            int nahlo = ask(segments[m].first, segments[i].first);
            
            if(cursegment > nahlo){
                l = m + 1;
                col = color[m];
            } else{
                r = m - 1;
            }
        }

        if(col == lc + 1) lc++;

        color[i] = col;
    }   

    cout << "0 ";
    for(int i = 0; i < segments.size(); i++){
        auto &[l, r] = segments[i];
        for(int j = l; j <= r; j++) cout << color[i] << " ";
    }
    cout << endl;

    return 0;
}

Compilation message (stderr)

carnival.cpp: In function 'int main()':
carnival.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 2; i < segments.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~
carnival.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i = 0; i < segments.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~
#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...