답안 #42446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42446 2018-02-27T08:23:15 Z nonocut 조교 (CEOI16_popeala) C++14
0 / 100
2 ms 1020 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 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[30];
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-1] = '('; ans[x-1] = ')';
    solve(l+1,x-1); solve(x+1,r);
}
int main() {
	scanf(" %s",s);
	n = strlen(s);
	for(int i=n;i>=1;i--) s[i] = s[i-1];
	int r = 0;
	for(int i=1;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(1,n);
    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 888 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 1008 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 1020 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 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -