# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
476128 | elgamalsalman | 괄호 문자열 (CEOI16_match) | C++14 | 2 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
bool validate(int l, int r) {
//cerr << "// validate(" << l << ", " << r << ")\n";
if (r < l) return 1;
int ind = 0;
for (int i = l + 1; i <= r; i++) {
if (s[l] == s[i]) ind = i;
}
if (!ind) return 0;
s[l] = '(';
s[ind] = ')';
return (validate(l + 1, ind - 1) && validate(ind + 1, r));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
freopen("match.in", "r", stdin);
freopen("match.out", "w", stdout);
cin >> s;
n = (int)s.size();
if (!validate(0, n - 1)) cout << "-1\n";
else cout << s << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |