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

Ruben Ashughyan How to get speed 0.001 seconds ???? [4] // Problem 1048. Superlong Sums 9 Jun 2016 01:20
 -- 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 :)
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 !!!!!
xurshid_n Re: How to get speed 0.001 seconds ???? // Problem 1048. Superlong Sums 18 Dec 2016 15:47
I got 0.001s AC!!
buffered i/o  helped me.
ToadMonster Re: How to get speed 0.001 seconds ???? // Problem 1048. Superlong Sums 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