【Atcoder Beginner Contest 045】C-Many Formulas
【Atcoder Beginner Contest 045】C - Many Formulas
Time Limit: \(2\) sec / Memory Limit: \(256\) MB
Score : \(300\) points
Problem Statement
You are given a string \(S\) consisting of digits between 1 and 9, inclusive. You can insert the letter + into some of the positions (possibly none) between two letters in this string. Here, + must not occur consecutively after insertion.
All strings that can be obtained in this way can be evaluated as formulas.
Evaluate all possible formulas, and print the sum of the results.
Constraints
-
\(1≤|S|≤10\)
-
All letters in are digits between
1and9, inclusive.
Input
The input is given from Standard Input in the following format:
S
Output
Print the sum of the evaluated value over all possible formulas.
//解释待补充
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
string s;
cin>>s;
ll a=0,k=1<<(s.size()-1),t=k;
for(ll i=s.size()-1;i>=0;i--) a+=(s[i]-'0')*k,k=k*5+t/2;
cout<<a<<endl;
}

浙公网安备 33010602011771号