fork download
  1. // ROOT : DRAGON3012009
  2. #include <bits/stdc++.h>
  3. #define ll long long
  4. #define el "\n"
  5. #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  6. #define __ROOT__ int main()
  7. #define fi first
  8. #define se second
  9. #define M 1000000007
  10. #define MAXN 1000001
  11. #define GIOIHAN 1000001
  12. #define BLOCK_SIZE 425
  13. #define MAX_NODE 1001001
  14. #define LOG 19
  15. #define ALPHA_SIZE 26
  16. #define NAME "check"
  17. #define compare(v) sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); // dùng để nén sort mảng compare
  18. using namespace std;
  19. //**Variable**//
  20. ll n ;
  21. string l , r;
  22. ll arr[MAXN];
  23. //**Struct**//
  24. ll dp[15][2][10][16][15*15*9+1];
  25. //**Function**//
  26. ll DP(ll pos ,ll lower , ll last , ll cnt , ll sum, string &x){
  27. ll &cur = dp[pos][lower][last][cnt][sum] ;
  28. if(x.size() == pos){
  29. return cur =sum + cnt*cnt*last ;
  30. }
  31. if(cur!=-1 ) return cur;
  32. cur = 0 ;
  33. ll limit = lower ? x[pos] -'0' :9 ;
  34. for(ll i = 0 ; i <=limit; i ++ ){
  35. if(last == i) cur += DP(pos+1 , i == limit && lower , i , cnt+1, sum,x );
  36. else cur+=DP(pos+1, i == limit && lower , i , 1 ,sum + cnt*cnt*last , x) ;
  37. }
  38. return cur ;
  39. }
  40. void init() {
  41. cin>>l>>r;
  42. }
  43. ll check(string temp) {
  44. ll t = 0 ;
  45. ll cnt = 0 ;
  46. char last = temp[0];
  47. for(ll i = 0 ; i <= temp.size() ; i ++ ) {
  48. if(temp[i] == last) {
  49. cnt++ ;
  50. }else{
  51. t += cnt*cnt*(last-'0') ;
  52. cnt=1 ;
  53. last = temp[i] ;
  54. }
  55. }
  56. return t;
  57. }
  58. ll F(string x){
  59. memset(dp , - 1 , sizeof dp ) ;
  60. return DP(0 , 1 , 0 , 0 , 0 , x) ;
  61. }
  62. void solve() {
  63. cout<<F(r) - F(l) + check(l);
  64. }
  65.  
  66. __ROOT__ {
  67. // freopen(NAME".inp" , "r" , stdin);
  68. // freopen(NAME".out" , "w", stdout) ;
  69. fast;
  70. init();
  71. solve();
  72. }
  73.  
Success #stdin #stdout 0.03s 81408KB
stdin
Standard input is empty
stdout
Standard output is empty