You are not logged in. Please login at www.codechef.com to post your questions!

×

Palin Problems

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 <iostream>
    #include <string>
    #include <algorithm>
    #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<T;x++){
            cin >> a;
            cout << nextPal(a)<<endl;
        }

        return 0;

    }

asked 28 Jul '17, 04:02

jaycram's gravatar image

3★jaycram
1
accept rate: 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 :)

link

answered 28 Jul '17, 04:47

liaojh's gravatar image

5★liaojh
1825
accept rate: 7%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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,698
×1,901
×53

question asked: 28 Jul '17, 04:02

question was seen: 273 times

last updated: 28 Jul '17, 04:47