Submission #730711

# Submission time Handle Problem Language Result Execution time Memory
730711 2023-04-26T10:11:08 Z Augustyn Superpozicija (COCI22_superpozicija) C++17
110 / 110
29 ms 4400 KB
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
vector<pair<int,int>>ab;
vector<char>naw;
vector<int>juzwyb,gdziedr;
int t,n;
void rozw()
{
    scanf("%d",&n);    
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>dod;
    ab.resize(n);
    juzwyb.resize(n<<1);
    gdziedr.resize(n<<1);
    naw.resize(n<<1);
    char wcz=getchar();
    while(wcz!='('&&wcz!=')')
        wcz=getchar();
    for(int i=0;i<(n<<1);++i)
    {
        naw[i]=wcz;
        wcz=getchar();
    }
    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;
                    dod.push({gdziedr[i],i});
                }
                else
                {
                    juzwyb[i]=t;
                    juzwyb[gdziedr[i]]=-t;
                    --ile;
                    dod.push({gdziedr[i],i});
                }
            }
            else
            {
                if(juzwyb[i]==t)
                {
                    if(naw[i]==')')
                        --ile;
                    else
                        ++ile;
                }
            }
        }
        if(ile<0)
        {
            if(dod.empty())
            {
                printf("-1\n");
                return;
            }
            juzwyb[dod.top().second]*=-1;
            juzwyb[dod.top().first]*=-1;
            ++ile;
            if(max(dod.top().first,dod.top().second)<=i)
                ++ile;
            dod.pop();
        }
    }
    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()
{
    ios_base::sync_with_stdio(0);
    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:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d%d",&ab[i].first,&ab[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:112:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 460 KB Output is correct
2 Correct 21 ms 324 KB Output is correct
3 Correct 24 ms 484 KB Output is correct
4 Correct 24 ms 468 KB Output is correct
5 Correct 23 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 336 KB Output is correct
2 Correct 18 ms 576 KB Output is correct
3 Correct 17 ms 724 KB Output is correct
4 Correct 18 ms 1100 KB Output is correct
5 Correct 16 ms 1368 KB Output is correct
6 Correct 12 ms 1600 KB Output is correct
7 Correct 14 ms 1748 KB Output is correct
8 Correct 17 ms 2004 KB Output is correct
9 Correct 17 ms 2260 KB Output is correct
10 Correct 20 ms 2624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 19 ms 340 KB Output is correct
3 Correct 22 ms 672 KB Output is correct
4 Correct 20 ms 992 KB Output is correct
5 Correct 20 ms 1352 KB Output is correct
6 Correct 22 ms 1788 KB Output is correct
7 Correct 10 ms 2228 KB Output is correct
8 Correct 17 ms 3004 KB Output is correct
9 Correct 17 ms 3468 KB Output is correct
10 Correct 21 ms 3904 KB Output is correct
11 Correct 25 ms 4304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 460 KB Output is correct
2 Correct 21 ms 324 KB Output is correct
3 Correct 24 ms 484 KB Output is correct
4 Correct 24 ms 468 KB Output is correct
5 Correct 23 ms 404 KB Output is correct
6 Correct 17 ms 336 KB Output is correct
7 Correct 18 ms 576 KB Output is correct
8 Correct 17 ms 724 KB Output is correct
9 Correct 18 ms 1100 KB Output is correct
10 Correct 16 ms 1368 KB Output is correct
11 Correct 12 ms 1600 KB Output is correct
12 Correct 14 ms 1748 KB Output is correct
13 Correct 17 ms 2004 KB Output is correct
14 Correct 17 ms 2260 KB Output is correct
15 Correct 20 ms 2624 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 19 ms 340 KB Output is correct
18 Correct 22 ms 672 KB Output is correct
19 Correct 20 ms 992 KB Output is correct
20 Correct 20 ms 1352 KB Output is correct
21 Correct 22 ms 1788 KB Output is correct
22 Correct 10 ms 2228 KB Output is correct
23 Correct 17 ms 3004 KB Output is correct
24 Correct 17 ms 3468 KB Output is correct
25 Correct 21 ms 3904 KB Output is correct
26 Correct 25 ms 4304 KB Output is correct
27 Correct 25 ms 1348 KB Output is correct
28 Correct 25 ms 1836 KB Output is correct
29 Correct 23 ms 2168 KB Output is correct
30 Correct 27 ms 2664 KB Output is correct
31 Correct 25 ms 2760 KB Output is correct
32 Correct 16 ms 2644 KB Output is correct
33 Correct 19 ms 3024 KB Output is correct
34 Correct 22 ms 3488 KB Output is correct
35 Correct 26 ms 3992 KB Output is correct
36 Correct 29 ms 4400 KB Output is correct