Submission #21996

#TimeUsernameProblemLanguageResultExecution timeMemory
21996gs14004Make superpalindrome! (kriii1_M)C++11
1 / 1
6 ms3048 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<int, int> pi; const int mod = 1e9 + 7; string rv(string s){ reverse(s.begin(), s.end()); return s; } bool is_super(string s){ if(s.size() <= 1) return 1; string w = s.substr(0, s.size() / 2); return is_super(w) && (w + s.substr(s.size() / 2, s.size() % 2) + rv(w)) == s; } string solve(string s){ if(s.size() == 1){ s[0]++; return s; } string t = s.substr(0, s.size() / 2); string ans = t + s.substr(s.size() / 2, s.size() % 2) + rv(t); if(is_super(t) && ans > s) return ans; if(is_super(t) && s.size() % 2 == 1 && s[s.size()/2] < 'z'){ ans[s.size()/2]++; return ans; } t = solve(t); if(s.size() % 2 == 0) return t + rv(t); else return t + "a" + rv(t); } int main(){ string s; cin >> s; cout << solve(s); }
#Verdict Execution timeMemoryGrader output
Fetching results...