Submission #285444

#TimeUsernameProblemLanguageResultExecution timeMemory
285444a14789654Palindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
3 ms2944 KiB
#include <bits/stdc++.h> using namespace std; long long f[20][2][2][20][10][10][2]; string a, b; int n; long long calc(int pos, bool ok1, bool ok2, int start, int prev, int prevPrev, bool check) { if (pos == n + 1) return !check; if (f[pos][ok1][ok2][start][prev][prevPrev][check] != - 1) return f[pos][ok1][ok2][start][prev][prevPrev][check]; int low = 0, high = 9; if (ok1) low = a[pos] - '0'; if (ok2) high = b[pos] - '0'; long long res = 0; for (int i = low; i <= high; ++i) { bool okI = ok1 && i == a[pos] - '0', okII = ok2 && i == b[pos] - '0'; int first = (!start && i) ? pos : start; bool okIII = check; okIII |= start && i == prev; okIII |= start && pos - start + 1 > 2 && i == prevPrev; res += calc(pos + 1, okI, okII, first, i, prev, okIII); } return f[pos][ok1][ok2][start][prev][prevPrev][check] = res; } int main() { // freopen("test.inp", "r", stdin); // freopen("test.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> a >> b; while (a.size() < b.size()) a = "0" + a; n = a.size(); a = "p" + a, b = "p" + b; memset(f, - 1, sizeof(f)); cout << calc(1, 1, 1, 0, 0, 0, 0); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...