답안 #42445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42445 2018-02-27T08:19:27 Z nonocut 조교 (CEOI16_popeala) C++14
0 / 100
2 ms 624 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 20 + 5;
struct node {
    int cnt[26];
    node() {
        for(int i=0;i<26;i++) cnt[i] = 0;
    }
    bool operator < (node a) const {
        for(int i=0;i<26;i++) {
            if(a.cnt[i]!=cnt[i]) return a.cnt[i]<cnt[i];
        }
        return 0;
    }
};
int n;
char s[maxn], ans[maxn];
int a[maxn];
node val[maxn];
map<node, set<int>> pos[26];
void solve(int l, int r) {
    if(l>r) return ;
    int x = *(--pos[s[l]-'a'][val[l-1]].upper_bound(r));
//    printf("solve %d %d => x = %d\n",l,r,x);
    ans[l] = '('; ans[x] = ')';
    solve(l+1,x-1); solve(x+1,r);
}
int main() {
	scanf(" %s",s);
	n = strlen(s);
	int r = 0;
	for(int i=0;i<n;i++) {
        val[i] = val[i-1];
        a[++r] = s[i]-'a';
        val[i].cnt[s[i]-'a']++;
        while(r>=2 && a[r]==a[r-1]) {
            val[i].cnt[a[r]]-=2;
            r-=2;
        }
        pos[s[i]-'a'][val[i]].insert(i);
//        printf("i = %d (%c) : val = ",i,s[i]);
//        for(int j=0;j<5;j++) printf("%d",val[i].cnt[j]);
//        printf("\n");
	}
	if(r>0) return !printf("-1");
    solve(0,n-1);
    printf("%s",ans);
}

Compilation message

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