# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
65729 | 2018-08-08T14:12:00 Z | Namnamseo | 괄호 문자열 (CEOI16_match) | C++17 | 1823 ms | 2292 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pp; typedef pair<ll,ll> pll; void read(int& x){ scanf("%d",&x); } void read(ll& x){ scanf("%lld",&x); } template<typename T,typename... Args> void read(T& a,Args&... b){ read(a); read(b...); } #define all(x) (x).begin(),(x).end() #define pb push_back #define eb emplace_back #define x first #define y second int n; char s[100010]; char ans[100010]; char stk[100010]; int top; bool solve(int l, int r){ if(l>r) return 1; if(((r+l)&1) == 0) return 0; if(s[l] == s[r]){ ans[l]='('; ans[r]=')'; return solve(l+1, r-1); } top = 0; for(int i=r; l<=i; --i){ if(!top || stk[top-1] != s[i]) stk[top++] = s[i]; else { if(!--top && l < i-1 && s[l] == s[i-1]){ ans[l] = '('; ans[i-1] = ')'; return solve(l+1, i-2) && solve(i, r); } } } return 0; } int main() { scanf("%s", s+1); n = strlen(s+1); if(solve(1, n)){ puts(ans + 1); } else puts("-1"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 472 KB | Output is correct |
3 | Correct | 2 ms | 472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 472 KB | Output is correct |
3 | Correct | 2 ms | 472 KB | Output is correct |
4 | Correct | 3 ms | 472 KB | Output is correct |
5 | Correct | 2 ms | 476 KB | Output is correct |
6 | Correct | 2 ms | 480 KB | Output is correct |
7 | Correct | 2 ms | 484 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 472 KB | Output is correct |
3 | Correct | 2 ms | 472 KB | Output is correct |
4 | Correct | 3 ms | 472 KB | Output is correct |
5 | Correct | 2 ms | 476 KB | Output is correct |
6 | Correct | 2 ms | 480 KB | Output is correct |
7 | Correct | 2 ms | 484 KB | Output is correct |
8 | Correct | 3 ms | 668 KB | Output is correct |
9 | Correct | 9 ms | 668 KB | Output is correct |
10 | Correct | 4 ms | 736 KB | Output is correct |
11 | Correct | 3 ms | 760 KB | Output is correct |
12 | Correct | 64 ms | 1024 KB | Output is correct |
13 | Correct | 29 ms | 1156 KB | Output is correct |
14 | Correct | 479 ms | 1408 KB | Output is correct |
15 | Correct | 4 ms | 1408 KB | Output is correct |
16 | Correct | 4 ms | 1408 KB | Output is correct |
17 | Correct | 61 ms | 1452 KB | Output is correct |
18 | Correct | 9 ms | 1536 KB | Output is correct |
19 | Correct | 939 ms | 1880 KB | Output is correct |
20 | Correct | 371 ms | 1880 KB | Output is correct |
21 | Correct | 1823 ms | 2292 KB | Output is correct |