# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
500382 | SirCovidThe19th | 괄호 문자열 (CEOI16_match) | C++17 | 22 ms | 12856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
int n, dp[100005][26]; string s; char ans[100005];
void solve(int l, int r){
if (l > r) return;
int pt = dp[r][s[l] - 'a']; //l matches with pt
ans[l] = '('; ans[pt] = ')';
solve(l + 1, pt - 1); solve(pt + 1, r);
}
int main(){
cin >> s; n = s.size();
stack<int> stk;
FOR(i, 0, n){
if (stk.empty() or s[stk.top()] != s[i]) stk.push(i);
else stk.pop();
}
if (!stk.empty()){ cout<<-1<<"\n"; return 0; }
memset(dp, -1, sizeof(dp));
FOR(i, 0, n) FOR(c, 0, 26){
if (s[i] - 'a' == c) dp[i][c] = i;
else if (i){
int l = dp[i - 1][s[i] - 'a']; //[l, i] is good
if (l > 0) dp[i][c] = dp[l - 1][c];
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |