Submission #338877

#TimeUsernameProblemLanguageResultExecution timeMemory
338877limabeansPalindrome-Free Numbers (BOI13_numbers)C++17
72.50 / 100
2 ms492 KiB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;










ll dp[20][2][11][11][2];

void reset() {
    memset(dp,-1,sizeof(dp));
}



ll solve(string s, int i, bool lower, int l0, int l1, bool started) {
    int n = s.length();
    if (i == n) {
	return started;
    } else {
	ll &res = dp[i][lower][l0][l1][started];
	if (~res) return res;
	res = 0;
	
	for (int d=0; d<=(lower?9:int(s[i]-'0')); d++) {
	    if (d==l0) continue;
	    if (d==l1) continue;
	    res += solve(s,i+1,lower||(d<int(s[i]-'0')), l1, d, started || (d>0));
	}

	return res;
    }
}



int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);


    ll a,b;
    cin>>a>>b;
    // [a,b]

    --a;


    reset();
    ll res = solve(to_string(b),0,false,10,10,false);
    reset();
    res -= solve(to_string(a),0,false,10,10,false);

    out(res);    
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...