답안 #985892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
985892 2024-05-19T08:46:34 Z simona1230 사육제 (CEOI14_carnival) C++17
100 / 100
4 ms 716 KB
#include <bits/stdc++.h>

using namespace std;
int n,num;
int in[256];
int a[256];

int guess(vector<int> v)
{
    cout<<v.size()<<" ";
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    cout<<endl;

    cout.flush();

    int val;
    cin>>val;

    return val;
}

void solve()
{
    for(int i=1;i<=n;i++)
    {
        in[i]=1;
        vector<int> v;
        for(int j=1;j<=i;j++)
            if(in[j])v.push_back(j);

        int x=guess(v);
        if(x>num)
        {
            num++;
            a[i]=num;
            continue;
        }

        in[i]=0;

        vector<int> h;
        int ans=0;

        int l=0,r=v.size()-2;
        while(l<=r)
        {
            if(l==r)
            {
                ans=v[l];
                break;
            }
            int m=(l+r)/2;
            h.clear();
            for(int j=l;j<=m;j++)
                h.push_back(v[j]);
            h.push_back(i);
            x=guess(h);
            if(x==m-l+1)
            {
                r=m;
            }
            else
            {
                l=m+1;
            }
        }

        a[i]=a[ans];
    }

    cout<<"0 ";
    for(int i=1;i<=n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	solve();
	return 0;
}

Compilation message

carnival.cpp: In function 'int guess(std::vector<int>)':
carnival.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 2 ms 712 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
6 Correct 2 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 456 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
3 Correct 2 ms 708 KB Output is correct
4 Correct 2 ms 712 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 3 ms 456 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 3 ms 456 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 456 KB Output is correct
6 Correct 3 ms 712 KB Output is correct
7 Correct 2 ms 712 KB Output is correct