Submission #1268659

#TimeUsernameProblemLanguageResultExecution timeMemory
1268659urd05Superpozicija (COCI22_superpozicija)C++20
0 / 110
132 ms532 KiB
# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

int n;
char s[200005];
typedef pair<int,int> P;
P arr[200005];
int chk[25];

int main() {
    int tc;
    scanf("%d",&tc);
    for(int t=0;t<tc;t++) {
        scanf("%d",&n);
        scanf("%s",s+1);
        for(int i=0;i<n;i++) {
            scanf("%d %d",&arr[i].first,&arr[i].second);
        }
        int ret=-1;
        for(int bit=(1<<n)-1;bit>=0;bit--) {
            memset(chk,0,sizeof(chk));
            for(int i=0;i<n;i++) {
                if (bit&(1<<i)) {
                    chk[arr[i].second]=1;
                }
                else {
                    chk[arr[i].first]=1;
                }
            }
            int mn=0;
            int sum=0;
            for(int i=1;i<=n*2;i++) {
                if (chk[i]) {
                    if (s[i]=='(') {
                        sum++;
                    }
                    else {
                        sum--;
                    }
                    mn=min(mn,sum);
                }
            }
            if (sum==0&&mn==0) {
                ret=bit;
                break;
            }
        }
        if (ret==-1) {
            printf("-1\n");
            continue;
        }
        for(int i=0;i<n;i++) {
            if (ret&(1<<i)) {
                printf("1 ");
            }
            else {
                printf("0 ");
            }
        }
        printf("\n");
    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d",&tc);
      |     ~~~~~^~~~~~~~~~
Main.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
Main.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%s",s+1);
      |         ~~~~~^~~~~~~~~~
Main.cpp:20:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |             scanf("%d %d",&arr[i].first,&arr[i].second);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...