Submission #4635345


Source Code Expand

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    string S; cin >> S;
    ll ans=0;

    for(int bit=0; bit < (1<<S.size()-1); ++bit){
        ll num=S[0]-'0';
        //cout << "before num= " << num << endl;
        for(int i=0; i<S.size()-1; ++i){
            if(bit & (1<<i)){
                ans+=num;
                num=0;
            }
            num = num*10 + (S[i+1]-'0');
            //cout << "after num= " << num << endl;
        }
        ans+=num;
        //cout << "ans= " << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task C - Many Formulas
User Radperia
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1327 Byte
Status AC
Exec Time 3 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status AC
AC × 12
Set Name Test Cases
Sample
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
01.txt AC 3 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 1 ms 256 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB