Submission #810765

# Submission time Handle Problem Language Result Execution time Memory
810765 2023-08-06T15:05:59 Z pdm Palindrome-Free Numbers (BOI13_numbers) C++14
96.25 / 100
1 ms 340 KB
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
//#pragma expected_value
//#pragma isolated_call
//#pragma disjoint

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define setpre(i) setprecision(i)<<fixed
#define foru(i, a, b) for(int i=a;i<=b;++i)
#define ford(i, a, b) for(int i=a;i>=b;--i)
#define mp make_pair
#define moo cout<<"moo "
#define fi first
#define se second

ll lmod = 1e9 + 7;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef pair<double, double> dd;

ll dp[20][2][2][11][11];
string num;

ll solve(int pos, bool under, bool started, int dig1, int dig2){
    ll &ans = dp[pos][under][started][dig1][dig2];
    if(pos == num.size()){
        if(!started) return 0;
        else return 1;
    }
    if(ans != -1) return ans;
    ans = 0;
    foru(i, 0, 9){
        if(!under and i > num[pos] - '0') break;
        if(i == dig1 or i == dig2) continue;
        if(i) ans += solve(pos + 1, under or i < num[pos] - '0', 1, dig2, i);
        else {
            if(started) ans += solve(pos + 1, under or i < num[pos] - '0', 1, dig2, i);
            else ans += solve(pos + 1, under or i < num[pos] - '0', 0, dig2, 10);
        }
    }
    return ans;
}

ll cnt(ll x, ll y){
    num = to_string(y);
    memset(dp, -1, sizeof dp);
    ll temp1 = solve(0, 0, 0, 10, 10);
    // cout << temp1 << endl;
    num = to_string(x - 1);
    memset(dp, -1, sizeof dp);
    ll temp2 = solve(0, 0, 0, 10, 10);
    // cout << temp2 << endl;
    return temp1 - temp2;
    
}

int main(){
//	freopen("input.inp", "r", stdin);
//	freopen("output.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // cout << cnt(1, 10);
    ll a, b; cin >> a >> b;
    cout << cnt(a, b) << endl;

//	fclose(stdout);
}

Compilation message

numbers.cpp: In function 'long long int solve(int, bool, bool, int, int)':
numbers.cpp:33:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if(pos == num.size()){
      |        ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Incorrect 0 ms 340 KB Output isn't correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Incorrect 0 ms 340 KB Output isn't 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 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 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 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 0 ms 340 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 0 ms 340 KB Output is correct
35 Correct 0 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 0 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct