Submission #939057

# Submission time Handle Problem Language Result Execution time Memory
939057 2024-03-06T04:47:35 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
35 / 100
866 ms 131072 KB
#include "bits/stdc++.h"
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds; 
 
using namespace std;
 
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
const int INF = 1e18;
void solve(){	
	
	string s;
	cin >> s;
	int n = s.size();
	int dp[n + 1][n + 1];
	for(int i = 0;i < n + 1;i++){
		for(int j = i;j < n + 1;j++){
			dp[i][j] = 1;
		}
		for(int j = 0;j < i;j++){
			dp[i][j] = 0;
		}
	}
	for(int l = n - 1;l >= 0;l--){
		for(int r = l;r <= n - 1;r++){
			string suff = "";
			string pref = "";
			int nl = l,nr = r;
			while(nl < nr){
				pref += s[nl];
				suff = s[nr] + suff;
				
				if(pref == suff){
					dp[l][r] = max(dp[l][r],dp[nl + 1][nr - 1] + 2) ;
				}
				nl++;
				nr--;
			}
			
		}
	}
	cout << dp[0][n - 1] << "\n";
}
//(h[i] - h[j]) * (h[i] - h[j]) + pref[i] - pref[j + 1]
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 866 ms 1140 KB Output is correct
7 Correct 388 ms 1108 KB Output is correct
8 Correct 752 ms 1108 KB Output is correct
9 Correct 538 ms 948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 866 ms 1140 KB Output is correct
7 Correct 388 ms 1108 KB Output is correct
8 Correct 752 ms 1108 KB Output is correct
9 Correct 538 ms 948 KB Output is correct
10 Runtime error 63 ms 131072 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 866 ms 1140 KB Output is correct
7 Correct 388 ms 1108 KB Output is correct
8 Correct 752 ms 1108 KB Output is correct
9 Correct 538 ms 948 KB Output is correct
10 Runtime error 63 ms 131072 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -