Submission #579881

#TimeUsernameProblemLanguageResultExecution timeMemory
579881RealSnakePalindrome-Free Numbers (BOI13_numbers)C++14
72.50 / 100
1 ms340 KiB
#include "bits/stdc++.h" using namespace std; #define ll long long #define mod 1000000007 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll n; string s; ll dp[20][2][11][11]; ll solve(ll ind, bool b, ll lst1, ll lst2) { if(ind + 1 == n) return 1; if(dp[ind + 1][b][lst1][lst2]) return dp[ind + 1][b][lst1][lst2]; ll ans = 0; if(b == 1) { ll d = (s[ind + 1] - '0'); for(ll i = 0; i <= d; i++) { if(i == lst1 || i == lst2) continue; ans += solve(ind + 1, (i == d), i, lst1); } } else { for(ll i = 0; i <= 9; i++) { if(i == lst1 || i == lst2) continue; ans += solve(ind + 1, 0, i, lst1); } } return dp[ind + 1][b][lst1][lst2] = ans; } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string b; ll a; cin >> a >> b; s = b; n = s.size(); ll ans = solve(-1, 1, 10, 10); a--; if(a >= 0) { memset(dp, 0, sizeof dp); s = to_string(a); n = s.size(); ans -= solve(-1, 1, 10, 10); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...