Submission #696225

# Submission time Handle Problem Language Result Execution time Memory
696225 2023-02-06T01:32:44 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define all(a) a.begin(), a.end()
#define pb push_back

typedef long long ll;
typedef pair<int, int> ii;

void print() {cerr << '\n';} template<typename T1, typename... T2> void print(T1 a, T2... b) {cerr << a << ' ', print(b...);}

vector<int> num;
ll a, b;
ll f[20][11][11][2];

ll dp(int i, int pre1, int pre2, bool smaller)
{
    if(i == (int)num.size()) return 1;

    ll &res = f[i][pre1 + 1][pre2 + 1][smaller];
    if(~res) return res;
    res = 0;

    int lim = (smaller ? 9 : num[i]);
    for(int d = 0; d <= lim; d++)
    {
        if(d == pre1 || d == pre2) continue;
        res += dp(i + 1, pre2, pre2 == -1 && d == 0 ? -1 : d, smaller || (d < lim));
    }
    return res;
}

ll calc(ll n)
{
    if(n <= 0) return n == 0;
    num.clear();
    while(n) num.pb(n % 10), n /= 10;
    reverse(all(num));
    memset(f, -1, sizeof f);
    return dp(0, -1, -1, 0);
}

void solve()
{
    cin >> a >> b;
    cout << calc(b) - calc(a - 1);
}

signed main()
{
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    cin.tie(0) -> sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while(t--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 328 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct