Submission #96931

# Submission time Handle Problem Language Result Execution time Memory
96931 2019-02-12T19:12:31 Z Kastanda Match (CEOI16_match) C++11
100 / 100
19 ms 11888 KB
// I do it for the glory
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, SGM = 26;
int n, C[N][SGM];
char A[N], B[N];
void Solve(int l, int r)
{
    if (r <= l)
        return ;
    int opt = C[r - 1][A[l] - 'a'];
    if (opt <= l)
        {printf("-1\n"); exit(0);}
    B[l] = '('; B[opt] = ')';
    Solve(l + 1, opt);
    Solve(opt + 1, r);
}
int main()
{
    scanf("%s", A);
    n = strlen(A);
    memset(C, -1, sizeof(C));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < SGM; j++)
        {
            if (A[i] - 'a' == j)
                C[i][j] = i;
            else if (i > 0 && C[i - 1][A[i] - 'a'] > 0)
                C[i][j] = C[C[i - 1][A[i] - 'a'] - 1][j];
        }
    Solve(0, n);
    return !printf("%s\n", B);
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", A);
     ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10496 KB Output is correct
2 Correct 10 ms 10624 KB Output is correct
3 Correct 12 ms 10496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10496 KB Output is correct
2 Correct 10 ms 10624 KB Output is correct
3 Correct 12 ms 10496 KB Output is correct
4 Correct 11 ms 10496 KB Output is correct
5 Correct 11 ms 10524 KB Output is correct
6 Correct 11 ms 10496 KB Output is correct
7 Correct 11 ms 10496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10496 KB Output is correct
2 Correct 10 ms 10624 KB Output is correct
3 Correct 12 ms 10496 KB Output is correct
4 Correct 11 ms 10496 KB Output is correct
5 Correct 11 ms 10524 KB Output is correct
6 Correct 11 ms 10496 KB Output is correct
7 Correct 11 ms 10496 KB Output is correct
8 Correct 10 ms 10624 KB Output is correct
9 Correct 10 ms 10624 KB Output is correct
10 Correct 11 ms 10624 KB Output is correct
11 Correct 10 ms 10624 KB Output is correct
12 Correct 16 ms 11264 KB Output is correct
13 Correct 14 ms 11264 KB Output is correct
14 Correct 16 ms 11520 KB Output is correct
15 Correct 14 ms 11816 KB Output is correct
16 Correct 16 ms 11888 KB Output is correct
17 Correct 16 ms 11876 KB Output is correct
18 Correct 16 ms 11264 KB Output is correct
19 Correct 16 ms 11520 KB Output is correct
20 Correct 14 ms 11392 KB Output is correct
21 Correct 19 ms 11640 KB Output is correct