답안 #727400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727400 2023-04-20T15:10:31 Z Augustyn Superpozicija (COCI22_superpozicija) C++17
10 / 110
29 ms 3928 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>>>dod1;
    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.push({i,gdziedr[i]});
                }
                else
                {
                    juzwyb[i]=t;
                    juzwyb[gdziedr[i]]=-t;
                    --ile;
                    dod1.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]);
                }
            }
        }
        if(ile<0)
        {
            
            while(!dod2.empty())
            {
                if(juzwyb[dod2.front()]!=-t)
                    break;
                dod2.pop();
            }
            if(dod2.empty())
            {
                while(!dod1.empty())
                {
                    if(juzwyb[dod1.top().second]!=-t)
                        break;
                    dod1.pop();
                }
                if(dod1.empty())
                {
                    printf("-1\n");
                    return;
                }
                juzwyb[dod1.top().second]=-t;
                juzwyb[dod1.top().first]=t;
                ++ile;
                dod1.pop();
            }
            else
            {
                juzwyb[dod2.front()]=-t;
                juzwyb[gdziedr[dod2.front()]]=t;
                dod2.pop();
                ile+=2;
            }
        }
    }
    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:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%s",naw);
      |     ~~~~~^~~~~~~~~~
Main.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d%d",&ab[i].first,&ab[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:135:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1184 KB Output is correct
2 Correct 24 ms 1692 KB Output is correct
3 Correct 19 ms 1844 KB Output is correct
4 Correct 20 ms 2212 KB Output is correct
5 Correct 19 ms 2388 KB Output is correct
6 Correct 16 ms 2260 KB Output is correct
7 Correct 17 ms 2644 KB Output is correct
8 Correct 19 ms 2976 KB Output is correct
9 Correct 20 ms 3412 KB Output is correct
10 Correct 28 ms 3864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 28 ms 1232 KB Output is correct
3 Correct 23 ms 1820 KB Output is correct
4 Correct 22 ms 2060 KB Output is correct
5 Correct 24 ms 2612 KB Output is correct
6 Runtime error 29 ms 3928 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 27 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -