Submission #1121072

# Submission time Handle Problem Language Result Execution time Memory
1121072 2024-11-28T11:30:04 Z raul2008487 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
2 ms 508 KB
#include<bits/stdc++.h>

#define ll long long
#define int ll
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"

using namespace std;
const int sz = 3e5 + 5; /// mind this
const int MAX = 2e6 + 123;
const int BS = 61;
const int mod = 998244353;
ll dp[18][11][11][2];
string s;
ll f(ll ind, ll prv1, ll prv2, bool ok){
    if(ind == s.size()){
        return 1;
    }
    if(dp[ind][prv1][prv2][ok] != -1){
        return dp[ind][prv1][prv2][ok];
    }
    ll ans = 0;
    for(int d = 0; d < 10; d++){
        if(d == prv1 || d == prv2){continue;}
        if(ok && d > (s[ind] - '0')){break;}
        ll val = d;
        if(val == 0 && prv1 == 10)val = 10;
        if(d == (s[ind] - '0')){
            ans += f(ind + 1, val, prv1, ok);
        }
        else{
            ans += f(ind + 1, val, prv1, 0);
        }
    }
    return dp[ind][prv1][prv2][ok] = ans;
}
void solve(){
    ll a, b, i, j;
    cin >> a >> b;
    memset(dp, -1, sizeof(dp));
    s = to_string(b);
    ll r = f(0, 10, 10, 1);
    if(!a){
        cout << r << endl;
        return ;
    }
    s = to_string(--a);
    memset(dp, -1, sizeof(dp));
    ll l = f(0, 10, 10, 1);
    cout << r - l << endl;

}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

/*
*/

Compilation message

numbers.cpp: In function 'long long int f(long long int, long long int, long long int, bool)':
numbers.cpp:21:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     if(ind == s.size()){
      |        ~~~~^~~~~~~~~~~
numbers.cpp: In function 'void solve()':
numbers.cpp:43:14: warning: unused variable 'i' [-Wunused-variable]
   43 |     ll a, b, i, j;
      |              ^
numbers.cpp:43:17: warning: unused variable 'j' [-Wunused-variable]
   43 |     ll a, b, i, j;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 400 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 508 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 488 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 504 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 488 KB Output is correct