×

# Palin Problems

 0 This problem is killing me: My solution is very straight forward and doesnt seem to exceed time limit: it simply goes through every number bigger than K and checks if its a palindrome, but I keep on getting wrong answers. Every test case ive thrown at it has worked. Please help. using namespace std; #include #include #include #define lo unsigned long long //queue all data //systematically go through and solve bool palin(lo p) { string a = std::to_string(p); string b = a; reverse(b.begin(),b.end()); if(a == b){ return true; } else{ return false; } } lo nextPal(lo p){ while(true) { p++; if (palin(p)) { return p; } } } int main() { lo T; cin >> T; lo a; for (lo x = 0;x> a; cout << nextPal(a)<

 0 So the problem is asking for the first number bigger than $K$ that is a palindrome. What is the constraint on $K$? For me, your code TLE on where $K \geq 10^{13}$. You can use your brute force and come up with a greedy solution :) answered 28 Jul '17, 04:47 5★liaojh 182●5 accept rate: 7%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,738
×1,918
×54

question asked: 28 Jul '17, 04:02

question was seen: 307 times

last updated: 28 Jul '17, 04:47