Submission #397369

#TimeUsernameProblemLanguageResultExecution timeMemory
397369Pichon5Palindromic Partitions (CEOI17_palindromic)C++17
0 / 100
2 ms588 KiB
#include <iostream> #include <bits/stdc++.h> #define pb push_back using namespace std; int dp[301][301]; string s; int f(int b, int e){ if(e<b)return 0; if(b==e)return 1; if(dp[b][e]!=-1)return dp[b][e]; dp[b][e]=1; for(int i=1;i<=e-b+1;i++){ if(i+i>e-b+1)break; string A=s.substr(b,i); string B=s.substr(e-i+1,i); if(A==B){ dp[b][e]+=1+f(b+i,e-i); } } return dp[b][e]; } void init(){ for(int i=0;i<=300;i++){ for(int l=0;l<=300;l++)dp[i][l]=-1; } } int main() { int n,t; cin>>t; while(t--){ cin>>s; init(); int n=s.size(); cout<<f(0,n-1)<<endl; } return 0; }

Compilation message (stderr)

palindromic.cpp: In function 'int main()':
palindromic.cpp:29:9: warning: unused variable 'n' [-Wunused-variable]
   29 |     int n,t;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...