# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
342340 | jeroenodb | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 1 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <bitset>
#include <cassert>
#include <algorithm>
#include <cstring>
using namespace std;
#define all(x) begin(x),end(x)
typedef long long ll;
const int mxN = 1e5+1;
ll dp[18][11][11][2];
vector<int> dig;
ll recur(int i=0, int p=10, int pp=10, bool free=false) {
if(i==dig.size()) return 1;
if(dp[i][p][pp][free]) {
return dp[i][p][pp][free]-1;
}
dp[i][p][pp][free]++;
int limit = free?9:dig[i];
for(int d=0;d<=limit;++d) {
if(d==p or d==pp) continue;
int tmp = d;
if(p==10 and d==0) {
tmp=10;
}
dp[i][p][pp][free]+=recur(i+1,tmp,p,free or d!=dig[i]);
}
return dp[i][p][pp][free]-1;
}
ll solve(ll a) {
if(a==-1) return 0;
memset(&dp[0][0][0][0], 0,sizeof(dp));
dig.clear();
while(a!=0) {
dig.push_back(a%10);
a/=10;
}
reverse(all(dig));
return recur();
}
int main() {
ll a,b; cin >> a >> b;
cout << solve(b) - solve(a-1) << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |