제출 #359793

#제출 시각아이디문제언어결과실행 시간메모리
359793entikiPalindrome-Free Numbers (BOI13_numbers)C++11
100 / 100
1 ms640 KiB
#include <iostream> #include <stdio.h> #include <cstdint> #include <cstring> #include <queue> #include <stack> #include <time.h> #include <map> #include <algorithm> #include <iomanip> #include <cstdlib> #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); ll res_a = 0, res_b = 0; int len = 0; string sa = "" ,sb = ""; if (a > 0) { memset(f,-1,sizeof(f)); sa = convert_string(a-1); len = get_len(sa); res_a = calc(1,10,10,0,0,len,sa); } else res_a = 0; memset(f,-1,sizeof(f)); sb = convert_string(b); len = get_len(sb); res_b = calc(1,10,10,0,0,len,sb); cout<<res_b - res_a; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...