Submission #546245

#TimeUsernameProblemLanguageResultExecution timeMemory
546245yutabiZagrade (COI20_zagrade)C++14
100 / 100
707 ms4064 KiB
#include <bits/stdc++.h>
using namespace std;

struct pos
{
    int ptr=0;

    pos* l=NULL;
    pos* r=NULL;
};

pos* bas=new pos;

void rm(pos* nd)
{
    if(nd->l!=NULL)
    {
        nd->l->r=nd->r;
    }
    
    if(nd->r!=NULL)
    {
        nd->r->l=nd->l;
    }
    

    if(nd==bas && nd->r!=NULL)
    {
        bas=nd->r;
    }
}

int n;

int q;

int ans[100007];

int k;

int main()
{
    scanf("%d %d",&n,&q);

    pos* curr=bas;

    for(int i=1;i<n;i++)
    {
        pos* nw=new pos;
        nw->ptr=i;

        nw->l=curr;
        curr->r=nw;

        curr=nw;
    }

    curr=bas;

    for(int i=0;i<n;i++)
    {
        if(curr->l!=NULL)
        {
            printf("? %d %d\n",(curr->l->ptr)+1,(curr->ptr)+1);
            fflush(stdout);

            int a;

            scanf(" %d",&a);

            if(a==1)
            {
                ans[curr->l->ptr]=1;
                ans[curr->ptr]=2;

                rm(curr->l);
                rm(curr);

                k+=2;
            }

            else if(a!=0)
            {
                return 0;
            }
        }

        curr=curr->r;
    }

    curr=bas;

    for(int i=0;i<n-k;i++)
    {
        if(i*2<n-k)
        {
            ans[curr->ptr]=2;
        }

        else
        {
            ans[curr->ptr]=1;
        }

        curr=curr->r;
    }

    printf("! ");

    for(int i=0;i<n;i++)
    {
        if(ans[i]==1)
        {
            printf("(");
        }

        if(ans[i]==2)
        {
            printf(")");
        }
    }
    fflush(stdout);
}

Compilation message (stderr)

zagrade.cpp: In function 'int main()':
zagrade.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
zagrade.cpp:69:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |             scanf(" %d",&a);
      |             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...