Submission #77206

#TimeUsernameProblemLanguageResultExecution timeMemory
77206EntityITPalindrome-Free Numbers (BOI13_numbers)C++14
100 / 100
3 ms700 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int a, b, arr[19], dp[19][10][10][2][2]; int calc (int pos, int las1, int las2, bool smaller, bool nonZero) { if ( (nonZero || las1) && las1 == las2) return 0; if (pos == 1) { if (smaller || las1 < arr[pos] || (las1 == arr[pos] && las2 <= arr[pos - 1]) ) return 1; } int &ret = dp[pos][las1][las2][smaller][nonZero]; if (ret != -1) return ret; ret = 0; if (smaller || las1 < arr[pos] || (las1 == arr[pos] && las2 <= arr[pos - 1]) ) { for (int las3 = 0; las3 < 10; ++las3) { if ( (nonZero || las1) && las1 == las3) continue ; ret += calc(pos - 1, las2, las3, max(smaller, (las1 < arr[pos]) ), max(nonZero, (las1 > 0) ) ); } } return ret; } int solve (int lim) { memset(dp, -1, sizeof dp); if (lim < 0) return 0; int cur = 0; memset(arr, 0, sizeof arr); while (lim) { arr[cur++] = lim % 10; lim /= 10; } int ret = 0; for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { ret += calc(18, i, j, 0, 0); } } return ret; } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b; cout << solve(b) - solve(a - 1); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...