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

How to get speed 0.001 seconds ????
Posted by Ruben Ashughyan 9 Jun 2016 01:20
Re: How to get speed 0.001 seconds ????
Posted by c_pp 13 Dec 2016 20:59
 -- use fread | fwrite;
 -- do not use << if >> statement or minimize it;
 -- minimize div  and mod  operations ( % , / operators);
 -- instead of % , /  operators may to use  pre-calculated arrays.
 -- and last, need lucky :)
Re: How to get speed 0.001 seconds ????
Posted by ToadMonster 13 Dec 2016 21:33
Your program ate 12 Mb memory. So I suppose you are reading the whole numbers and then do addition.

It isn't necessary. It's possible to add numbers digit by digit (yes, from high digits to low) without any arrays usage - 0.3s even using scanf/printf.

And yes, use fread/fwrite.

Edited by author 13.12.2016 22:15
Re: How to get speed 0.001 seconds ????
Posted by c_pp 16 Dec 2016 21:25
10^6 numbers --> input file size ~4 Mbytes, and output file size ~1 Mbytes.
MY PC i-core 3 , 3 GB RAM, gcc 5.4.0 with option:  g++ -Wall  -O3  -std=c++14  reads/writes took   6-9 milliseconds. So there need something magic tricky to solve this with time < 1 milliseconds !!!!!
Re: How to get speed 0.001 seconds ????
Posted by xurshid_n 18 Dec 2016 15:47
I got 0.001s AC!!
buffered i/o  helped me.