Submission #1102954

# Submission time Handle Problem Language Result Execution time Memory
1102954 2024-10-19T09:19:19 Z Cam Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
3 ms 1812 KB
#include <bits/stdc++.h>
#define name "palinfree"
#define ll long long
#define db double
#define pb push_back
#define ii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define bit(x,i) (((x)>>(i))&1)
#define sz(s) (int)(s).size()
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int i=(a), _b=(b); i<=_b; i++)
#define repd(i,a,b) for(int i=(a), _b=(b); i>=_b; i--)
#define _unique(x) (x).resize(unique(all(x)) - (x).begin())

using namespace std;

const int N = 1e5 + 3;

ll l, r;
ll f[25][2][25][13][13];
vector <int> digit;

ll Try (int i, bool isless, bool ok, int cnt, int pre1, int pre2) {

    if (i == -1) {
        return ok;
    }
    if (isless && f[i][ok][cnt][pre1][pre2] != -1) return f[i][ok][cnt][pre1][pre2];
    ll res = 0;
    int mx = (isless ? 9 : digit[i]);
    rep (j, 0, mx) {

        if (!ok && j == 0) res += Try (i - 1, isless || j < mx, 0, 0, pre2, j);
        else {

            if (cnt <= 1) {
                if (j != pre2) res += Try (i - 1, isless || j < mx, 1, cnt + 1, pre2, j);
            }
            else if (j != pre1 && j != pre2) res += Try (i - 1, isless || j < mx, 1, cnt + 1, pre2, j);
        }
    }
    if (isless) f[i][ok][cnt][pre1][pre2] = res;
    return res;
}
ll sol (ll x) {

    digit.clear();
    while (x > 0) digit.pb (x % 10), x /= 10;
    return Try (sz (digit) - 1, 0, 0, 0, 0, 0);
}

void solve (void) {

    cin >> l >> r;
    bool ok = 0;
    if (l > r) swap (l, r), ok = 1;
    rep (i, 0, 20) rep (ok, 0, 1) rep (cnt, 0, 20) rep (pre1, 0, 9) rep (pre2, 0, 9) f[i][ok][cnt][pre1][pre2] = -1;
    ll res = sol (r) - sol (l - 1);
    if (l == 0) res ++;
    if (ok) res *= -1;
    cout << res;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);

    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1616 KB Output is correct
2 Correct 2 ms 1616 KB Output is correct
3 Correct 2 ms 1616 KB Output is correct
4 Correct 2 ms 1616 KB Output is correct
5 Correct 1 ms 1616 KB Output is correct
6 Correct 2 ms 1616 KB Output is correct
7 Correct 2 ms 1616 KB Output is correct
8 Correct 1 ms 1616 KB Output is correct
9 Correct 2 ms 1616 KB Output is correct
10 Correct 2 ms 1616 KB Output is correct
11 Correct 2 ms 1784 KB Output is correct
12 Correct 2 ms 1616 KB Output is correct
13 Correct 2 ms 1632 KB Output is correct
14 Correct 2 ms 1616 KB Output is correct
15 Correct 2 ms 1616 KB Output is correct
16 Correct 2 ms 1784 KB Output is correct
17 Correct 2 ms 1616 KB Output is correct
18 Correct 2 ms 1784 KB Output is correct
19 Correct 2 ms 1616 KB Output is correct
20 Correct 2 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1628 KB Output is correct
2 Correct 2 ms 1616 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 3 ms 1784 KB Output is correct
5 Correct 1 ms 1616 KB Output is correct
6 Correct 2 ms 1668 KB Output is correct
7 Correct 2 ms 1616 KB Output is correct
8 Correct 2 ms 1616 KB Output is correct
9 Correct 2 ms 1812 KB Output is correct
10 Correct 2 ms 1616 KB Output is correct
11 Correct 2 ms 1616 KB Output is correct
12 Correct 2 ms 1616 KB Output is correct
13 Correct 3 ms 1616 KB Output is correct
14 Correct 2 ms 1616 KB Output is correct
15 Correct 2 ms 1616 KB Output is correct
16 Correct 3 ms 1616 KB Output is correct
17 Correct 2 ms 1668 KB Output is correct
18 Correct 2 ms 1784 KB Output is correct
19 Correct 2 ms 1616 KB Output is correct
20 Correct 2 ms 1696 KB Output is correct
21 Correct 2 ms 1616 KB Output is correct
22 Correct 2 ms 1616 KB Output is correct
23 Correct 2 ms 1784 KB Output is correct
24 Correct 3 ms 1616 KB Output is correct
25 Correct 2 ms 1616 KB Output is correct
26 Correct 2 ms 1784 KB Output is correct
27 Correct 3 ms 1616 KB Output is correct
28 Correct 3 ms 1616 KB Output is correct
29 Correct 2 ms 1616 KB Output is correct
30 Correct 2 ms 1616 KB Output is correct
31 Correct 3 ms 1784 KB Output is correct
32 Correct 2 ms 1668 KB Output is correct
33 Correct 3 ms 1616 KB Output is correct
34 Correct 2 ms 1664 KB Output is correct
35 Correct 3 ms 1616 KB Output is correct
36 Correct 2 ms 1616 KB Output is correct
37 Correct 2 ms 1616 KB Output is correct
38 Correct 2 ms 1616 KB Output is correct
39 Correct 3 ms 1616 KB Output is correct
40 Correct 2 ms 1616 KB Output is correct
41 Correct 3 ms 1616 KB Output is correct
42 Correct 2 ms 1616 KB Output is correct
43 Correct 2 ms 1616 KB Output is correct
44 Correct 2 ms 1668 KB Output is correct
45 Correct 2 ms 1616 KB Output is correct