Submission #1108348

#TimeUsernameProblemLanguageResultExecution timeMemory
1108348Kirill22Palindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
3 ms592 KiB
#include "bits/stdc++.h" using namespace std; long long get(long long r) { if (r <= 0) { return 0; } map<array<int, 3>, long long> dp; string s = to_string(r); for (int i = 0; i < (int) s.size(); i++) { auto dp2 = dp; dp.clear(); for (int j = 0; j < 10; j++) { if (i == 0) { if (j && j < s[i] - '0') { dp[{0, -1, j}]++; } if (j == s[i] - '0') { dp[{1, -1, j}]++; } } else { if (j) { dp[{0, -1, j}]++; } } for (auto [_, cnt] : dp2) { auto [t, x, y] = _; if (x == j || y == j) { continue; } if (t == 1 && j > s[i] - '0') { continue; } int nt = t; if (j < s[i] - '0') { nt = 0; } dp[{nt, y, j}] += cnt; } } } long long ans = 0; for (auto [_, cnt] : dp) { ans += cnt; } return ans; } void solve() { long long l, r; cin >> l >> r; cout << get(r) - get(l - 1) + int(l <= 0 && 0 <= r) << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...