# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
608818 | 2022-07-27T10:27:39 Z | UncoolAnon | 괄호 문자열 (CEOI16_match) | C++14 | 0 ms | 212 KB |
#include <bits/stdc++.h> using namespace std; int ok=1; string answer,a; void solve(int l,int r){ vector<int> occ(26); int candidate=-1; occ[a[l]-'a']++; for(int i=l+1;i<=r;i++){ occ[a[i]-'a']++; bool yes=1; for(int j=0;j<26;++j)yes&=(occ[j]%2==0); if(yes&&a[i]==a[l]){ candidate=i; } } if(candidate==-1){ ok=0; return ; } answer[l]='('; answer[candidate]=')'; if(l+1<=candidate-1) solve(l+1,candidate-1); if( candidate+1<=r) solve(candidate+1,r); return; } int main(){ cin>>a; for(int i=0;i<a.size();++i) answer+='#'; solve(0,a.size()-1); if(!ok) cout<<-1; else cout<<answer; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Incorrect | 0 ms | 212 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Incorrect | 0 ms | 212 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |