답안 #154367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154367 2019-09-21T09:57:59 Z arnold518 괄호 문자열 (CEOI16_match) C++14
37 / 100
2000 ms 636 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int N;
char A[MAXN+10];
char ans[MAXN+10];

int main()
{
    int i, j;

    scanf("%s", A+1); N=strlen(A+1);

    vector<char> S;
    for(i=1; i<=N; i++)
    {
        if(!S.empty() && A[i]==S.back()) S.pop_back();
        else S.push_back(A[i]);
    }
    if(!S.empty()) return !printf("-1");

    for(i=1; i<=N; i++)
    {
        ans[i]='(';
        vector<char> V;
        for(j=1; j<=i; j++)
        {
            if(ans[j]=='(') V.push_back(A[j]);
            else V.pop_back();
        }

        for(j=i+1; j<=N; j++)
        {
            if(!V.empty() && A[j]==V.back()) V.pop_back();
            else V.push_back(A[j]);
        }
        if(!V.empty()) ans[i]=')';
    }
    printf("%s", ans+1);
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", A+1); N=strlen(A+1);
     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 9 ms 376 KB Output is correct
7 Correct 16 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 9 ms 376 KB Output is correct
7 Correct 16 ms 380 KB Output is correct
8 Correct 214 ms 380 KB Output is correct
9 Correct 231 ms 380 KB Output is correct
10 Correct 160 ms 348 KB Output is correct
11 Correct 152 ms 400 KB Output is correct
12 Execution timed out 2044 ms 636 KB Time limit exceeded
13 Halted 0 ms 0 KB -