답안 #365450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365450 2021-02-11T17:11:18 Z lookcook parentrises (BOI18_parentrises) Java 11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int maxn = 1000005;
char res[maxn];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int p, t;
    cin >> p >> t;
    if (p == 1) {
        while (t--) {
            string s;
            cin >> s;
            bool ok = true;
            bool turn = true;
            int sr = 0;
            int sb = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s[i] == '(') {
                    res[i] = 'G';
                    sr++;
                    sb++;
                } else {
                    if (turn) {
                        res[i] = 'R';
                        sr--;
                    } else {
                        res[i] = 'B';
                        sb--;
                    }
                    turn = !turn;
                }
                if (sr < 0 || sb < 0) ok = false;
            }
            if (sb>sr) {
                for (int i = s.length()-1; i >= 0; i--) {
                    if (s[i] == '(') {
                        res[i] = 'R';
                        break;
                    }
                    if (s[i] == ')' && res[i] == 'R') {
                        res[i] = 'G';
                        break;
                    }
                }
            }
            sr = 0;
            sb = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s[i] == ')') {
                    if (res[i] == 'G') {
                        sr--;
                        sb--;
                    }
                    if (res[i] == 'R') sr--;
                    if (res[i] == 'B') sb--;
                } else {
                    if (res[i] == 'G') {
                        sr++;
                        sb++;
                    }
                    if (res[i] == 'R') sr++;
                    if (res[i] == 'B') sb++;
                }
                if (sr < 0 || sb < 0) ok = false;
            }
            for (int i = s.length()-1; i >= 0; i--) {
                if (s[i] == '(' && res[i] == 'G') {
                    if (sr>=sb && sr>0) { // maybe swap order?
                        sr--;
                        res[i] = 'B';
                    } else if (sb > 0) {
                        sb--;
                        res[i] = 'R';
                    }
                }
                if (s[i] == ')') {
                    if (res[i] == 'R' && sb>0) {
                        res[i] = 'G';
                        sb--;
                    } else if (res[i] == 'B' && sr>0) {
                        res[i] = 'G';
                        sr--;
                    }
                }
            }
            sr = 0;
            sb = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s[i] == ')') {
                    if (res[i] == 'G') {
                        sr--;
                        sb--;
                    }
                    if (res[i] == 'R') sr--;
                    if (res[i] == 'B') sb--;
                } else {
                    if (res[i] == 'G') {
                        sr++;
                        sb++;
                    }
                    if (res[i] == 'R') sr++;
                    if (res[i] == 'B') sb++;
                }
                if (sr < 0 || sb < 0) ok = false;
            }
            if (ok && sr==0&&sb==0) {
                for (int i = 0; i < s.length(); i++) cout << res[i];
                cout << '\n';
            } else {
                cout << "impossible\n";
            }
        }
    }
}

Compilation message

parentrises.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
parentrises.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
parentrises.java:3: error: illegal character: '#'
#define int long long
^
parentrises.java:7: error: class, interface, or enum expected
const int maxn = 1000005;
^
parentrises.java:8: error: class, interface, or enum expected
char res[maxn];
^
parentrises.java:10: error: class, interface, or enum expected
signed main() {
^
parentrises.java:12: error: class, interface, or enum expected
    cin.tie(0);
    ^
parentrises.java:13: error: class, interface, or enum expected
    int p, t;
    ^
parentrises.java:14: error: class, interface, or enum expected
    cin >> p >> t;
    ^
parentrises.java:15: error: class, interface, or enum expected
    if (p == 1) {
    ^
parentrises.java:18: error: class, interface, or enum expected
            cin >> s;
            ^
parentrises.java:19: error: class, interface, or enum expected
            bool ok = true;
            ^
parentrises.java:20: error: class, interface, or enum expected
            bool turn = true;
            ^
parentrises.java:21: error: class, interface, or enum expected
            int sr = 0;
            ^
parentrises.java:22: error: class, interface, or enum expected
            int sb = 0;
            ^
parentrises.java:23: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
            ^
parentrises.java:23: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
                            ^
parentrises.java:23: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
                                            ^
parentrises.java:26: error: class, interface, or enum expected
                    sr++;
                    ^
parentrises.java:27: error: class, interface, or enum expected
                    sb++;
                    ^
parentrises.java:28: error: class, interface, or enum expected
                } else {
                ^
parentrises.java:31: error: class, interface, or enum expected
                        sr--;
                        ^
parentrises.java:32: error: class, interface, or enum expected
                    } else {
                    ^
parentrises.java:34: error: class, interface, or enum expected
                        sb--;
                        ^
parentrises.java:35: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:37: error: class, interface, or enum expected
                }
                ^
parentrises.java:39: error: class, interface, or enum expected
            }
            ^
