fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5. #include<math.h>
  6.  
  7. int digit(int x)
  8. {
  9. // int count=0;
  10. // if(x==0)
  11. // return 1;
  12.  
  13. // else
  14. // {
  15. // while(x!=0)
  16. // {
  17. // x=x/10;
  18. // count++;
  19. // }
  20. // }
  21.  
  22. int count = to_string(x).length();
  23. return count;
  24. }
  25.  
  26. int main() {
  27. // your code goes here
  28. int n;
  29. cin>>n;
  30. vector<int>arr(n+1);
  31. int i=1;
  32. while(i<=n)
  33. {
  34. cin>>arr[i];
  35. i++;
  36. }
  37.  
  38. int sum=0;
  39. int prefix[n+1]={0};
  40. prefix[0]=arr[0];
  41. //for(int i=1;i<n;i++)
  42. // {
  43. // prefix[i]=prefix[i-1]+arr[i];
  44. // }
  45. //for(int j=1;j<n;j++) //0(n)
  46. // { int i=0;
  47. // int p = pow(10,digit(arr[j])); //0(l)
  48. // sum+=prefix[j-1]*p+arr[j]*(j-i) ;
  49.  
  50.  
  51. // }
  52.  
  53.  
  54. sum=0;
  55. int ans=0;
  56. for(int j=1;j<=n;j++)
  57. {
  58. int p =digit(arr[j]);
  59. int vl = arr[j]*(j-1)+pow(10,p)*sum;
  60. ans+=vl;
  61. sum+=arr[j];
  62. }
  63.  
  64. cout<<ans;
  65.  
  66. return 0;
  67. }
Success #stdin #stdout 0s 5288KB
stdin
3
3 14 15
stdout
2044