답안 #44681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44681 2018-04-04T19:40:30 Z bogdan10bos Palindromic Partitions (CEOI17_palindromic) C++14
60 / 100
10000 ms 18204 KB
#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef pair<char, char> pcc;
typedef long long LL;

const int base = 31;

int N;
int dp[1000005];
char s[1000005];
LL pw[1000005], hsh[1000005];
map< pcc, vector<int> > mp;

int get_hash(int st, int dr)
{
    return hsh[dr] - hsh[st - 1] * pw[dr - st + 1];
}

void solve_test()
{
    scanf("%s", s + 1);
    N = strlen(s + 1);
    for(int i = 1; i <= N; i++)
        hsh[i] = (1LL * hsh[i - 1] * base) + s[i] - 'a' + 1;
    mp.clear();
    int ans = 1;
    for(int st = 1, dr = N; st < dr; st++, dr--)
    {
        dp[st] = 0;
        for(auto pos: mp[{s[dr], s[st]}])
        {
            int lgt = st - pos + 1;
            if(dp[pos - 1] > 0 && get_hash(pos, st) == get_hash(dr, dr + lgt - 1))
                dp[st] = max(dp[st], dp[pos - 1] + 2);
        }
        if(get_hash(1, st) == get_hash(dr, N))
            dp[st] = max(dp[st], 2);
        if(s[st] == s[dr] && dp[st - 1])
            dp[st] = max(dp[st], dp[st - 1] + 2);
        ans = max(ans, dp[st] + (st + 1 < dr ? 1 : 0));
        if(dp[st - 1] != 0) mp[{s[st], s[dr]}].push_back(st);
    }

    printf("%d\n", ans);
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    pw[0] = 1;
    int N = 1e6;
    for(int i = 1; i <= N; i++)
        pw[i] = 1LL * pw[i - 1] * base;

    int T;
    scanf("%d\n", &T);
    for(int t = 1; t <= T; t++)
        solve_test();

    return 0;
}

Compilation message

palindromic.cpp: In function 'void solve_test()':
palindromic.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", s + 1);
     ~~~~~^~~~~~~~~~~~~
palindromic.cpp: In function 'int main()':
palindromic.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d\n", &T);
     ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8232 KB Output is correct
3 Correct 7 ms 8236 KB Output is correct
4 Correct 8 ms 8236 KB Output is correct
5 Correct 8 ms 8296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8232 KB Output is correct
3 Correct 7 ms 8236 KB Output is correct
4 Correct 8 ms 8236 KB Output is correct
5 Correct 8 ms 8296 KB Output is correct
6 Correct 8 ms 8312 KB Output is correct
7 Correct 8 ms 8344 KB Output is correct
8 Correct 7 ms 8344 KB Output is correct
9 Correct 7 ms 8344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8232 KB Output is correct
3 Correct 7 ms 8236 KB Output is correct
4 Correct 8 ms 8236 KB Output is correct
5 Correct 8 ms 8296 KB Output is correct
6 Correct 8 ms 8312 KB Output is correct
7 Correct 8 ms 8344 KB Output is correct
8 Correct 7 ms 8344 KB Output is correct
9 Correct 7 ms 8344 KB Output is correct
10 Correct 151 ms 8600 KB Output is correct
11 Correct 22 ms 8600 KB Output is correct
12 Correct 11 ms 8600 KB Output is correct
13 Correct 99 ms 8600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8184 KB Output is correct
2 Correct 8 ms 8232 KB Output is correct
3 Correct 7 ms 8236 KB Output is correct
4 Correct 8 ms 8236 KB Output is correct
5 Correct 8 ms 8296 KB Output is correct
6 Correct 8 ms 8312 KB Output is correct
7 Correct 8 ms 8344 KB Output is correct
8 Correct 7 ms 8344 KB Output is correct
9 Correct 7 ms 8344 KB Output is correct
10 Correct 151 ms 8600 KB Output is correct
11 Correct 22 ms 8600 KB Output is correct
12 Correct 11 ms 8600 KB Output is correct
13 Correct 99 ms 8600 KB Output is correct
14 Execution timed out 10069 ms 18204 KB Time limit exceeded
15 Halted 0 ms 0 KB -