Submission #779003

# Submission time Handle Problem Language Result Execution time Memory
779003 2023-07-11T06:24:32 Z vjudge1 Palindrome-Free Numbers (BOI13_numbers) C++17
71.25 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define st first
#define nd second
#define ppii pair<pair<int,int>,pair<int, int>>
const int maxn = 2e5 + 5;
string t;
int a, b, dp[20][2][11][11][2];
int caldp(int pos, int eq, int lst1, int lst2, int start){
    if(pos == t.size())
        return 1;
    if(dp[pos][eq][lst1][lst2][start] != -1)
        return dp[pos][eq][lst1][lst2][start];
    int ans = 0;
    if(eq){
        int limit = t[pos] - '0';
        if(start){
            for(int i = 0 ; i <= limit ; i++){
                if(i == lst1 || i == lst2)
                    continue;
                ans += caldp(pos + 1, (i == limit), i, lst1, start);
            }
        }
        else{
            for(int i = 1 ; i <= limit ; i++){
                ans += caldp(pos + 1, (i == limit), i, -1, 1);
            }
        }
    }
    else{
        if(start){
            for(int i = 0 ; i <= 9 ; i++){
                if(i == lst1 || i == lst2)
                    continue;
                ans += caldp(pos + 1, 0, i, lst1, start);
            }
        }
        else{
            for(int i = 1 ; i <= 9 ; i++){
                ans += caldp(pos + 1, 0, i, -1, 1);
            }
        }
    }
    return dp[pos][eq][lst1][lst2][start] = ans;
}
int prepdp(int x){
    memset(dp, -1, sizeof dp);
    t = to_string(x);
    return caldp(0, 1, -1, -1, 0);
}
void solve(){
    int a, b;
    cin >> a >> b;
    cout << prepdp(b) - prepdp(a - 1);
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int tc = 1;
    // cin >> tc;
    while(tc--){
        solve();
    }
}

Compilation message

numbers.cpp: In function 'long long int caldp(long long int, long long int, long long int, long long int, long long int)':
numbers.cpp:11: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]
   11 |     if(pos == t.size())
      |        ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 324 KB Output isn't correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Incorrect 1 ms 320 KB Output isn't correct
19 Correct 1 ms 320 KB Output is correct
20 Incorrect 1 ms 340 KB Output isn't 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 Incorrect 1 ms 340 KB Output isn't correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 320 KB Output isn't correct
9 Incorrect 1 ms 320 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 1 ms 320 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 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 1 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 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 324 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 324 KB Output is correct
44 Correct 1 ms 320 KB Output is correct
45 Correct 1 ms 340 KB Output is correct