Submission #486786

#TimeUsernameProblemLanguageResultExecution timeMemory
486786NintsiChkhaidzePalindrome-Free Numbers (BOI13_numbers)C++14
56.67 / 100
1096 ms324 KiB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int ll
using namespace std;

int p[25];
signed main (){
    ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL);
    
    p[0] = 1;
    for (int i = 1; i <= 18; i++)
        p[i] = p[i - 1]*10;
        
    int a,b,ans=0;
    cin>>a>>b;

    for (int i = a; i <= b; ){
        int q=1,cnt=0,x=0;
        for (int j = 18; j >= 0; j--){
            if (i < p[j]) continue;
            cnt++;
            int y = (i/p[j])%10;
            x = x*10 + y;
            // if (i== 199)
                // cout<<cnt<<" "<<y<<" "<<p[j]<<" "<<p[j + 1]<<" "<<p[j + 2]<<endl;
                
            if ((cnt > 1 && y == (i/p[j + 1])%10) || (cnt > 2 && y == (i/p[j + 2])%10)){
                // cout<<"num = "<<i<<" "<<cnt<<" "<<j<<endl;
                q=0;
                x++;
                x *= p[j];
                // cout<<"num = "<<i<<" "<<x<<endl;
                // exit(0);
                break;
            }
            
        }
        
        if (q) ans++,i++;
        else i = x;
    }
    cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...