ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1048. Сверхдлинные суммы

Ruben Ashughyan How to get speed 0.001 seconds ???? [4] // Задача 1048. Сверхдлинные суммы 9 июн 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 !!!!!
I got 0.001s AC!!
buffered i/o  helped me.
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