| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1117847 | AtabayRajabli | 괄호 문자열 (CEOI16_match) | C++17 | 1 ms | 592 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define int long long
using namespace std;
void f(int l, int r, string &s, string &t, vector<vector<int>> &last)
{
if(l > r) return;
int pos = last[r][s[l] - 'a'];
t[l] = '(', t[pos] = ')';
f(l + 1, pos - 1, s, t, last), f(pos + 1, r, s, t, last);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
vector<vector<int>> last(s.size(), vector<int>(26, -1));
stack<int> st;
for(int i = 0; i < s.size(); i++)
{
if(!st.empty() && s[st.top()] == s[i]) st.pop();
else st.push(i);
}
if(!st.empty())
{
cout << -1;
return 0;
}
for(int i = 0; i < s.size(); i++)
{
last[i][s[i] - 'a'] = i;
for(int j = 0; j < 26 && i > 0; j++)
{
last[i][j] = max(last[i - 1][j], last[i][j]);
}
}
string t(s.size(), ' ');
f(0, s.size() - 1, s, t, last);
cout << t;
}컴파일 시 표준 에러 (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... | ||||
