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

Обсуждение задачи 1318. Логарифм

How to avoid TLE?
Послано Geworm 17 апр 2004 08:45
I think O(n^2) algorithms will certainly lead to TLE.
I tried to count how many results will be larger than 10,100,... and got an algorithm, and its complexity is O(800nlogn), still TLE.
I heard that there was an O(n) algorithm, can anyone tell me how to do that? Thanks.
Ultra-strict optimization (-)
Послано Dmitry 'Diman_YES' Kovalioff 17 апр 2004 12:43
Re: Ultra-strict optimization (-)
Послано Geworm 19 апр 2004 09:16
Do you mean optimize the simple O(n^2) solution or use an O(n) algorithm?
Re: Re: Ultra-strict optimization (-)
Послано Sergey Chernykh 24 авг 2004 22:49
My ultra-optimized O(n^2) solution using some assembler in critical parts of code passed in 0.718 seconds. But I spend almost 2 hours for optimizing my code.
Re: Re: Ultra-strict optimization (-)
Послано Fat Peter 24 сен 2004 20:18
Can you tell me more about it?I got TLE...:(
Re: Re: Ultra-strict optimization (-)
Послано Sergey Chernykh 18 окт 2004 16:30
You should use a table, which for every 2^k (0 <= k <= 127) keeps a value of Trunc(log10(2^k)). You should also keep a table with powers of 10 (10^0 .. 10^39). In the main loop of the program (which is straight-forward) you compute B = A[i] XOR A[j], then find the position k of the most significant bit of B (k is counted from zero). k is obtained using assembler instruction BSR (Bit Scan Reverse).
At this point you know that 2^k <= B < 2^(k+1). Now, M := Trunc(log10(2^k)), and N := Trunc(log10(2^(k+1)). If B >= 10^N, then Trunc(log10(B))=N, else Trunc(log10(B))=M.

Starting with this algorithm and optimizing it, you should get AC.