# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1120329 | vjudge1 | Palindrome-Free Numbers (BOI13_numbers) | C++17 | 2 ms | 564 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 <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F
int dp[20][11][11][2];
string N;
int f(int i, int a, int b, int ff)
{
if (i == N.length()) return 1;
if (dp[i][a][b][ff] != -1) return dp[i][a][b][ff];
int res = 0;
for (int c = 0; c <= 9; c++)
{
if (a == c || b == c) continue;
if (ff && c > N[i] - '0') continue;
int nwf = ff && (c == N[i] - '0');
res += f(i + 1, b, c, nwf);
}
return dp[i][a][b][ff] = res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, b;
cin >> a >> b;
for (int i = 0; i < 20; i++) for (int j = 0; j < 11; j++) for (int k = 0; k < 11; k++) for (int l = 0; l < 2; l++) dp[i][j][k][l] = -1;
N = to_string(b);
int res = f(0, 10, 10, 1);
if (a == 0)
{
cout << res << '\n';
return 0;
}
a--;
for (int i = 0; i < 20; i++) for (int j = 0; j < 11; j++) for (int k = 0; k < 11; k++) for (int l = 0; l < 2; l++) dp[i][j][k][l] = -1;
N = to_string(a);
res -= f(0, 10, 10, 1);
cout << res << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |