# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
176051 | 2020-01-07T18:26:43 Z | rzbt | 괄호 문자열 (CEOI16_match) | C++14 | 2 ms | 380 KB |
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 100005 typedef long long ll; using namespace std; int n; char ss[MAXN],res[MAXN]; int x[MAXN]; set<pair<int,int> > s[30]; stack<int > tmin; int tx; bool obrisan[MAXN]; int main() { scanf("%s",ss); n=strlen(ss); for(int i=1;i<=n;i++){ int t=ss[i-1]-'a'; tx^=(1<<t); x[i]=tx; s[t].insert(mp(tx,-i)); } tmin.push(n+5); for(int i=1;i<=n;i++){ if(obrisan[i])continue; while(i>tmin.top())tmin.pop(); int t=ss[i-1]-'a'; auto a=s[t].lower_bound(mp(x[i-1],-tmin.top())); if(a==s[t].end() || a->F!=x[i-1]){ printf("-1"); return 0; } //printf(" %d %d\n",i,-(a->S)); res[i-1]='('; res[-(a->S)-1]=')'; obrisan[i]=true; obrisan[-(a->S)]=true; tmin.push(-(a->S)); s[t].erase(a); s[t].erase(mp(x[i],i)); } printf("%s",res); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Incorrect | 2 ms | 376 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Incorrect | 2 ms | 376 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |