Submission #730714

# Submission time Handle Problem Language Result Execution time Memory
730714 2023-04-26T10:25:23 Z Augustyn Superpozicija (COCI22_superpozicija) C++17
110 / 110
45 ms 3108 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pf printf
#define pii pair<int,int>
pii ab[200001];
char naw[200001];
int jb[200001],gr[200001];
int t,n;
void rozw()
{
    scanf("%d",&n);    
    priority_queue<pii ,vector<pii >,greater<pii >>dod;
    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].f,&ab[i].s);
        --ab[i].f;
        --ab[i].s;
        gr[ab[i].f]=ab[i].s;
        gr[ab[i].s]=ab[i].f;
    }
    int ile=0;
    for(int i=0;i<2*n;++i)
    {
        if(naw[gr[i]]==naw[i])
        {
            if(naw[i]=='('&&i<gr[i])
            {
                jb[i]=t;
                jb[gr[i]]=-t;
                ++ile;
            }
            else if(naw[i]==')'&&i>gr[i])
            {
                jb[i]=t;
                jb[gr[i]]=-t;
                --ile;
            }
        }
        else
        {
            if(jb[i]!=-t&&jb[i]!=t)
            {
                if(naw[i]=='(')
                {
                    jb[i]=-t;
                    jb[gr[i]]=t;
                    dod.push({gr[i],i});
                }
                else
                {
                    jb[i]=t;
                    jb[gr[i]]=-t;
                    --ile;
                    dod.push({gr[i],i});
                }
            }
            else
            {
                if(jb[i]==t)
                {
                    if(naw[i]==')')
                        --ile;
                    else
                        ++ile;
                }
            }
        }
        if(ile<0)
        {
            if(dod.empty())
            {
                pf("-1\n");
                return;
            }
            jb[dod.top().s]*=-1;
            jb[dod.top().f]*=-1;
            ++ile;
            if(max(dod.top().f,dod.top().s)<=i)
                ++ile;
            dod.pop();
        }
    }
    if(ile!=0)
    {
        pf("-1\n");
        return;
    }
    for(int i=0;i<n;++i)
    {
        if(jb[ab[i].f]==t)
            pf("0 ");
        else
            pf("1 ");
    }
    pf("\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:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d%d",&ab[i].f,&ab[i].s);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:110:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 460 KB Output is correct
2 Correct 22 ms 376 KB Output is correct
3 Correct 45 ms 432 KB Output is correct
4 Correct 29 ms 480 KB Output is correct
5 Correct 30 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 352 KB Output is correct
2 Correct 23 ms 604 KB Output is correct
3 Correct 17 ms 852 KB Output is correct
4 Correct 18 ms 1108 KB Output is correct
5 Correct 14 ms 1236 KB Output is correct
6 Correct 18 ms 1592 KB Output is correct
7 Correct 17 ms 1824 KB Output is correct
8 Correct 15 ms 2080 KB Output is correct
9 Correct 18 ms 2260 KB Output is correct
10 Correct 21 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 18 ms 388 KB Output is correct
3 Correct 18 ms 680 KB Output is correct
4 Correct 16 ms 1000 KB Output is correct
5 Correct 23 ms 1360 KB Output is correct
6 Correct 20 ms 1700 KB Output is correct
7 Correct 10 ms 1108 KB Output is correct
8 Correct 16 ms 2180 KB Output is correct
9 Correct 25 ms 2432 KB Output is correct
10 Correct 21 ms 2896 KB Output is correct
11 Correct 36 ms 3024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 460 KB Output is correct
2 Correct 22 ms 376 KB Output is correct
3 Correct 45 ms 432 KB Output is correct
4 Correct 29 ms 480 KB Output is correct
5 Correct 30 ms 428 KB Output is correct
6 Correct 22 ms 352 KB Output is correct
7 Correct 23 ms 604 KB Output is correct
8 Correct 17 ms 852 KB Output is correct
9 Correct 18 ms 1108 KB Output is correct
10 Correct 14 ms 1236 KB Output is correct
11 Correct 18 ms 1592 KB Output is correct
12 Correct 17 ms 1824 KB Output is correct
13 Correct 15 ms 2080 KB Output is correct
14 Correct 18 ms 2260 KB Output is correct
15 Correct 21 ms 2516 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 18 ms 388 KB Output is correct
18 Correct 18 ms 680 KB Output is correct
19 Correct 16 ms 1000 KB Output is correct
20 Correct 23 ms 1360 KB Output is correct
21 Correct 20 ms 1700 KB Output is correct
22 Correct 10 ms 1108 KB Output is correct
23 Correct 16 ms 2180 KB Output is correct
24 Correct 25 ms 2432 KB Output is correct
25 Correct 21 ms 2896 KB Output is correct
26 Correct 36 ms 3024 KB Output is correct
27 Correct 37 ms 484 KB Output is correct
28 Correct 25 ms 724 KB Output is correct
29 Correct 21 ms 1060 KB Output is correct
30 Correct 32 ms 1456 KB Output is correct
31 Correct 25 ms 1776 KB Output is correct
32 Correct 14 ms 2004 KB Output is correct
33 Correct 20 ms 2240 KB Output is correct
34 Correct 22 ms 2528 KB Output is correct
35 Correct 27 ms 2776 KB Output is correct
36 Correct 28 ms 3108 KB Output is correct