Submission #810652

# Submission time Handle Problem Language Result Execution time Memory
810652 2023-08-06T13:38:24 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++14
23.3333 / 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 ans += solve(pos + 1, under or i < num[pos] - '0', started, dig2, i);
    }
    return ans;
}

ll cnt(int x, int 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 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 0 ms 340 KB Output isn't 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 Incorrect 0 ms 340 KB Output isn't correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Incorrect 0 ms 340 KB Output isn't correct
20 Incorrect 0 ms 340 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Correct 0 ms 340 KB Output is correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Incorrect 0 ms 340 KB Output isn't correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Incorrect 0 ms 340 KB Output isn't correct
14 Incorrect 0 ms 340 KB Output isn't correct
15 Incorrect 0 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Correct 0 ms 340 KB Output is correct
19 Incorrect 0 ms 340 KB Output isn't correct
20 Correct 0 ms 324 KB Output is correct
21 Incorrect 0 ms 340 KB Output isn't correct
22 Incorrect 0 ms 340 KB Output isn't correct
23 Incorrect 0 ms 340 KB Output isn't correct
24 Correct 0 ms 340 KB Output is correct
25 Incorrect 0 ms 340 KB Output isn't correct
26 Incorrect 1 ms 340 KB Output isn't correct
27 Incorrect 0 ms 340 KB Output isn't correct
28 Incorrect 1 ms 340 KB Output isn't correct
29 Correct 0 ms 340 KB Output is correct
30 Incorrect 0 ms 340 KB Output isn't correct
31 Incorrect 0 ms 340 KB Output isn't correct
32 Incorrect 0 ms 340 KB Output isn't correct
33 Incorrect 1 ms 340 KB Output isn't correct
34 Incorrect 0 ms 340 KB Output isn't correct
35 Incorrect 0 ms 340 KB Output isn't correct
36 Incorrect 0 ms 340 KB Output isn't correct
37 Incorrect 0 ms 340 KB Output isn't correct
38 Incorrect 0 ms 340 KB Output isn't correct
39 Incorrect 1 ms 340 KB Output isn't correct
40 Incorrect 0 ms 340 KB Output isn't correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Correct 1 ms 340 KB Output is correct
43 Incorrect 0 ms 340 KB Output isn't correct
44 Incorrect 0 ms 340 KB Output isn't correct
45 Incorrect 0 ms 340 KB Output isn't correct