Submission #255225

# Submission time Handle Problem Language Result Execution time Memory
255225 2020-07-31T15:13:28 Z Kastanda parentrises (BOI18_parentrises) C++11
50 / 100
70 ms 7540 KB
// M
#include<bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, q, Sub;
char S[N];
void SolveSub1()
{
        scanf("%d", &q);
        for (; q; q --)
        {
                scanf("%s", S);
                n = strlen(S);
                vector < int > C(n, 0), Stk, OP;
                for (int i = 0; i < n; i ++)
                {
                        if (S[i] == '(')
                                Stk.push_back(i);
                        else if (Stk.size())
                                C[Stk.back()] = C[i] = 1, Stk.pop_back();
                        else
                                OP.push_back(i);
                }
                bool Fail = 0;
                vector < int > Kts, PO;
                for (int i = n - 1; ~ i; i --)
                {
                        if (Stk.size())
                        {
                                if (Stk.back() == i)
                                {
                                        if (!Kts.size())
                                                {Fail = 1; break;}
                                        C[Kts.back()] += 2;
                                        Kts.pop_back();
                                        C[Stk.back()] += 2;
                                        Stk.pop_back();
                                        continue;
                                }
                                if (S[i] == '(')
                                        continue;
                                Kts.push_back(i);
                        }
                        else
                        {
                                if (OP.size() && OP.back() == i)
                                {
                                        PO.push_back(OP.back());
                                        OP.pop_back();
                                        continue;
                                }
                                if (S[i] == ')')
                                        continue;
                                if (PO.size())
                                {
                                        C[PO.back()] += 2;
                                        PO.pop_back();
                                        C[i] += 2;
                                }
                        }
                }
                if (PO.size() || OP.size() || Stk.size())
                        Fail = 1;
                fill(S, S + n, 0);
                if (Fail)
                        printf("impossible\n");
                else
                {
                        for (int i = 0; i < n; i ++)
                                printf("%c", "RBG"[C[i] - 1]);
                        printf("\n");
                }
        }
        exit(0);
}
int main()
{
        scanf("%d", &Sub);
        if (Sub == 1)
                SolveSub1();
}

Compilation message

parentrises.cpp: In function 'void SolveSub1()':
parentrises.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &q);
         ~~~~~^~~~~~~~~~
parentrises.cpp:12:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%s", S);
                 ~~~~~^~~~~~~~~
parentrises.cpp: In function 'int main()':
parentrises.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &Sub);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 7 ms 512 KB Output is correct
17 Correct 7 ms 1024 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 6 ms 896 KB Output is correct
20 Correct 10 ms 1280 KB Output is correct
21 Correct 59 ms 2168 KB Output is correct
22 Correct 70 ms 7540 KB Output is correct
23 Correct 51 ms 2940 KB Output is correct
24 Correct 57 ms 4972 KB Output is correct
25 Correct 64 ms 7288 KB Output is correct
# 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