답안 #223628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223628 2020-04-15T20:41:45 Z MKopchev 괄호 문자열 (CEOI16_match) C++14
10 / 100
19 ms 20992 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=1e5+42;

int n;
string inp;

char output[nmax];

int prev_pos[nmax][26];

void solve(int l,int r)
{
    if(l>r)return;

    int mid=prev_pos[r][inp[l]-'a'];

    if(l>=mid)
    {
        cout<<-1<<endl;
        exit(0);
    }

    output[l]='(';
    output[mid]=')';

    solve(l+1,mid-1);

    solve(mid+1,r);
}
int main()
{
    cin>>inp;
    n=inp.size();

    memset(prev_pos,-1,sizeof(prev_pos));

    for(int i=0;i<n;i++)
        for(int j=0;j<26;j++)
    {
        if(inp[i]==j+'a')prev_pos[i][j]=i;
        else if(prev_pos[i-1][j]!=-1)prev_pos[i][j]=prev_pos[prev_pos[i-1][inp[i]-'a']-1][j];
    }

    solve(0,n-1);

    for(int i=0;i<n;i++)
        cout<<output[i];

    cout<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10496 KB Output is correct
2 Correct 9 ms 10496 KB Output is correct
3 Correct 9 ms 10496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10496 KB Output is correct
2 Correct 9 ms 10496 KB Output is correct
3 Correct 9 ms 10496 KB Output is correct
4 Runtime error 19 ms 20992 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10496 KB Output is correct
2 Correct 9 ms 10496 KB Output is correct
3 Correct 9 ms 10496 KB Output is correct
4 Runtime error 19 ms 20992 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -