답안 #982631

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982631 2024-05-14T14:22:16 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
35 / 100
10000 ms 608 KB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define int long long
#define ff first
#define ss second
using namespace std;

void solve()
{
    
    string s;
    cin >> s;
    int n = s.length();
    vector<int> dp(n/2+2,0);
    int back = n-1;
    for (int i = 0; i < n/2+1; i++)
    {
        if (i >= back)
            break;
        for(int j = 0; j <= i; j++)
        {
            //cout << s.substr(j,i-j+1) << ' ' << s.substr(back,i-j+1) << " i: " << i << " j: " << j << '\n';
            if (s.substr(j,i-j+1) == s.substr(back,i-j+1))
            {
                if (j==0)
                    dp[i] = max(dp[i],2ll);
                else if (dp[j-1] > 0)
                    dp[i] = max(dp[i],dp[j-1]+2);
            }
        }
        back--;
    }
    int ans = 1;
    if (n%2)
    {
        for (int i = 0; i < n/2+1; i++)
        {
            ans = max(ans,dp[i]+1);   
        }
    }
    else
    {
        for (int i = 0; i < n/2-1; i++)
        {
            ans = max(ans,dp[i]+1);
        }
        ans = max(ans,dp[n/2-1]);
    }
    cout << ans << '\n';
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    
    while(t--)
    {
       solve();
    }
    
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Execution timed out 10096 ms 608 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Execution timed out 10096 ms 608 KB Time limit exceeded
11 Halted 0 ms 0 KB -