parentrises.java:41: error: class, interface, or enum expected
                for (int i = s.length()-1; i >= 0; i--) {
                                           ^
parentrises.java:41: error: class, interface, or enum expected
                for (int i = s.length()-1; i >= 0; i--) {
                                                   ^
parentrises.java:44: error: class, interface, or enum expected
                        break;
                        ^
parentrises.java:45: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:48: error: class, interface, or enum expected
                        break;
                        ^
parentrises.java:49: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:53: error: class, interface, or enum expected
            sb = 0;
            ^
parentrises.java:54: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
            ^
parentrises.java:54: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
                            ^
parentrises.java:54: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
                                            ^
parentrises.java:58: error: class, interface, or enum expected
                        sb--;
                        ^
parentrises.java:59: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:61: error: class, interface, or enum expected
                    if (res[i] == 'B') sb--;
                    ^
parentrises.java:62: error: class, interface, or enum expected
                } else {
                ^
parentrises.java:65: error: class, interface, or enum expected
                        sb++;
                        ^
parentrises.java:66: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:68: error: class, interface, or enum expected
                    if (res[i] == 'B') sb++;
                    ^
parentrises.java:69: error: class, interface, or enum expected
                }
                ^
parentrises.java:71: error: class, interface, or enum expected
            }
            ^
parentrises.java:72: error: class, interface, or enum expected
            for (int i = s.length()-1; i >= 0; i--) {
                                       ^
parentrises.java:72: error: class, interface, or enum expected
            for (int i = s.length()-1; i >= 0; i--) {
                                               ^
parentrises.java:76: error: class, interface, or enum expected
                        res[i] = 'B';
                        ^
parentrises.java:77: error: class, interface, or enum expected
                    } else if (sb > 0) {
                    ^
parentrises.java:79: error: class, interface, or enum expected
                        res[i] = 'R';
                        ^
parentrises.java:80: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:85: error: class, interface, or enum expected
                        sb--;
                        ^
parentrises.java:86: error: class, interface, or enum expected
                    } else if (res[i] == 'B' && sr>0) {
                    ^
parentrises.java:88: error: class, interface, or enum expected
                        sr--;
                        ^
parentrises.java:89: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:93: error: class, interface, or enum expected
            sb = 0;
            ^
parentrises.java:94: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
            ^
parentrises.java:94: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
                            ^
parentrises.java:94: error: class, interface, or enum expected
            for (int i = 0; i < s.length(); i++) {
                                            ^
parentrises.java:98: error: class, interface, or enum expected
                        sb--;
                        ^
parentrises.java:99: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:101: error: class, interface, or enum expected
                    if (res[i] == 'B') sb--;
                    ^
parentrises.java:102: error: class, interface, or enum expected
                } else {
                ^
parentrises.java:105: error: class, interface, or enum expected
                        sb++;
                        ^
parentrises.java:106: error: class, interface, or enum expected
                    }
                    ^
parentrises.java:108: error: class, interface, or enum expected
                    if (res[i] == 'B') sb++;
                    ^
parentrises.java:109: error: class, interface, or enum expected
                }
                ^
parentrises.java:111: error: class, interface, or enum expected
            }
            ^
parentrises.java:113: error: class, interface, or enum expected
                for (int i = 0; i < s.length(); i++) cout << res[i];
                                ^
parentrises.java:113: error: class, interface, or enum expected
                for (int i = 0; i < s.length(); i++) cout << res[i];
                                                ^
parentrises.java:114: error: class, interface, or enum expected
                cout << '\n';
                ^
parentrises.java:115: error: class, interface, or enum expected
            } else {
            ^
parentrises.java:117: error: class, interface, or enum expected
            }
            ^
74 errors