답안 #730703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730703 2023-04-26T09:48:09 Z Augustyn Superpozicija (COCI22_superpozicija) C++17
10 / 110
26 ms 3872 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({i,gdziedr[i]});
                }
                else
                {
                    juzwyb[i]=t;
                    juzwyb[gdziedr[i]]=-t;
                    --ile;
                    dod.push({i,gdziedr[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);
      |     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1168 KB Output is correct
2 Correct 20 ms 1680 KB Output is correct
3 Correct 24 ms 1836 KB Output is correct
4 Correct 21 ms 2260 KB Output is correct
5 Correct 16 ms 2380 KB Output is correct
6 Correct 11 ms 2232 KB Output is correct
7 Correct 15 ms 2596 KB Output is correct
8 Correct 18 ms 3012 KB Output is correct
9 Correct 20 ms 3452 KB Output is correct
10 Correct 22 ms 3872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 19 ms 1220 KB Output is correct
3 Correct 26 ms 1748 KB Output is correct
4 Correct 21 ms 2004 KB Output is correct
5 Correct 22 ms 2472 KB Output is correct
6 Runtime error 22 ms 3832 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -