Submission #786777

#TimeUsernameProblemLanguageResultExecution timeMemory
786777serifefedartarPalindrome-Free Numbers (BOI13_numbers)C++17
72.50 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); typedef long long ll; #define f first #define s second #define MAXN 100005 #define int long long ll count(string x) { int len = x.length(); vector<vector<vector<int>>> dp(11, vector<vector<int>>(11, vector<int>(2, 0))); dp[10][10][0] = 1; for (int i = 0; i < len; i++) { vector<vector<vector<int>>> new_dp(11, vector<vector<int>>(11, vector<int>(2, 0))); for (auto smaller : {false, true}) { for (int second_last = 0; second_last <= 10; second_last++) { for (int last_digit = 0; last_digit <= 10; last_digit++) { for (int digit = 0; digit < 10; digit++) { if (!smaller && digit > x[i]-'0') break; if (digit == last_digit || digit == second_last) continue; new_dp[digit][last_digit][smaller || digit < x[i]-'0'] += dp[last_digit][second_last][smaller]; } } } } dp = new_dp; } ll ans = 0; for (int second_last = 0; second_last < 10; second_last++) for (int last_digit = 0; last_digit < 10; last_digit++) ans += dp[last_digit][second_last][0] + dp[last_digit][second_last][1]; return ans; } signed main() { fast ll a, b; cin >> a >> b; string strA = to_string(a-1), strB = to_string(b); ll ans = count(strB) - count(strA); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...