Submission #423713

# Submission time Handle Problem Language Result Execution time Memory
423713 2021-06-11T11:41:43 Z egekabas parentrises (BOI18_parentrises) C++14
50 / 100
59 ms 7276 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
void solve1(){
    string s;
    cin >> s;
    int n = s.size();
    int cur = 0;
    int mini = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == '(')
            cur++;
        else
            cur--;
        mini = min(mini, cur);
    }
    vector<int> ans(n);
    mini *= -1;
    for(int i = 0; i < n; ++i){
        if(mini > 0 && s[i] == '('){
            ans[i] = 1;
            --mini;
            ++cur;
        }
    }
    if(mini > 0){
        cout << "impossible\n";
        return;
    }
    for(int i = n-1; i >= 0; --i){
        if(s[i] == '(')
            continue;
            
        if(cur > 0){
            ans[i] = 1;
            --cur;
        }
    }
    if(cur > 0){
        cout << "impossible\n";
        return;
    }
    cur = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == '(')
            cur++;
        else
            cur--;
        if(ans[i]){
            if(s[i] == '(')
                cur++;
            else
                cur--;    
        }
        if(cur < 0){
            cout << "impossible\n";
            return;
        }
    }
    int val[2] = {0, 0};
    char c[3] = {'R', 'B', 'G'};
    for(int i = 0; i < n; ++i){
        //cout << '\n' << val[0] << ' ' << val[1] << '\n';
        if(ans[i]){
            cout << c[2];
            if(s[i] == '('){
                ++val[0];
                ++val[1];
            }
            else{
                --val[0];
                --val[1];
            }
        }
        else{
            if(s[i] == '('){
                if(val[0] < val[1]){
                    ++val[0];
                    cout << c[0];
                }
                else{
                    ++val[1];
                    cout << c[1];
                }
            }
            else{
                if(val[0] > val[1]){
                    --val[0];
                    cout << c[0];
                }
                else{
                    --val[1];
                    cout << c[1];
                }
            }
        }
    }
    cout << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    int p;
    cin >> p;
    if(p == 1){
        int t;
        cin >> t;
        while(t--)
            solve1();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 4 ms 448 KB Output is correct
17 Correct 6 ms 1100 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
19 Correct 5 ms 708 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
21 Correct 30 ms 1996 KB Output is correct
22 Correct 57 ms 7196 KB Output is correct
23 Correct 38 ms 2620 KB Output is correct
24 Correct 59 ms 4048 KB Output is correct
25 Correct 56 ms 7276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected