답안 #42438

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42438 2018-02-27T07:35:31 Z nonocut 괄호 문자열 (CEOI16_match) C++14
0 / 100
6 ms 6112 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
int n;
char s[maxn], a[maxn], ans[maxn];
set<int> pos[30][maxn];
void solve(int l, int r, int cur) {
    if(l>r) return ;
    int x = *(--pos[s[l]-'a'][cur].upper_bound(r));
    ans[l] = '('; ans[x] = ')';
    solve(l+1,x-1,cur+1); solve(x+1,r,cur);
}
int main() {
	scanf(" %s",s);
	n = strlen(s);
	int r = 0;
	for(int i=0;i<n;i++) {
        a[++r] = s[i];
        while(r>=2 && a[r]==a[r-1]) r-=2;
        pos[s[i]-'a'][r].insert(i);
	}
	if(r>0) return !printf("-1");
    solve(0,n-1,0);
    printf("%s",ans);
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:14:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s",s);
                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Runtime error 6 ms 6112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Runtime error 6 ms 6112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Runtime error 6 ms 6112 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -