Submission #900312

# Submission time Handle Problem Language Result Execution time Memory
900312 2024-01-08T05:53:49 Z theghostking Palindrome-Free Numbers (BOI13_numbers) C++17
73.75 / 100
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<int> num;

int dp[20][11][11][2][2];
//pos, last digit, last last digit, tight, all 0's boolean
//10 -> no digit

int call(int pos, int lst, int lslst, int f, bool zero){
    //cout << pos << " " << lst << " " << lslst << " " << f << '\n';
    if (pos == num.size()){
        //cout << lslst << " " << lst << '\n';
        return 1;
    }
    if (dp[pos][lst][lslst][f][zero] != -1) return dp[pos][lst][lslst][f][zero];
    int res = 0;
    int lmt = 0;
    if (f == 0){
        lmt = num[pos];
    }
    else{
        lmt = 9;
    }
    for (int dgt = 0; dgt <= lmt; dgt++){
        int nf = f;
        if ((f == 0) && (dgt < lmt)) nf = 1;
        if ((dgt == 0) && (zero) && ((lst == 0) || (lslst == 0))){
            res += call(pos+1,dgt,lst,nf,zero);
        }
        if ((dgt == lst) || (dgt == lslst)) continue;
        int nz = zero;
        if (dgt > 0) nz = false;
        //cout << dgt << " " << lst << '\n';
        res += call(pos+1,dgt,lst,nf,nz);
    }
    return dp[pos][lst][lslst][f][zero] = res;
}

int solve(int b){
    num.clear();
    while (b > 0){
        num.push_back(b%10);
        b /= 10;
    }
    reverse(num.begin(),num.end());
    memset(dp,-1,sizeof(dp));
    int res = call(0,10,10,0,1);
    return res;
}

signed main() {
    int a,b;
    cin >> a >> b;
    if (a != 0){
        cout << solve(b)-solve(a-1);
    }
    else{
        cout << solve(b);
    }
    return 0;

}

Compilation message

numbers.cpp: In function 'long long int call(long long int, long long int, long long int, long long int, bool)':
numbers.cpp:14:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     if (pos == num.size()){
      |         ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Incorrect 1 ms 344 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Correct 1 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Incorrect 1 ms 600 KB Output isn't correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 600 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 344 KB Output is correct