# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
52890 | 2018-06-27T06:35:53 Z | Petr(#1971) | 괄호 문자열 (CEOI16_match) | C++11 | 2000 ms | 392 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]; int al[100010][26]; bool even(int l, int r){ for(int i=0; i<26; ++i) if((al[r][i]+al[l-1][i])&1) return 0; return 1; } bool solve(int l, int r){ if(l > r) return 1; if(!even(l, r)) return 0; for(int i=r; l<i; --i){ if(((i-l)&1) == 1 && s[i]==s[l]){ ans[l] = '('; ans[i] = ')'; if(solve(l+1, i-1) && solve(i+1, r)) return 1; } } return 0; } int main() { scanf("%s", s+1); n = strlen(s+1); n = min(n, 2000); for(int i=1; i<=n; ++i){ copy(al[i-1], al[i-1]+26, al[i]); ++al[i][s[i]-'a']; } if(solve(1, n)){ puts(ans + 1); } else { puts("-1"); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 2 ms | 392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 2 ms | 392 KB | Output is correct |
4 | Execution timed out | 2082 ms | 392 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 2 ms | 392 KB | Output is correct |
4 | Execution timed out | 2082 ms | 392 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |