답안 #91028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91028 2018-12-25T16:25:23 Z choikiwon parentrises (BOI18_parentrises) C++17
50 / 100
93 ms 9368 KB
#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;

string S, ans;

void main2() {
    cin >> S;

    int cnt = 0, open = 0;
    int mx1 = 0;
    int mx2 = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '(') cnt++, open++;
        else cnt--;
        mx1 = max(mx1, -cnt);
        if(-cnt > open) {
            cout << "impossible\n";
            return;
        }
    }
    cnt = open = 0;
    for(int i = (int)S.size() - 1; i >= 0; i--) {
        if(S[i] == ')') cnt++, open++;
        else cnt--;
        mx2 = max(mx2, -cnt);
        if(-cnt > open) {
            cout << "impossible\n";
            return;
        }
    }

    ans.clear();
    ans.resize(S.size());
    for(int i = 0; i < S.size(); i++) {
        if(mx1 && S[i] == '(') ans[i] = 'G', mx1--;
    }
    for(int i = (int)S.size() - 1; i >= 0; i--) {
        if(mx2 && S[i] == ')') ans[i] = 'G', mx2--;
    }

    int rg = 0;
    int bg = 0;
    for(int i = 0; i < S.size(); i++) {
        if(ans[i] == 'G') {
            if(S[i] == '(') rg++, bg++;
            else rg--, bg--;
        }
        else {
           if(S[i] == '(') {
                if(rg < bg) ans[i] = 'R', rg++;
                else ans[i] = 'B', bg++;
            }
            else {
                if(rg < bg) ans[i] = 'B', bg--;
                else ans[i] = 'R', rg--;
            }
        }
    }

    cout << ans << endl;
}

void main3() {

}

int P, TC;
int main() {
    std::ios::sync_with_stdio(false);

    cin >> P >> TC;
    if(P == 1) {
        while(TC--) main2();
    }
    if(P == 2) {
        while(TC--) main3();
    }
}

Compilation message

parentrises.cpp: In function 'void main2()':
parentrises.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < S.size(); i++) {
                    ~~^~~~~~~~~~
parentrises.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < S.size(); i++) {
                    ~~^~~~~~~~~~
parentrises.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < S.size(); i++) {
                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 9 ms 452 KB Output is correct
5 Correct 2 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
9 Correct 2 ms 704 KB Output is correct
10 Correct 2 ms 708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 700 KB Output is correct
9 Correct 2 ms 704 KB Output is correct
10 Correct 2 ms 708 KB Output is correct
11 Correct 2 ms 712 KB Output is correct
12 Correct 2 ms 784 KB Output is correct
13 Correct 2 ms 812 KB Output is correct
14 Correct 2 ms 840 KB Output is correct
15 Correct 2 ms 884 KB Output is correct
16 Correct 13 ms 1024 KB Output is correct
17 Correct 4 ms 1388 KB Output is correct
18 Correct 3 ms 1388 KB Output is correct
19 Correct 3 ms 1460 KB Output is correct
20 Correct 4 ms 1688 KB Output is correct
21 Correct 93 ms 3196 KB Output is correct
22 Correct 24 ms 6428 KB Output is correct
23 Correct 14 ms 6428 KB Output is correct
24 Correct 20 ms 7244 KB Output is correct
25 Correct 24 ms 9368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9368 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9368 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9368 KB Unexpected end of file - int32 expected