QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217064#5534. MatchCamillus#0 0ms3756kbC++201.1kb2023-10-16 13:24:222024-07-04 02:20:08

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:20:08]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3756kb
  • [2023-10-16 13:24:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

signed main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#else
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    int n = (int)s.size();
    string t = s;

    vector<int> q;
    for (int i = 0; i < n; i++) {
        if (!q.empty() && s[q.back()] == s[i]) {
            t[i] = ')';
            q.pop_back();
        } else {
            t[i] = '(';
            q.push_back(i);
        }
    }

    if (!q.empty()) {
        cout << -1 << '\n';
    } else {
        for (int i = 0; i + 1 < n; i++) {
            if (s[i] == s[i + 1] && t[i] == ')' && t[i + 1] == '(') {
                for (int j = i; j >= 0; j--) {
                    if (s[j] == s[j + 1] && t[j] == ')' && t[j + 1] == '(') {
                        swap(t[j], t[j + 1]);
                    } else {
                        break;
                    }
                }
            }
        }
        cout << t << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 3596kb

input:

abbaaa

output:

(()())

result:

ok single line: '(()())'

Test #2:

score: -10
Wrong Answer
time: 0ms
memory: 3756kb

input:

cbbbbccbbccbbbbbbc

output:

((())()()()((())))

result:

wrong answer 1st lines differ - expected: '(((((((()))())))))', found: '((())()()()((())))'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%