ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1048. Superlong Sums

TLE can u reduce time its not clicking?
Posted by Varun Kumar(Fundu) 3 Oct 2008 19:16
import java.io.*;
import java.util.*;

public class LargeSum_1048{


public static void main(String args[]) throws IOException
{
    BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));

    String temp=new String(buf.readLine());
    int n=Integer.parseInt(temp);



    int total=n*5;
    int k=total-3;
    total=total+20;

    char input[]=new char[total];


    buf.read(input,0,total);




    int sum=0,carry=0,i;
    String str=new String();



    for(i=0;i<n;i++)
    {


        sum=input[k]+input[k-2]-96+carry;


        k=k-5;

        if(sum>9)
        {
            carry=1;
            sum=sum-10;
        }
        else{
            carry=0;
        }

        str=sum+str;
    }

    System.out.println(str);




}
}
There is a solution without arrays, with O(1) memory
Posted by Vladimir Yakovlev (USU) 6 Oct 2008 19:38