# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
35792 | funcsr | Palindrome-Free Numbers (BOI13_numbers) | C++14 | 0 ms | 2268 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
long long A, B;
long long dp[20][10][10][3][2];
long long solve(string X) {
rep(i, X.size()+1) rep(j, 10) rep(k, 10) rep(l, 3) rep(r, 2) dp[i][j][k][l][r] = 0;
dp[0][0][0][0][0] = 1;
rep(i, X.size()) {
int ud = X[i]-'0';
rep(j, 10) {
rep(k, 10) {
rep(s, 3) {
rep(r, 2) {
if (dp[i][j][k][s][r] == 0) continue;
rep(next, 10) {
if (s == 1 && k == next) continue;
if (s == 2 && (k == next || j == next)) continue;
if (r == 0 && next > ud) continue;
int ns = s;
if (ns == 0) {
if (next) ns++;
}
else if (ns == 1) ns++;
dp[i+1][k][next][ns][r|(next<ud)] += dp[i][j][k][s][r];
}
}
}
}
}
}
long long s = 0;
rep(i, 10) rep(j, 10) rep(k, 3) rep(r, 2) s += dp[X.size()][i][j][k][r];
return s;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> A >> B;
long long s = solve(to_string(B));
if (A > 0) s -= solve(to_string(A-1));
cout << s << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |