Submission #1120812

#TimeUsernameProblemLanguageResultExecution timeMemory
1120812vjudge1Palindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
2 ms592 KiB
/** ██╗░░██╗████████╗██╗░░░░░███╗░░░███╗ ██║░░██║╚══██╔══╝██║░░░░░████╗░████║ ███████║░░░██║░░░██║░░░░░██╔████╔██║ ██╔══██║░░░██║░░░██║░░░░░██║╚██╔╝██║ ██║░░██║░░░██║░░░███████╗██║░╚═╝░██║ ╚═╝░░╚═╝░░░╚═╝░░░╚══════╝╚═╝░░░░░╚═╝ **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; int32_t main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll L, R; cin >> L >> R; auto get = [&](ll eded) -> ll { if (eded == -1LL) return 0; string x = to_string(eded); if (x.size() == 1) { return x[0] - '0' + 1LL; } reverse (x.begin(), x.end()); const int MAXN = x.size(); const int MAXM = 10; vector<vector<vector<array<ll, 2>>>> dp(MAXN + 1, vector<vector<array<ll, 2>>> (MAXM, vector<array<ll, 2>>(MAXM, {0, 0}))); for (int a = 0;a < MAXM;a ++) { for (int b = 0;b < MAXM;b ++) { if (a != b) { dp[2][a][b][0] = 1; if (x[1] - '0' >= a || (x[1] - '0' == a && x[0] - '0' >= b)) { dp[2][a][b][1] = 1; } } } } for (int i = 3;i <= MAXN;i ++) { for (int a = 0;a < MAXM;a ++) { for (int b = 0;b < MAXM;b ++) if (a != b) { for (int c = 0;c < MAXM;c ++) if (a != c && b != c) { if (a < x[i - 1] - '0' || (a == x[i - 1] - '0' && b < x[i - 2] - '0') || (a == x[i - 1] - '0' && b == x[i - 2] - '0' && c < x[i - 3] - '0')) { dp[i][a][b][0] += dp[i - 1][b][c][0]; dp[i][a][b][1] += dp[i - 1][b][c][0]; } else if ((a == x[i - 1] - '0' && b == x[i - 2] - '0' && c == x[i - 3] - '0')) { dp[i][a][b][0] += dp[i - 1][b][c][0]; dp[i][a][b][1] += dp[i - 1][b][c][1]; } else { dp[i][a][b][0] += dp[i - 1][b][c][0]; } } } } } ll ans = 10; for (int i = 2;i <= MAXN;i ++) { for (int a = 1;a < MAXM;a ++) { for (int b = 0;b < MAXM;b ++) if (a != b) { if (i < MAXN || (a < x[i - 1] - '0' || (a == x[i - 1] - '0' && b < x[i - 2] - '0'))) { ans += dp[i][a][b][0]; } else if ((a == x[i - 1] - '0' && b == x[i - 2] - '0')) { ans += dp[i][a][b][1]; } } } } return ans; }; cout << get (R) - get (L - 1) << "\n"; // cout << get (R) << " " << get(L - 1) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...