답안 #51019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51019 2018-06-15T15:42:36 Z SpaimaCarpatilor 괄호 문자열 (CEOI16_match) C++17
0 / 100
2 ms 484 KB
#include<bits/stdc++.h>

using namespace std;

int N, t[100009], nxt[100009][26], lst[100009][26];
char sir[100009], ans[100009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%s", sir + 1), N = strlen (sir + 1);
for (int i=1; i<=N; i++)
    sir[i] -= 'a';
for (int i=N; i>=1; i--)
{
    t[i] = nxt[i + 1][sir[i]];
    nxt[i][sir[i]] = i;
    if (t[i] != 0)
    {
        for (int c=0; c<26; c++)
            if (c != sir[i])
                nxt[i][c] = nxt[t[i] + 1][c];
    }
}
if (t[1] == 0)
{
    printf ("-1\n");
    return 0;
}
for (int i=N; i>=1; i--)
    for (int j=0; j<26; j++)
        if (nxt[i][j] != 0)
        {
            int k = nxt[i + 1][j];
            if (lst[k + 1][j] != 0) lst[i][j] = lst[k + 1][j];
            else lst[i][j] = k;
        }
for (int i=1; i<=N; i++)
    if (ans[i] == 0)
    {
        int j = lst[i][sir[i]];
        ans[i] = '(', ans[j] = ')';
        /*for (int k=1; k<=N; k++)
            if (ans[k] == 0) printf (".");
            else printf ("%c", ans[k]);
        printf ("\n");*/
    }
printf ("%s\n", ans + 1);
return 0;
}

Compilation message

match.cpp: In function 'int main()':
match.cpp:18:29: warning: array subscript has type 'char' [-Wchar-subscripts]
     t[i] = nxt[i + 1][sir[i]];
                             ^
match.cpp:19:18: warning: array subscript has type 'char' [-Wchar-subscripts]
     nxt[i][sir[i]] = i;
                  ^
match.cpp:43:30: warning: array subscript has type 'char' [-Wchar-subscripts]
         int j = lst[i][sir[i]];
                              ^
match.cpp:13:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf ("%s", sir + 1), N = strlen (sir + 1);
 ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 484 KB Output isn't correct
3 Halted 0 ms 0 KB -