Submission #60308

#TimeUsernameProblemLanguageResultExecution timeMemory
60308IvanCPalindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
5 ms992 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXL = 25; const int MAXD = 12; ll dp[MAXL][MAXD][MAXD][2][2]; vector<int> digitos; int N; ll A,B; ll solve(int pos,int l1,int l2,int flag,int leading){ ll &ret = dp[pos][l1][l2][flag][leading]; if(ret != -1) return ret; ret = 0; if(pos == N){ ret = 1; return ret; } int limite = 9; if(flag) limite = digitos[pos]; for(int i = 0;i<=limite;i++){ if(leading == 1 && i == 0){ ret += solve(pos+1,l1,l2,flag && (i == limite),leading); } else{ if(l1 != i && l2 != i) ret += solve(pos+1,i,l1,flag && (i == limite), 0); } } return ret; } ll calcula(ll X){ if(X == -1) return 0; if(X == 0) return 1; digitos.clear(); memset(dp,-1,sizeof(dp)); while(X != 0){ digitos.push_back(X % 10); X /= 10; } reverse(digitos.begin(),digitos.end()); N = digitos.size(); return solve(0,10,10,1,1); } int main(){ cin >> A >> B; cout << calcula(B) - calcula(A-1) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...