답안 #710887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710887 2023-03-16T03:51:25 Z ToroTN 사육제 (CEOI14_carnival) C++14
100 / 100
19 ms 208 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int n,p[155],st,md,ed,con,r,l,hsh[155],cnt=0;
set<int> s;
vector<int> v,g;
int f(int a)
{
    if(p[a]==a)
    {
        return a;
    }
    return p[a]=f(p[a]);
}
void un(int b,int c)
{p[f(b)]=f(c);}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)p[i]=i;
    while(1)
    {
        s.clear(),v.clear();
        for(int i=1;i<=n;i++)s.insert(f(i));
        for(auto it=s.begin();it!=s.end();it++)v.pb(*it);
        st=0,ed=v.size()-1;
        while(ed>=st)
        {
            g.clear();
            md=(st+ed)/2;
            for(int i=0;i<=md;i++)g.pb(v[i]);
            printf("%d ",g.size());
            for(auto node:g)printf("%d ",node);
            printf("\n");
            fflush(stdout);
            scanf("%d",&con);
            if(con==g.size())
            {
                st=md+1;
            }else
            {
                ed=md-1;
            }
        }
        r=st;
        if(r==v.size())break;
        ed=r;
        st=0;
        while(ed>=st)
        {
            g.clear();
            md=(st+ed)/2;
            for(int i=md;i<=r;i++)g.pb(v[i]);
            printf("%d ",g.size());
            for(auto node:g)printf("%d ",node);
            printf("\n");
            fflush(stdout);
            scanf("%d",&con);
            if(con==g.size())
            {
                ed=md-1;
            }else
            {
                st=md+1;
            }
        }
        l=ed;
        un(v[l],v[r]);
    }
    for(int i=1;i<=n;i++)
    {
        if(hsh[f(i)]==0)
        {
            ++cnt;
            hsh[f(i)]=cnt;
        }
    }
    printf("0 ");
    for(int i=1;i<=n;i++)
    {
        printf("%d ",hsh[f(i)]);
    }
    printf("\n");
    fflush(stdout);
    return 0;
}

Compilation message

carnival.cpp: In function 'int main()':
carnival.cpp:32:22: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   32 |             printf("%d ",g.size());
      |                     ~^   ~~~~~~~~
      |                      |         |
      |                      int       std::vector<int>::size_type {aka long unsigned int}
      |                     %ld
carnival.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             if(con==g.size())
      |                ~~~^~~~~~~~~~
carnival.cpp:46:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if(r==v.size())break;
      |            ~^~~~~~~~~~
carnival.cpp:54:22: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   54 |             printf("%d ",g.size());
      |                     ~^   ~~~~~~~~
      |                      |         |
      |                      int       std::vector<int>::size_type {aka long unsigned int}
      |                     %ld
carnival.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             if(con==g.size())
      |                ~~~^~~~~~~~~~
carnival.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
carnival.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |             scanf("%d",&con);
      |             ~~~~~^~~~~~~~~~~
carnival.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |             scanf("%d",&con);
      |             ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 208 KB Output is correct
2 Correct 11 ms 208 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 12 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 15 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 208 KB Output is correct
2 Correct 17 ms 208 KB Output is correct
3 Correct 6 ms 208 KB Output is correct
4 Correct 4 ms 208 KB Output is correct
5 Correct 12 ms 208 KB Output is correct
6 Correct 9 ms 208 KB Output is correct
7 Correct 13 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 208 KB Output is correct
2 Correct 15 ms 208 KB Output is correct
3 Correct 18 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 8 ms 208 KB Output is correct
6 Correct 12 ms 208 KB Output is correct
7 Correct 16 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 208 KB Output is correct
2 Correct 16 ms 208 KB Output is correct
3 Correct 5 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 13 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 11 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 15 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 9 ms 208 KB Output is correct
5 Correct 12 ms 208 KB Output is correct
6 Correct 9 ms 208 KB Output is correct
7 Correct 3 ms 208 KB Output is correct