Submission #98571

# Submission time Handle Problem Language Result Execution time Memory
98571 2019-02-24T13:11:54 Z tdwn parentrises (BOI18_parentrises) C++17
50 / 100
178 ms 8420 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

string code;

void solve() {
    cin>>code;
    string answ = code;

    stack<int>s1, s2;
    for(int i=0;i<code.length();i++) {
        if(code[i] == '(') {
            s1.push(i);
        }
        else {
            if(s1.size() > 0) {
                answ[s1.top()] = answ[i] = 'R';
                s2.push(s1.top());
                s1.pop();
            }
            else if(s2.size() > 0) {
                answ[s2.top()] = 'G';
                answ[i] = 'B';
                s2.pop();
            }
            else {
                cout<<"impossible\n";
                return;
            }
        }
    }

    stack<int>t1, t2;
    for(int i=code.length()-1;i>=0;i--) {
        if(code[i] == ')') {
            t1.push(i);
        }
        else {
            if(answ[i] == 'R' || answ[i] == 'G') continue;
            else {
                if(t1.size() > 0) {
                    answ[i] = 'B';
                    answ[t1.top()] = 'G';
                    t1.pop();
                }
                else {
                    cout<<"impossible\n";
                    return;
                }
            }
        }
    }
    cout<<answ<<"\n";
    return;
}

int main() {
    int P, T;
    cin>>P;
    cin>>T;

    while(T--) {
        solve();
    }
    return 0;
}

Compilation message

parentrises.cpp: In function 'void solve()':
parentrises.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<code.length();i++) {
                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 368 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 368 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 368 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 6 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 23 ms 640 KB Output is correct
17 Correct 8 ms 1188 KB Output is correct
18 Correct 7 ms 640 KB Output is correct
19 Correct 9 ms 768 KB Output is correct
20 Correct 8 ms 1152 KB Output is correct
21 Correct 178 ms 2136 KB Output is correct
22 Correct 88 ms 8420 KB Output is correct
23 Correct 58 ms 2680 KB Output is correct
24 Correct 62 ms 4716 KB Output is correct
25 Correct 77 ms 8416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Expected integer, but "impossible" found
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Expected integer, but "impossible" found
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Expected integer, but "impossible" found