Submission #248666

# Submission time Handle Problem Language Result Execution time Memory
248666 2020-07-13T03:05:01 Z thebes parentrises (BOI18_parentrises) C++14
0 / 100
0 ms 256 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 1e6+6, MM = 303;
int S, T, N, i, j, w[MN], cur, fl;
string s; stack<int> go;

int main(){
    scanf("%d",&S);
    if(S==1){
        scanf("%d",&T);
        while(T--){
            cin >> s; N = (int)s.size();
            for(i=1;i<=N;i++) w[i]=1;
            while(go.size()) go.pop();
            cur = fl = 0;
            for(i=0;i<N;i++){
                if(s[i]=='('){
                    cur++;
                    go.push(i);
                }
                else if(cur) cur--;
                else{
                    if(go.empty()){
                        fl=1;
                        break;
                    }
                    w[go.top()]=2;
                    go.pop();
                }
            }
            while(go.size()) go.pop();
            cur = 0;
            for(i=N-1;i>=0;i--){
                if(s[i]==')'){
                    cur++;
                    go.push(i);
                }
                else if(cur>=w[i]) cur-=w[i];
                else{
                    int r = cur;
                    cur = 0;
                    while(r<w[i]){
                        if(go.empty()){
                            fl=1;
                            break;
                        }
                        r++;
                        w[go.top()]=2;
                        go.pop();
                    }
                }
            }
            if(fl) printf("impossible\n");
            else{
                int hm = 0;
                for(i=0;i<N;i++){
                    if(w[i]==2) printf("G");
                    else printf("%c","BR"[hm]), hm=!hm;
                }
                printf("\n");
            }
        }
    }
}

Compilation message

parentrises.cpp: In function 'int main()':
parentrises.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&S);
     ~~~~~^~~~~~~~~
parentrises.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&T);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 0 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 256 KB Unexpected end of file - int32 expected