Submission #730705

# Submission time Handle Problem Language Result Execution time Memory
730705 2023-04-26T09:51:53 Z Augustyn Superpozicija (COCI22_superpozicija) C++17
20 / 110
31 ms 2800 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>>,greater<pair<int,int>>>dod;
    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;
                    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()
{
    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:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%s",naw);
      |     ~~~~~^~~~~~~~~~
Main.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d%d",&ab[i].first,&ab[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:105:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 340 KB Output is correct
2 Correct 23 ms 972 KB Output is correct
3 Correct 24 ms 1108 KB Output is correct
4 Correct 24 ms 1184 KB Output is correct
5 Correct 27 ms 1128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 304 KB Output is correct
2 Correct 18 ms 556 KB Output is correct
3 Correct 15 ms 836 KB Output is correct
4 Correct 18 ms 980 KB Output is correct
5 Correct 15 ms 1236 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 14 ms 1844 KB Output is correct
8 Correct 17 ms 2092 KB Output is correct
9 Correct 20 ms 2352 KB Output is correct
10 Correct 25 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 21 ms 324 KB Output is correct
3 Correct 26 ms 596 KB Output is correct
4 Correct 31 ms 976 KB Output is correct
5 Correct 23 ms 1248 KB Output is correct
6 Runtime error 23 ms 2800 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 340 KB Output is correct
2 Correct 23 ms 972 KB Output is correct
3 Correct 24 ms 1108 KB Output is correct
4 Correct 24 ms 1184 KB Output is correct
5 Correct 27 ms 1128 KB Output is correct
6 Correct 19 ms 304 KB Output is correct
7 Correct 18 ms 556 KB Output is correct
8 Correct 15 ms 836 KB Output is correct
9 Correct 18 ms 980 KB Output is correct
10 Correct 15 ms 1236 KB Output is correct
11 Correct 11 ms 1492 KB Output is correct
12 Correct 14 ms 1844 KB Output is correct
13 Correct 17 ms 2092 KB Output is correct
14 Correct 20 ms 2352 KB Output is correct
15 Correct 25 ms 2516 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 21 ms 324 KB Output is correct
18 Correct 26 ms 596 KB Output is correct
19 Correct 31 ms 976 KB Output is correct
20 Correct 23 ms 1248 KB Output is correct
21 Runtime error 23 ms 2800 KB Execution killed with signal 6
22 Halted 0 ms 0 KB -