Submission #95921

# Submission time Handle Problem Language Result Execution time Memory
95921 2019-02-04T11:04:03 Z Kastanda Palindromic Partitions (CEOI17_palindromic) C++11
100 / 100
923 ms 129692 KB
#include<bits/stdc++.h>
using namespace std;
const int MXN = 1000006, SGM = 26;
int n, ts, link[MXN], len[MXN];
int slink[MXN], diff[MXN], sdp[MXN], dp[MXN];
map < int , int > C[MXN];
char S[MXN], _S[MXN];
inline int GetLink(int nw, int i)
{
    while (S[i] != S[i - len[nw] - 1])
        nw = link[nw];
    return (nw);
}
inline int Add(int nw, int i)
{
    int ch = S[i] - 'a';
    nw = GetLink(nw, i);
    if (!C[nw][ch])
    {
        ts ++;
        len[ts] = len[nw] + 2;
        link[ts] = C[GetLink(link[nw], i)][ch];
        diff[ts] = len[ts] - len[link[ts]];
        slink[ts] = link[ts];
        if (diff[ts] == diff[link[ts]])
            slink[ts] = slink[link[ts]];
        C[nw][ch] = ts;
        return (ts);
    }
    return (C[nw][ch]);
}
int main()
{
    int q;
    scanf("%d", &q);
    for (; q; q --)
    {
        memset(_S, 0, sizeof(_S));
        scanf("%s", _S);
        n = strlen(_S);
        for (int i = 1; i < n; i += 2)
        {
            S[i - 1] = _S[i >> 1];
            S[i] = _S[n - 1 - (i >> 1)];
        }
        link[0] = link[1] = 1;
        len[1] = -1; ts = 1;
        sdp[0] = sdp[1] = - MXN;
        dp[0] = 0;
        int nw = 1, Mx = 1;
        for (int i = 1; i <= (n >> 1 << 1); i++)
        {
            dp[i] = - MXN;
            nw = Add(nw, i - 1);
            for (int u = nw; len[u] > 0; u = slink[u])
            {
                sdp[u] = dp[i - len[slink[u]] - diff[u]];
                if (diff[u] == diff[link[u]])
                    sdp[u] = max(sdp[u], sdp[link[u]]);
                if (!(i & 1)) dp[i] = max(dp[i], sdp[u] + 1);
            }
            Mx = max(Mx, dp[i] + dp[i] + (i < n));
        }
        for (int i = 0; i <= ts; i++)
            C[i].clear();
        printf("%d\n", Mx);
    }
    return 0;
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
palindromic.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", _S);
         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 48248 KB Output is correct
2 Correct 38 ms 48248 KB Output is correct
3 Correct 40 ms 48248 KB Output is correct
4 Correct 37 ms 48376 KB Output is correct
5 Correct 38 ms 48376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 48248 KB Output is correct
2 Correct 38 ms 48248 KB Output is correct
3 Correct 40 ms 48248 KB Output is correct
4 Correct 37 ms 48376 KB Output is correct
5 Correct 38 ms 48376 KB Output is correct
6 Correct 39 ms 48376 KB Output is correct
7 Correct 38 ms 48376 KB Output is correct
8 Correct 39 ms 48376 KB Output is correct
9 Correct 38 ms 48376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 48248 KB Output is correct
2 Correct 38 ms 48248 KB Output is correct
3 Correct 40 ms 48248 KB Output is correct
4 Correct 37 ms 48376 KB Output is correct
5 Correct 38 ms 48376 KB Output is correct
6 Correct 39 ms 48376 KB Output is correct
7 Correct 38 ms 48376 KB Output is correct
8 Correct 39 ms 48376 KB Output is correct
9 Correct 38 ms 48376 KB Output is correct
10 Correct 45 ms 49144 KB Output is correct
11 Correct 42 ms 49148 KB Output is correct
12 Correct 47 ms 49144 KB Output is correct
13 Correct 45 ms 48892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 48248 KB Output is correct
2 Correct 38 ms 48248 KB Output is correct
3 Correct 40 ms 48248 KB Output is correct
4 Correct 37 ms 48376 KB Output is correct
5 Correct 38 ms 48376 KB Output is correct
6 Correct 39 ms 48376 KB Output is correct
7 Correct 38 ms 48376 KB Output is correct
8 Correct 39 ms 48376 KB Output is correct
9 Correct 38 ms 48376 KB Output is correct
10 Correct 45 ms 49144 KB Output is correct
11 Correct 42 ms 49148 KB Output is correct
12 Correct 47 ms 49144 KB Output is correct
13 Correct 45 ms 48892 KB Output is correct
14 Correct 758 ms 129692 KB Output is correct
15 Correct 711 ms 125032 KB Output is correct
16 Correct 923 ms 128984 KB Output is correct
17 Correct 694 ms 85228 KB Output is correct