Task: | Longest palindrome |
Sender: | aalto2024j_007 |
Submission time: | 2024-11-06 16:26:54 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | RUNTIME ERROR | 0.42 s | details |
#4 | RUNTIME ERROR | 0.42 s | details |
#5 | RUNTIME ERROR | 0.42 s | details |
#6 | RUNTIME ERROR | 0.42 s | details |
#7 | RUNTIME ERROR | 0.42 s | details |
#8 | RUNTIME ERROR | 0.42 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | RUNTIME ERROR | 0.40 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | RUNTIME ERROR | 0.41 s | details |
Code
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; string longestPalindrome(string &s) { int n = s.size(); vector<vector<bool>> dp(n, vector<bool>(n, false)); int maxLen = 1; for (int i = 0; i < n; ++i) dp[i][i] = true; int start = 0; for (int i = 0; i < n - 1; ++i) { if (s[i] == s[i + 1]) { dp[i][i + 1] = true; start = i; maxLen = 2; } } for (int k = 3; k <= n; ++k) { for (int i = 0; i < n - k + 1; ++i) { int j = i + k - 1; if (dp[i + 1][j - 1] && s[i] == s[j]) { dp[i][j] = true; if (k > maxLen) { start = i; maxLen = k; } } } } return s.substr(start, maxLen); } int main() { string s; cin >> s; cout << longestPalindrome(s) << endl; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
aaaaaaaaaa |
correct output |
---|
aaaaaaaaaa |
user output |
---|
aaaaaaaaaa |
Test 2
Verdict: ACCEPTED
input |
---|
ababababab |
correct output |
---|
ababababa |
user output |
---|
ababababa |
Test 3
Verdict: RUNTIME ERROR
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
(empty) |
Test 4
Verdict: RUNTIME ERROR
input |
---|
ababababababababababababababab... |
correct output |
---|
ababababababababababababababab... |
user output |
---|
(empty) |
Test 5
Verdict: RUNTIME ERROR
input |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
correct output |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
user output |
---|
(empty) |
Test 6
Verdict: RUNTIME ERROR
input |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
correct output |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
user output |
---|
(empty) |
Test 7
Verdict: RUNTIME ERROR
input |
---|
abaabaaaaaaabaababbbbbbabaaabb... |
correct output |
---|
babbbabbbaabbbbaabbbbbbbbaabbb... |
user output |
---|
(empty) |
Test 8
Verdict: RUNTIME ERROR
input |
---|
txolestmgyepwrpofxyesjtsfkhjac... |
correct output |
---|
yxnbaabnxy |
user output |
---|
(empty) |
Test 9
Verdict: ACCEPTED
input |
---|
ihpohpzoffel |
correct output |
---|
ff |
user output |
---|
ff |
Test 10
Verdict: ACCEPTED
input |
---|
flexflexvpqxierullgcfckjqflexf... |
correct output |
---|
cfc |
user output |
---|
cfc |
Test 11
Verdict: RUNTIME ERROR
input |
---|
aabbabaabbaababbabaababbaabbab... |
correct output |
---|
abaababbaabbabaababbabaabbaaba... |
user output |
---|
(empty) |
Test 12
Verdict: ACCEPTED
input |
---|
obsession |
correct output |
---|
ses |
user output |
---|
ses |
Test 13
Verdict: ACCEPTED
input |
---|
abcxcbaxcba |
correct output |
---|
abcxcba |
user output |
---|
abcxcba |
Test 14
Verdict: ACCEPTED
input |
---|
zzabc |
correct output |
---|
zz |
user output |
---|
zz |
Test 15
Verdict: ACCEPTED
input |
---|
aaccaabbaaccaaccaabbaaccaa |
correct output |
---|
aaccaabbaaccaaccaabbaaccaa |
user output |
---|
aaccaabbaaccaaccaabbaaccaa |
Test 16
Verdict: RUNTIME ERROR
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
(empty) |