Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
using namespace std; bool is_palindrome(int x) { string s = ""; while(x > 0) { int digit = x % 10; s += (digit + '0'); x /= 10; } int i = 0, j = s.size() - 1; while(i < j) { if(s[i] != s[j]) { return false; } i++; j--; } return true; } int main() { vector
palindromes; for(int i = 1; i <= 100000; i++) { if(is_palindrome(i)) { palindromes.push_back(i); } } int S, E; cin >> S >> E; vector
visited(100000, false); visited[S] = true; queue
q; q.push(S); q.push(0); while(!q.empty()) { int number = q.front(); q.pop(); int dist = q.front(); q.pop(); if(number == E) { cout << dist << endl; return 0; } for(int i = 0; i < palindromes.size(); i++) { int palindrome = palindromes[i]; if(palindrome < number and palindrome + number <= E) { if(!visited[palindrome + number]) { visited[palindrome + number] = true; q.push(palindrome + number); q.push(dist + 1); } } } } return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)