Submission #359769

# Submission time Handle Problem Language Result Execution time Memory
359769 2021-01-27T07:49:59 Z entiki Palindrome-Free Numbers (BOI13_numbers) C++11
Compilation error
0 ms 0 KB
#include <iostream>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <queue>
#include <stack>
#include <time.h>
#include <map>
#include <algorithm>
#include <iomanip>
 
#define BIT(x,pos) (((x)>>(pos)) & 1LL)
#define _(x) (1LL<<(x))
#define cnt_bit(x) __builtin_popcountll(x)
#define turn_on(x,pos) ((x) |= (_(pos)))
#define turn_off(x,pos) ((x) &= ~(_(pos))
#define flip_bit(x,pos) ((x) ^= (_(pos))
#define low_bit(x) ((x) & (-x))
#define bit_on(x) (_(x)-1LL)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef int64_t int64;
typedef long double ld;
 
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<ll> vll;
 
ll f[20][11][11][3][3];
ll a,b;
 
string convert_string(ll n)
{
    string res = "";
    for (;n > 0; n /= 10)
    {
        char tmp = (char)(n % 10 + '0');
        res = tmp + res;
    }
return res;
}
 
int get_digit(const string &s,int pos)
{
    return s[pos-1] - '0';
}
 
int get_len(const string &s)
{
    return s.size();
}
 
ll calc(int pos,int first_D,int second_D,bool is_less,bool not_first,int len,const string &s)
{
    if (pos > len) return 1;
 
    ll &ret = f[pos][first_D][second_D][is_less][not_first];
    if (ret != -1) return ret;
 
    ret = 0;
    int x = 9;
    if (is_less == false) x = get_digit(s,pos);
 
    for (int d = 0; d <= x; ++d)
        if (d != first_D && d != second_D)
        {
            int t_firstD = second_D;
            int t_secondD = d;
            bool new_notfirst = (not_first | (d > 0));
 
            if (new_notfirst == false && d == 0) t_secondD = 10;
 
            ret += calc(pos+1,t_firstD,t_secondD,is_less | (d < x),new_notfirst,len,s);
        }
 
return ret;
}
 
int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
 
    cin>>a>>b;
  
  	if (a > b) swap(a,b);
  
    memset(f,-1,sizeof(f));
    string sa = convert_string(a-1);
    int len = get_len(sa);
    if (a != 0) ll res_a = calc(1,10,10,0,0,len,sa);
  	else ll res_a = -1;
 
    memset(f,-1,sizeof(f));
    string sb = convert_string(b);
    len = get_len(sb);
    ll res_b = calc(1,10,10,0,0,len,sb);
 
    cout<<res_b - res_a;
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:97:20: warning: unused variable 'res_a' [-Wunused-variable]
   97 |     if (a != 0) ll res_a = calc(1,10,10,0,0,len,sa);
      |                    ^~~~~
numbers.cpp:98:12: warning: unused variable 'res_a' [-Wunused-variable]
   98 |    else ll res_a = -1;
      |            ^~~~~
numbers.cpp:105:19: error: 'res_a' was not declared in this scope; did you mean 'res_b'?
  105 |     cout<<res_b - res_a;
      |                   ^~~~~
      |                   res_b