結果
| 問題 |
No.3381 Palindrome Substrings (C++)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-22 13:13:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 926 bytes |
| コンパイル時間 | 1,823 ms |
| コンパイル使用メモリ | 203,980 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-22 13:13:21 |
| 合計ジャッジ時間 | 4,196 ms |
|
ジャッジサーバーID (参考情報) |
judge7 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
string s;
vector<vector<int>> dp;
bool rec(int i,int j){
if(i>=j){
return true;
}
if(dp[i][j]!=-1){
return dp[i][j];
}
if(s[i]!=s[j]){
return dp[i][j]=false;
}else{
return dp[i][j]=rec(i+1,j-1);
}
}
int main()
{
int n;
cin>>n;
cin>>s;
int ans=0;
dp.resize(n,vector<int>(n,-1));
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
ans+=rec(i,j);
}
}
cout<<ans<<endl;
return 0;
}