Submission #1187091


Source Code Expand

import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		String s = in.next();
		int len = s.length(), n = len - 1;
		char[] buf = s.toCharArray();
		int[] a = new int[len];
		long ans = 0, tmp, sum;

		if (len == 1) {
			out.println(s);
			return ;
		}

		for (int i=0; i<len; ++i)
			a[i] = buf[i] - '0';

		int mst = 1<<n;

		for (int st=0; st<mst; ++st) {
			sum = 0;
			tmp = a[0];
			for (int j=0; j<n; ++j) {
				if ((st & (1<<j)) == 0) {
					// consecutive
					tmp = 10 * tmp + a[j+1];
				} else {
					// there is '+'
			//		out.print(tmp + "+");
					sum += tmp;
					tmp = a[j+1];
				}
			}
			sum += tmp;
			//out.println(tmp + " = " + sum);
			ans += sum;
		}

		out.println(ans);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Submission Info

Submission Time
Task C - Many Formulas
User Trasier
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 1895 Byte
Status AC
Exec Time 72 ms
Memory 21332 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 69 ms 18004 KB
02.txt AC 71 ms 20948 KB
03.txt AC 71 ms 19412 KB
04.txt AC 70 ms 18132 KB
05.txt AC 71 ms 19412 KB
06.txt AC 70 ms 18260 KB
07.txt AC 71 ms 21204 KB
08.txt AC 72 ms 20820 KB
09.txt AC 69 ms 21332 KB
10.txt AC 69 ms 20180 KB
sample_01.txt AC 72 ms 19412 KB
sample_02.txt AC 71 ms 20564 KB