Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя Wansur

Автор Wansur, история, 34 часа назад, По-русски

2013A — Блендер Жана

Первый решивший: rob00

Разбор
Решение

2013B — Бой на выживание

Первый решивший: neal

Разбор
Решение

2013C — Взлом Пароля

Первый решивший: Pagode_Paiva

Разбор
Решение

2013D — Минимизировать разность

Первый решивший: edogawa_something

Разбор
Решение

2013E — Префиксные НОД

Первый решивший: meme

Разбор
Решение

2013F1 — Игра на дереве (простая версия)

Первый решивший: EnofTaiPeople

Разбор
Решение c деревом отрезков
Решение за O(n)

2013F2 — Игра на дереве (сложная версия)

Первый решивший: rainboy

Разбор
Решение
Разбор задач Codeforces Round 973 (Div. 2)
  • Проголосовать: нравится
  • +32
  • Проголосовать: не нравится

»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Problem E originally meant a solution without a gready, but what are rich in :)

And in F you need to separately figure out when the first / second player wins if he starts at his top, because otherwise it hurts a lot)

»
4 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

any intuitive / formal proof to D ? i have a weird one that i'll write when i have time

»
3 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

why is cout.flush() not required in question C?

»
36 минут назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

:< could someone explain why cout<<ceil(double(n) / min(x,y)); in A led to WA

  • »
    »
    22 минуты назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    There are two reasons this may cause issue

    first (which is mostly the issue here), the output will be in scientific notation

    cout << ceil(1e9 / 2); // 5e+08
    

    this can be solved by casting the output to long/int

    cout << (long long)ceil(1e9 / 2); // 500000000
    

    Another issue which usually happens with large numbers is that double may not be precise enough, for example

    long long x = 1e18;
    x -= 2
    cout << (long long)ceil((double)x / 2) // 500000000000000000;
    

    Here the answer is off by 1 because double is not precise enough, a good solution for both these issues is to not use double for calculating ceil, instead you can calculate it using this

    $$$ceil(a/b) = floor((a + b - 1) / b)$$$

    Which can be written like this:

    long long a = 1e18, b = 2;
    a -= 2;
    cout << (a + b - 1) / b; // 499999999999999999