Submission #727896

# Submission time Handle Problem Language Result Execution time Memory
727896 2023-04-21T14:27:27 Z Augustyn Superpozicija (COCI22_superpozicija) C++17
0 / 110
28 ms 392 KB
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
char *naw;
vector<pair<int,int>>ab;
vector<int>juzwyb,gdziedr;
int t,n;
void rozw()
{
    scanf("%d",&n);
    priority_queue<pair<int,int>,vector<pair<int,int>>,less<pair<int,int>>>dod1_OZ,dod1_ZO_MAL;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>dod1_ZO,dod1_OZ_rosn;
    queue<int>dod2;
    delete[] naw;
    naw = new char[n<<1];
    ab.resize(n);
    juzwyb.resize(n<<1);
    gdziedr.resize(n<<1);
    scanf("%s",naw);
    for(int i=0;i<n;++i)
    {
        scanf("%d%d",&ab[i].first,&ab[i].second);
        --ab[i].first;
        --ab[i].second;
        gdziedr[ab[i].first]=ab[i].second;
        gdziedr[ab[i].second]=ab[i].first;
    }
    int ile=0;
    for(int i=0;i<2*n;++i)
    {
        if(naw[gdziedr[i]]==naw[i])
        {
            if(naw[i]=='('&&i<gdziedr[i])
            {
                juzwyb[i]=t;
                juzwyb[gdziedr[i]]=-t;
                ++ile;
            }
            else if(naw[i]==')'&&i>gdziedr[i])
            {
                juzwyb[i]=t;
                juzwyb[gdziedr[i]]=-t;
                --ile;
            }
        }
        else
        {
            if(juzwyb[i]!=-t&&juzwyb[i]!=t)
            {
                if(naw[i]=='(')
                {
                    juzwyb[i]=-t;
                    juzwyb[gdziedr[i]]=t;
                    dod1_OZ.push({gdziedr[i],i});
                    dod1_OZ_rosn.push({gdziedr[i],i});
                }
                else
                {
                    juzwyb[i]=t;
                    juzwyb[gdziedr[i]]=-t;
                    --ile;
                    dod1_ZO.push({gdziedr[i],i});
                    dod1_ZO_MAL.push({gdziedr[i],i});
                }
            }
            else
            {
                if(juzwyb[i]==t)
                {
                    if(naw[i]==')')
                    {
                        --ile;
                        dod2.push(i);
                    }
                    else
                        ++ile;
                }
                else
                {
                    if(naw[i]=='(')
                        dod2.push(gdziedr[i]);
                }
            }
        }
        ////cout<<ile<<endl;
        if(ile<0)
        {
            
            while(!dod2.empty())
            {
                if(juzwyb[dod2.front()]!=-t)
                    break;
                dod2.pop();
            }
            if(!dod2.empty())
            {
            
                juzwyb[dod2.front()]=-t;
                juzwyb[gdziedr[dod2.front()]]=t;
                dod2.pop();
                ile+=2;
            }
            else
            {
                while(!dod1_OZ.empty())
                {
                    if(juzwyb[dod1_OZ.top().second]!=t)
                        break;
                    dod1_OZ.pop();
                }
                if(!dod1_OZ.empty())
                {
                    if(dod1_OZ.top().first<gdziedr[i]||naw[gdziedr[i]]==naw[i])
                    {
                        while(!dod1_OZ_rosn.empty())
                        {
                            if(juzwyb[dod1_OZ_rosn.top().second]!=t)
                                break;
                            dod1_OZ_rosn.pop();
                        }
                        juzwyb[dod1_OZ_rosn.top().second]=t;
                        juzwyb[dod1_OZ_rosn.top().first]=-t;
                        ++ile;
                        dod1_OZ_rosn.pop();                        
                    }
                    else
                    {
                        juzwyb[gdziedr[i]]=t;
                        juzwyb[i]=-t;
                        ++ile;
                    }
                }
                else
                {
                    while(!dod1_ZO.empty())
                    {
                        if(juzwyb[dod1_ZO.top().second]==t)
                            break;
                        dod1_ZO.pop();
                    }
                    if(dod1_ZO.empty())
                    {
                        printf("-1\n");
                        return;
                    }
                    if(dod1_ZO.top().first<gdziedr[i]||naw[gdziedr[i]]==naw[i])
                    {
                        juzwyb[dod1_ZO.top().second]=-t;
                        juzwyb[dod1_ZO.top().first]=t;
                        ++ile;
                        dod1_ZO.pop();
                    }
                    else
                    {
                        juzwyb[gdziedr[i]]=t;
                        juzwyb[i]=-t;
                        ++ile;
                    }
                }
            }
        }
    //    cout<<i+1<<" "<<ile<<endl;
    //     //cout<<juzwyb[3]<<endl;
    //     for(int j=0;j<n;++j)
    //     {
    //         if(juzwyb[ab[j].first]==t)
    //             printf("0 ");
    //         else if(juzwyb[ab[j].first]==-t)
    //             printf("1 ");
    //         else 
    //             printf("n ");
    //     }
    //     printf("\n");
    }
    if(ile!=0)
    {
        printf("-1\n");
      //  return;
    }
    for(int i=0;i<n;++i)
    {
        if(juzwyb[ab[i].first]==t)
            printf("0 ");
        else
            printf("1 ");
    }
    printf("\n");
}
int main()
{
    scanf("%d",&t);
    while(t)
    {
        rozw();
        --t;
    }
}

Compilation message

Main.cpp: In function 'void rozw()':
Main.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%s",naw);
      |     ~~~~~^~~~~~~~~~
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d%d",&ab[i].first,&ab[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:192:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  192 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 392 KB Output isn't correct
2 Halted 0 ms 0 KB -