結果

問題 No.588 空白と回文
ユーザー snrnsidy
提出日時 2025-09-11 23:33:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,062 bytes
コンパイル時間 5,149 ms
コンパイル使用メモリ 212,220 KB
実行使用メモリ 7,492 KB
最終ジャッジ日時 2025-09-11 23:33:35
合計ジャッジ時間 6,866 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int dp[1001][1001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
    int res = 0;

    cin >> s;

    int n = s.length();

    memset(dp,-1,sizeof(dp));

    for(int i=0;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            if(s[i]==s[j])
            {
                if(i==j) dp[i][j] = 1;
                else dp[i][j] = 2;
            }
        }
    }

    for(int len=1;len<=n;len++)
    {
        for(int l=0;l<n;l++)
        {
            int r = l + len - 1;
            if(r >= n) break;
            if(dp[l][r]==-1) continue;
            if(l-1>=0 && r+1<n)
            {
                if(s[l-1]==s[r+1])
                {
                    dp[l-1][r+1] = max(dp[l-1][r+1],dp[l][r] + 2);
                }
                dp[l-1][r+1] = max(dp[l-1][r+1],dp[l][r]);
            }
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            res = max(res,dp[i][j]);
        }
    }

    cout << res << '\n';

	return 0;
} 
0