Submission #696224

# Submission time Handle Problem Language Result Execution time Memory
696224 2023-02-06T01:32:20 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++14
0 / 100
3 ms 392 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;
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     freopen("test.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:55:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     freopen("test.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Incorrect 2 ms 340 KB Output isn't correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Incorrect 2 ms 340 KB Output isn't correct
8 Incorrect 2 ms 340 KB Output isn't correct
9 Incorrect 2 ms 340 KB Output isn't correct
10 Incorrect 2 ms 340 KB Output isn't correct
11 Incorrect 2 ms 340 KB Output isn't correct
12 Incorrect 2 ms 340 KB Output isn't correct
13 Incorrect 2 ms 340 KB Output isn't correct
14 Incorrect 2 ms 340 KB Output isn't correct
15 Incorrect 2 ms 340 KB Output isn't correct
16 Incorrect 2 ms 340 KB Output isn't correct
17 Incorrect 2 ms 340 KB Output isn't correct
18 Incorrect 3 ms 340 KB Output isn't correct
19 Incorrect 2 ms 340 KB Output isn't correct
20 Incorrect 2 ms 340 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Incorrect 2 ms 340 KB Output isn't correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Incorrect 2 ms 340 KB Output isn't correct
8 Incorrect 2 ms 340 KB Output isn't correct
9 Incorrect 2 ms 392 KB Output isn't correct
10 Incorrect 2 ms 340 KB Output isn't correct
11 Incorrect 2 ms 340 KB Output isn't correct
12 Incorrect 2 ms 340 KB Output isn't correct
13 Incorrect 3 ms 340 KB Output isn't correct
14 Incorrect 2 ms 340 KB Output isn't correct
15 Incorrect 2 ms 340 KB Output isn't correct
16 Incorrect 2 ms 340 KB Output isn't correct
17 Incorrect 2 ms 340 KB Output isn't correct
18 Incorrect 2 ms 340 KB Output isn't correct
19 Incorrect 2 ms 340 KB Output isn't correct
20 Incorrect 2 ms 340 KB Output isn't correct
21 Incorrect 2 ms 340 KB Output isn't correct
22 Incorrect 2 ms 340 KB Output isn't correct
23 Incorrect 2 ms 340 KB Output isn't correct
24 Incorrect 3 ms 340 KB Output isn't correct
25 Incorrect 2 ms 340 KB Output isn't correct
26 Incorrect 2 ms 340 KB Output isn't correct
27 Incorrect 2 ms 340 KB Output isn't correct
28 Incorrect 2 ms 340 KB Output isn't correct
29 Incorrect 2 ms 340 KB Output isn't correct
30 Incorrect 2 ms 340 KB Output isn't correct
31 Incorrect 2 ms 340 KB Output isn't correct
32 Incorrect 2 ms 340 KB Output isn't correct
33 Incorrect 2 ms 340 KB Output isn't correct
34 Incorrect 2 ms 340 KB Output isn't correct
35 Incorrect 2 ms 340 KB Output isn't correct
36 Incorrect 2 ms 340 KB Output isn't correct
37 Incorrect 2 ms 340 KB Output isn't correct
38 Incorrect 2 ms 340 KB Output isn't correct
39 Incorrect 2 ms 340 KB Output isn't correct
40 Incorrect 2 ms 340 KB Output isn't correct
41 Incorrect 2 ms 340 KB Output isn't correct
42 Incorrect 2 ms 340 KB Output isn't correct
43 Incorrect 2 ms 340 KB Output isn't correct
44 Incorrect 3 ms 340 KB Output isn't correct
45 Incorrect 2 ms 300 KB Output isn't correct