Task: | Longest palindrome |
Sender: | aalto2024j_002 |
Submission time: | 2024-11-06 16:49:53 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.00 s | details |
#2 | WRONG ANSWER | 0.00 s | details |
#3 | TIME LIMIT EXCEEDED | -- | details |
#4 | TIME LIMIT EXCEEDED | -- | details |
#5 | TIME LIMIT EXCEEDED | -- | details |
#6 | TIME LIMIT EXCEEDED | -- | details |
#7 | TIME LIMIT EXCEEDED | -- | details |
#8 | TIME LIMIT EXCEEDED | -- | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | WRONG ANSWER | 0.00 s | details |
#11 | TIME LIMIT EXCEEDED | -- | details |
#12 | WRONG ANSWER | 0.00 s | details |
#13 | WRONG ANSWER | 0.00 s | details |
#14 | WRONG ANSWER | 0.01 s | details |
#15 | WRONG ANSWER | 0.00 s | details |
#16 | TIME LIMIT EXCEEDED | -- | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 70 | for(int i=0; i< s.size(); i++){ | ~^~~~~~~~~~ input/code.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 88 | for(int i=0; i<sol.size(); i++){ | ~^~~~~~~~~~~ input/code.cpp:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 98 | for(int i=0; i<sol.size(); i++){ | ~^~~~~~~~~~~
Code
#include <iostream> #include <string> #include <vector> using namespace std; pair<int,vector<char>> palind(string s, int i){ vector<char> sol; int n = s.size(); if(i==0){ if(n>=2 and s[0]==s[1]){ return make_pair(2,sol); } return make_pair(1,sol); } if(i==n-1)return make_pair(1,sol); int max1=1; int idx0=1; vector<char> sol1; while((i+idx0)<n and (i-idx0)>=0 and s[(i+idx0)]==s[(i-idx0)]){ sol1.push_back(s[(i+idx0)]); max1 += 2; idx0 += 1; } int max2=1; vector<char> sol2; if(i+1 < n and s[i+1]==s[i]){ max2 = 2; int idx1 = 1; while((i+idx1+1)<n and (i-idx1)>=0 and s[(i+idx1+1)]==s[(i-idx1)]){ sol2.push_back(s[(i+idx1+1)]); max2 += 2; idx1 += 1; } } if(max2 > max1) return make_pair(max2,sol2); return make_pair(max1,sol1); } int main(){ string s; cin >> s; int total = 1; int position = 0; vector<char> sol; for(int i=0; i< s.size(); i++){ //int a = palind(s,i); pair<int,vector<char>> temp = palind(s,i); if(temp.first>total){ total = temp.first; position = i; sol = temp.second; } } cout << total << endl; if(total%2==0){ for(int i=sol.size()-1; i>=0; i--){ cout<<sol[i]; } cout << s[position] << s[position]; for(int i=0; i<sol.size(); i++){ cout << sol[i]; } cout << endl; } else{ for(int i=sol.size()-1; i>=0; i--){ cout<<sol[i]; } cout << s[position]; for(int i=0; i<sol.size(); i++){ cout << sol[i]; } cout << endl; } }
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaa |
correct output |
---|
aaaaaaaaaa |
user output |
---|
10 aaaaaaaaaa |
Test 2
Verdict: WRONG ANSWER
input |
---|
ababababab |
correct output |
---|
ababababa |
user output |
---|
9 ababababa |
Test 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
(empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
input |
---|
ababababababababababababababab... |
correct output |
---|
ababababababababababababababab... |
user output |
---|
(empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
input |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
correct output |
---|
aztdvxzjwxtrludymvpradgbdpgnrq... |
user output |
---|
(empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
correct output |
---|
vvfigwwsyxbukedgcfyibvtbclybud... |
user output |
---|
(empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
input |
---|
abaabaaaaaaabaababbbbbbabaaabb... |
correct output |
---|
babbbabbbaabbbbaabbbbbbbbaabbb... |
user output |
---|
(empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
input |
---|
txolestmgyepwrpofxyesjtsfkhjac... |
correct output |
---|
yxnbaabnxy |
user output |
---|
(empty) |
Test 9
Verdict: WRONG ANSWER
input |
---|
ihpohpzoffel |
correct output |
---|
ff |
user output |
---|
2 ff |
Test 10
Verdict: WRONG ANSWER
input |
---|
flexflexvpqxierullgcfckjqflexf... |
correct output |
---|
cfc |
user output |
---|
3 cfc |
Test 11
Verdict: TIME LIMIT EXCEEDED
input |
---|
aabbabaabbaababbabaababbaabbab... |
correct output |
---|
abaababbaabbabaababbabaabbaaba... |
user output |
---|
(empty) |
Test 12
Verdict: WRONG ANSWER
input |
---|
obsession |
correct output |
---|
ses |
user output |
---|
3 ses |
Test 13
Verdict: WRONG ANSWER
input |
---|
abcxcbaxcba |
correct output |
---|
abcxcba |
user output |
---|
7 abcxcba |
Test 14
Verdict: WRONG ANSWER
input |
---|
zzabc |
correct output |
---|
zz |
user output |
---|
2 zz |
Test 15
Verdict: WRONG ANSWER
input |
---|
aaccaabbaaccaaccaabbaaccaa |
correct output |
---|
aaccaabbaaccaaccaabbaaccaa |
user output |
---|
26 aaccaabbaaccaaccaabbaaccaa |
Test 16
Verdict: TIME LIMIT EXCEEDED
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
user output |
---|
(empty) |