제출 #857001

#제출 시각아이디문제언어결과실행 시간메모리
857001MrModyPalindrome-Free Numbers (BOI13_numbers)C++17
100 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define el "\n" #define fio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); long long a,b; long long dp[22][2][10][10][2][2]; int d[22],cnt; int get_digits(long long n) { cnt=0; while(n) d[cnt++]=n%10,n/=10; reverse(d,d+cnt); return 0; } long long rec(int pos, int f, int before_last, int last, int has_before_last, int has_last) { if(pos == cnt) return has_last; auto &ret = dp[pos][f][before_last][last][has_before_last][has_last]; if(ret != -1) return ret; ret = 0; int i; for(i=0;i<10;i++) { if(f || i<=d[pos]){ if(!has_last || last!=i){ if(!has_before_last || before_last!=i) { ret += rec(pos+1,f|(i<d[pos]),last,i,has_last,has_last|(i>0)); } } } } return ret; } long long f(long long n) { get_digits(n); memset(dp,-1,sizeof(dp)); return 1 + rec(0,0,0,0,0,0); } int main() { fio cin >> a >> b; cout << f(b) - (a > 0 ? f(a-1):0); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...