Submission #474772

# Submission time Handle Problem Language Result Execution time Memory
474772 2021-09-19T16:03:47 Z Duy_e Palindrome-Free Numbers (BOI13_numbers) C++14
0 / 100
3 ms 460 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<long long, long long>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long oo = 1e18;
const long long N = 2e5 + 5;

ll dp[20][11][11][2][2];
vector <int> num;

ll cal(int pos, int pre, int cur, bool f, bool lz){

    if (pos == num.size()) return 1;

    ll &ans = dp[pos][pre][cur][f][lz];
    if (ans != - 1) return ans;
    ans = 0;

    ll lmt = num[pos];
    if (f) lmt = 9;

    for (int i = 0; i <= lmt; i ++)
    if (i != pre && i != cur){
        bool new_f = f, new_lz = lz & (i == 0);
        int new_pre, new_cur;
        if (f == 0 && i < lmt) new_f = 1;

        if (new_lz) new_pre = new_cur = 10;
        else {
            new_cur = i;
            if (lz) new_pre = 10; else new_pre = cur;
        }

        ans += cal(pos + 1, new_pre, new_cur, new_f, new_lz);
    }
    return ans;
}

ll solve(ll n){
    memset(dp, -1, sizeof dp);
    if (n <= 0) return 0;
    num.clear();

    while (n > 0) num.push_back(n%10), n/=10;
    reverse(num.begin(), num.end());
    return cal(0, 10, 10, 0, 1);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
    #endif
    
    ll A, B;
    cin >> A >> B;
    cout << solve(B) - solve(A - 1);

    return 0;
}    
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/

Compilation message

numbers.cpp: In function 'long long int cal(int, int, int, bool, bool)':
numbers.cpp:17:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     if (pos == num.size()) return 1;
      |         ~~~~^~~~~~~~~~~~~
numbers.cpp: In function 'int main()':
numbers.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:57:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
      |                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Incorrect 3 ms 332 KB Output isn't correct
3 Incorrect 2 ms 332 KB Output isn't correct
4 Incorrect 2 ms 460 KB Output isn't correct
5 Incorrect 2 ms 332 KB Output isn't correct
6 Incorrect 2 ms 332 KB Output isn't correct
7 Incorrect 2 ms 332 KB Output isn't correct
8 Incorrect 2 ms 332 KB Output isn't correct
9 Incorrect 2 ms 332 KB Output isn't correct
10 Incorrect 2 ms 332 KB Output isn't correct
11 Incorrect 2 ms 332 KB Output isn't correct
12 Incorrect 2 ms 460 KB Output isn't correct
13 Incorrect 2 ms 332 KB Output isn't correct
14 Incorrect 2 ms 332 KB Output isn't correct
15 Incorrect 2 ms 332 KB Output isn't correct
16 Incorrect 2 ms 332 KB Output isn't correct
17 Incorrect 2 ms 332 KB Output isn't correct
18 Incorrect 2 ms 332 KB Output isn't correct
19 Incorrect 2 ms 344 KB Output isn't correct
20 Incorrect 3 ms 332 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 460 KB Output isn't correct
2 Incorrect 2 ms 332 KB Output isn't correct
3 Incorrect 2 ms 460 KB Output isn't correct
4 Incorrect 2 ms 332 KB Output isn't correct
5 Incorrect 2 ms 332 KB Output isn't correct
6 Incorrect 3 ms 332 KB Output isn't correct
7 Incorrect 2 ms 332 KB Output isn't correct
8 Incorrect 2 ms 332 KB Output isn't correct
9 Incorrect 2 ms 460 KB Output isn't correct
10 Incorrect 3 ms 332 KB Output isn't correct
11 Incorrect 2 ms 332 KB Output isn't correct
12 Incorrect 2 ms 460 KB Output isn't correct
13 Incorrect 2 ms 332 KB Output isn't correct
14 Incorrect 2 ms 460 KB Output isn't correct
15 Incorrect 2 ms 460 KB Output isn't correct
16 Incorrect 2 ms 388 KB Output isn't correct
17 Incorrect 2 ms 460 KB Output isn't correct
18 Incorrect 2 ms 332 KB Output isn't correct
19 Incorrect 2 ms 332 KB Output isn't correct
20 Incorrect 3 ms 332 KB Output isn't correct
21 Incorrect 2 ms 332 KB Output isn't correct
22 Incorrect 2 ms 332 KB Output isn't correct
23 Incorrect 2 ms 332 KB Output isn't correct
24 Incorrect 2 ms 332 KB Output isn't correct
25 Incorrect 2 ms 332 KB Output isn't correct
26 Incorrect 2 ms 332 KB Output isn't correct
27 Incorrect 2 ms 332 KB Output isn't correct
28 Incorrect 2 ms 332 KB Output isn't correct
29 Incorrect 2 ms 332 KB Output isn't correct
30 Incorrect 2 ms 460 KB Output isn't correct
31 Incorrect 2 ms 460 KB Output isn't correct
32 Incorrect 2 ms 332 KB Output isn't correct
33 Incorrect 2 ms 332 KB Output isn't correct
34 Incorrect 3 ms 332 KB Output isn't correct
35 Incorrect 2 ms 332 KB Output isn't correct
36 Incorrect 3 ms 332 KB Output isn't correct
37 Incorrect 2 ms 460 KB Output isn't correct
38 Incorrect 2 ms 452 KB Output isn't correct
39 Incorrect 2 ms 332 KB Output isn't correct
40 Incorrect 3 ms 332 KB Output isn't correct
41 Incorrect 2 ms 332 KB Output isn't correct
42 Incorrect 2 ms 332 KB Output isn't correct
43 Incorrect 2 ms 460 KB Output isn't correct
44 Incorrect 2 ms 460 KB Output isn't correct
45 Incorrect 2 ms 332 KB Output isn't correct